Skip to content

Commit dce96bf

Browse files
Merge branch 'sqlpage:main' into feature_divider
2 parents dc81c8f + 6199e6f commit dce96bf

15 files changed

Lines changed: 416 additions & 233 deletions

File tree

‎Cargo.lock‎

Lines changed: 113 additions & 125 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ panic = "abort"
3737
codegen-units = 2
3838

3939
[dependencies]
40-
sqlx = { package = "sqlx-core-oldapi", version = "0.6.57", default-features = false, features = [
40+
sqlx = { package = "sqlx-core-oldapi", version = "0.6.59", default-features = false, features = [
4141
"any",
4242
"runtime-tokio-rustls",
4343
"migrate",

‎frontend/src/apexcharts.ts‎

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type DataPoint = {
1818
link?: string;
1919
};
2020

21+
type AxisTitles = Record<"x" | "y" | "z", string | undefined>;
22+
2123
type TooltipArgs = {
2224
seriesIndex: number;
2325
dataPointIndex: number;
@@ -29,13 +31,25 @@ function formatTooltipX(
2931
value: string | number | null,
3032
link: string | undefined,
3133
) {
32-
if (!link || !value) return value;
34+
const text = value == null ? "" : String(value);
35+
if (!link || !value) return text;
3336
const anchor = document.createElement("a");
3437
anchor.setAttribute("href", link);
35-
anchor.textContent = String(value);
38+
anchor.textContent = text;
3639
return anchor.outerHTML;
3740
}
3841

42+
const rangeBarLabel = (_value: string | number, args?: TooltipArgs) =>
43+
args ? args.w.config.series[args.seriesIndex].name : "";
44+
45+
const pieLabel = (value: string | number, args?: TooltipArgs) =>
46+
args
47+
? `${args.w.config.labels[args.seriesIndex]}: ${Number(value).toFixed()}%`
48+
: "";
49+
50+
const numberLabel = (value: string | number) =>
51+
value == null ? "" : value.toLocaleString?.() || String(value);
52+
3953
const sqlpage_chart = (() => {
4054
function sqlpage_chart() {
4155
const charts = document.querySelectorAll<HTMLElement>(
@@ -195,7 +209,9 @@ const sqlpage_chart = (() => {
195209
);
196210

197211
const labels =
198-
chart_type === "pie" ? points.map(({ name, x }) => x || name) : undefined;
212+
chart_type === "pie"
213+
? points.map(({ name, x }) => String(x || name))
214+
: undefined;
199215
const series =
200216
chart_type === "pie"
201217
? points.map(({ y }) => Number.parseFloat(String(y)))
@@ -217,11 +233,16 @@ const sqlpage_chart = (() => {
217233
chart_type === "rangeBar" || (chart_type === "bar" && !!data.horizontal);
218234
const value_axis = inverted ? "x" : "y";
219235
const category_axis = inverted ? "y" : "x";
236+
const axis_titles: AxisTitles = {
237+
x: data.xtitle || undefined,
238+
y: data.ytitle || undefined,
239+
z: data.ztitle || undefined,
240+
};
220241
const has_point_links = points.some((point) => point.link);
221242
const text_x_values = chart_series.every(({ data }) =>
222243
data.every(({ x }) => x == null || typeof x === "string"),
223244
);
224-
const options = {
245+
const options: ApexOptions = {
225246
annotations: {
226247
[`${value_axis}axis`]: reference_lines(
227248
reference_rows,
@@ -254,7 +275,7 @@ const sqlpage_chart = (() => {
254275
},
255276
events: {
256277
dataPointSelection: (_event, _chart, args) => {
257-
const link = pointLink(args, points);
278+
const link = args && pointLink(args, points);
258279
if (link) window.location.assign(link);
259280
},
260281
},
@@ -274,11 +295,10 @@ const sqlpage_chart = (() => {
274295
},
275296
formatter:
276297
chart_type === "rangeBar"
277-
? (_val, { seriesIndex, w }) => w.config.series[seriesIndex].name
298+
? rangeBarLabel
278299
: chart_type === "pie"
279-
? (value, { seriesIndex, w }) =>
280-
`${w.config.labels[seriesIndex]}: ${value.toFixed()}%`
281-
: (value) => value?.toLocaleString?.() || value,
300+
? pieLabel
301+
: numberLabel,
282302
},
283303
fill: {
284304
type: chart_type === "area" ? "gradient" : "solid",
@@ -295,12 +315,15 @@ const sqlpage_chart = (() => {
295315
min: data.xmin,
296316
max: data.xmax,
297317
title: {
298-
text: data.xtitle || undefined,
318+
text: axis_titles.x,
299319
},
300320
type: xaxis_type,
301321
labels: {
302322
datetimeUTC: false,
303323
},
324+
// Numeric axes count intervals; category and time axes use tickAmount
325+
// as a target for label density.
326+
tickAmount: data.xticks || undefined,
304327
},
305328
yaxis: {
306329
logarithmic: !!data.logarithmic,
@@ -309,12 +332,7 @@ const sqlpage_chart = (() => {
309332
stepSize: data.ystep,
310333
tickAmount: data.yticks,
311334
title: {
312-
text: data.ytitle || undefined,
313-
},
314-
},
315-
zaxis: {
316-
title: {
317-
text: data.ztitle || undefined,
335+
text: axis_titles.y,
318336
},
319337
},
320338
markers: {
@@ -329,7 +347,7 @@ const sqlpage_chart = (() => {
329347
interactive: has_point_links,
330348
custom:
331349
chart_type === "bubble" || chart_type === "scatter"
332-
? bubbleTooltip
350+
? (args: TooltipArgs) => chartTooltip(args, axis_titles)
333351
: undefined,
334352
x: {
335353
formatter:
@@ -363,19 +381,18 @@ const sqlpage_chart = (() => {
363381
colors,
364382
series,
365383
};
366-
if (labels) (options as { labels?: unknown }).labels = labels;
367-
// Numeric axes count intervals; category and time axes use tickAmount as a
368-
// target for label density.
369-
if (data.xticks)
370-
(options.xaxis as { tickAmount?: number }).tickAmount = data.xticks;
371-
const chart = new ApexCharts(chartContainer, options as ApexOptions);
384+
if (labels) options.labels = labels;
385+
const chart = new ApexCharts(chartContainer, options);
372386
chart.render().catch(console.error);
373387
if (window.charts) window.charts.push(chart);
374388
else window.charts = [chart];
375389
c.removeAttribute("data-pre-init");
376390
}
377391

378-
function chartTooltip({ seriesIndex, dataPointIndex, w }: TooltipArgs) {
392+
function chartTooltip(
393+
{ seriesIndex, dataPointIndex, w }: TooltipArgs,
394+
titles: AxisTitles,
395+
) {
379396
const series = w.config.series[seriesIndex];
380397
const name = series?.name || "";
381398
const point = series?.data[dataPointIndex];
@@ -390,14 +407,12 @@ const sqlpage_chart = (() => {
390407
seriesName.innerText = name;
391408
tooltip.appendChild(seriesName);
392409

393-
for (const axis of ["x", "y", "z"]) {
410+
for (const axis of ["x", "y", "z"] as const) {
394411
const value = point[axis];
395412
if (value == null) continue;
396413
const axisValue = document.createElement("div");
397414
axisValue.className = "apexcharts-tooltip-y-group";
398-
let axis_conf = w.config[`${axis}axis`];
399-
if (axis_conf.length) axis_conf = axis_conf[0];
400-
const title = axis_conf.title.text || axis;
415+
const title = titles[axis] || axis;
401416
const labelSpan = document.createElement("span");
402417
labelSpan.className = "apexcharts-tooltip-text-y-label";
403418
labelSpan.innerText = `${title}: `;
@@ -426,10 +441,6 @@ const sqlpage_chart = (() => {
426441
: points[seriesIndex]?.link;
427442
}
428443

429-
function bubbleTooltip(args: TooltipArgs) {
430-
return chartTooltip(args);
431-
}
432-
433444
return sqlpage_chart;
434445
})();
435446

‎frontend/src/globals.d.ts‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
// Names the browser bundle relies on at runtime rather than through an import:
2-
// libraries loaded on demand, and what a page may provide for our scripts.
3-
4-
/**
5-
* A library this project ships no type definitions for. Saying `unknown`
6-
* instead would only move the guesswork to a cast at every call site.
7-
*/
8-
// biome-ignore lint/suspicious/noExplicitAny: that is what an untyped library is
9-
type Untyped = any;
10-
11-
/** Leaflet, loaded from a CDN by sqlpage_map when a page holds a map. */
12-
declare const L: Untyped;
1+
// Names the browser bundle relies on at runtime rather than through an import.
132

143
interface Window {
154
/** Every chart rendered on the page, in the order they were built. */

0 commit comments

Comments
 (0)