-
-
Notifications
You must be signed in to change notification settings - Fork 173
Make chart data point links clickable #1450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f8f2b28
427a735
a8c8082
3945c7b
6109413
f01b713
d270265
048ff9f
b41e4eb
5705fb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -111,7 +111,7 @@ const sqlpage_chart = (() => { | |||
| const reference_rows = data.points.filter((row) => !Array.isArray(row)); | ||||
| /** @type { Series } */ | ||||
| const series_map = new Map(); | ||||
| for (const [name, old_x, old_y, color, z] of points) { | ||||
| for (const [name, old_x, old_y, color, z, link] of points) { | ||||
| /** @type {ChartSeries} */ | ||||
| const point_series = series_map.get(name) ?? { name, data: [] }; | ||||
| series_map.set(name, point_series); | ||||
|
|
@@ -123,7 +123,7 @@ const sqlpage_chart = (() => { | |||
| y = y.map((y) => new Date(y).getTime()); | ||||
| else x = new Date(x); | ||||
| } | ||||
| point_series.data.push({ x, y, z, fillColor: named_color(color) }); | ||||
| point_series.data.push({ x, y, z, link, fillColor: named_color(color) }); | ||||
| } | ||||
| if (data.xmin == null) data.xmin = undefined; | ||||
| if (data.xmax == null) data.xmax = undefined; | ||||
|
|
@@ -165,6 +165,7 @@ const sqlpage_chart = (() => { | |||
| chart_type === "rangeBar" || (chart_type === "bar" && !!data.horizontal); | ||||
| const value_axis = inverted ? "x" : "y"; | ||||
| const category_axis = inverted ? "y" : "x"; | ||||
| const has_point_links = points.some((point) => point[5]); | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why use magic numbers as indexes if we have all the named vars deconstructed here SQLPage/frontend/src/apexcharts.js Line 114 in b41e4eb
|
||||
| const options = { | ||||
| annotations: { | ||||
| [`${value_axis}axis`]: reference_lines( | ||||
|
|
@@ -196,6 +197,12 @@ const sqlpage_chart = (() => { | |||
| zoom: { | ||||
| enabled: false, | ||||
| }, | ||||
| events: { | ||||
| dataPointSelection: (_event, _chart, args) => { | ||||
| const link = pointLink(args, points); | ||||
| if (link) window.location.assign(link); | ||||
| }, | ||||
| }, | ||||
| }, | ||||
| theme: { | ||||
| mode: isDarkTheme ? "dark" : "light", | ||||
|
|
@@ -268,8 +275,10 @@ const sqlpage_chart = (() => { | |||
| }, | ||||
| tooltip: { | ||||
| fillSeriesColor: false, | ||||
| custom: | ||||
| chart_type === "bubble" || chart_type === "scatter" | ||||
| interactive: has_point_links, | ||||
| custom: has_point_links | ||||
| ? (args) => chartTooltip(args, points) | ||||
| : chart_type === "bubble" || chart_type === "scatter" | ||||
| ? bubbleTooltip | ||||
| : undefined, | ||||
| y: { | ||||
|
|
@@ -312,17 +321,25 @@ const sqlpage_chart = (() => { | |||
| c.removeAttribute("data-pre-init"); | ||||
| } | ||||
|
|
||||
| function bubbleTooltip({ seriesIndex, dataPointIndex, w }) { | ||||
| const { name, data } = w.config.series[seriesIndex]; | ||||
| const point = data[dataPointIndex]; | ||||
| function chartTooltip({ seriesIndex, dataPointIndex, w }, raw_points) { | ||||
| const series = w.config.series[seriesIndex]; | ||||
| const has_series_data = Array.isArray(series?.data); | ||||
| const point_index = has_series_data ? dataPointIndex : seriesIndex; | ||||
| const raw_point = raw_points[point_index]; | ||||
| const name = series?.name || w.config.labels?.[point_index] || ""; | ||||
| const point = has_series_data | ||||
| ? series.data[dataPointIndex] | ||||
| : { y: raw_point?.[2], z: raw_point?.[4] }; | ||||
| const link = pointLink({ seriesIndex, dataPointIndex, w }, raw_points); | ||||
|
|
||||
| const tooltip = document.createElement("div"); | ||||
| tooltip.className = "apexcharts-tooltip-text"; | ||||
| tooltip.style.fontFamily = "inherit"; | ||||
|
|
||||
| const seriesName = document.createElement("div"); | ||||
| const seriesName = document.createElement(link ? "a" : "div"); | ||||
| seriesName.className = "apexcharts-tooltip-y-group"; | ||||
| seriesName.style.fontWeight = "bold"; | ||||
| if (seriesName instanceof HTMLAnchorElement) seriesName.href = link; | ||||
| seriesName.innerText = name; | ||||
| tooltip.appendChild(seriesName); | ||||
|
|
||||
|
|
@@ -340,13 +357,29 @@ const sqlpage_chart = (() => { | |||
| axisValue.appendChild(labelSpan); | ||||
| const valueSpan = document.createElement("span"); | ||||
| valueSpan.className = "apexcharts-tooltip-text-y-value"; | ||||
| valueSpan.innerText = value; | ||||
| const formatter = axis === "y" && w.config.tooltip.y.formatter; | ||||
| const format = (v) => | ||||
| formatter ? formatter(v, { seriesIndex, dataPointIndex, w }) : v; | ||||
| valueSpan.innerText = Array.isArray(value) | ||||
| ? value.map(format).join(" - ") | ||||
| : format(value); | ||||
| axisValue.appendChild(valueSpan); | ||||
| tooltip.appendChild(axisValue); | ||||
| } | ||||
| return tooltip.outerHTML; | ||||
| } | ||||
|
|
||||
| function pointLink({ seriesIndex, dataPointIndex, w }, raw_points) { | ||||
| const series = w.config.series[seriesIndex]; | ||||
| return Array.isArray(series?.data) | ||||
| ? series.data[dataPointIndex]?.link | ||||
| : raw_points[seriesIndex]?.[5]; | ||||
| } | ||||
|
|
||||
| function bubbleTooltip(args) { | ||||
| return chartTooltip(args, []); | ||||
| } | ||||
|
|
||||
| return sqlpage_chart; | ||||
| })(); | ||||
|
|
||||
|
|
||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| SELECT 'chart' AS component, 'test-chart' AS id, 'Chart test fixture' AS title, | ||
| 'bar' AS type; | ||
| SELECT 'Points' AS series, 'Linked' AS label, 10 AS value, '/linked.sql' AS link; | ||
| SELECT 'Points' AS series, 'Linked too' AS label, 20 AS value, '/linked-too.sql' AS link; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| SELECT 'chart' AS component, 'test-chart' AS id, 'Chart test fixture' AS title, | ||
| 'line' AS type, 8 AS marker; | ||
| SELECT 'Points' AS series, 1 AS x, 10 AS y, '/linked.sql' AS link; | ||
| SELECT 'Points' AS series, 2 AS x, 20 AS y, '/linked-too.sql' AS link; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| SELECT 'chart' AS component, 'test-chart' AS id, 'Chart test fixture' AS title, | ||
| 'pie' AS type; | ||
| SELECT 'Points' AS series, 'A' AS label, 10 AS value, '/linked.sql' AS link; | ||
| SELECT 'Points' AS series, 'B' AS label, 20 AS value, '/linked-too.sql' AS link; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| SELECT 'chart' AS component, 'test-chart' AS id, 'Chart test fixture' AS title, | ||
| 'scatter' AS type, 8 AS marker; | ||
| SELECT 'Points' AS series, 1 AS x, 1 AS y, '/linked.sql' AS link; | ||
| SELECT 'Points' AS series, 2 AS x, 2 AS y, '/linked-too.sql' AS link; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| SELECT 'chart' AS component, 'test-chart' AS id, 'Chart test fixture' AS title, | ||
| 'rangeBar' AS type, TRUE AS time; | ||
| SELECT 'Design' AS series, 'Alice' AS label, | ||
| '2024-03-01' AS value, '2024-03-05' AS value, | ||
| '/workpackage_edit.sql?workpackage_name=Design' AS link; | ||
| SELECT 'Research' AS series, 'Bob' AS label, | ||
| '2024-03-06' AS value, '2024-03-10' AS value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the intention for the tooltip to change like this when a link has been added? IMO it makes more sense not to do this and just hyperlink the title (ie ::
Tomin this case)