@ruckc/truss-chart 1.48.1 → 1.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BarChart.svelte +36 -5
- package/dist/BarChart.svelte.d.ts +15 -0
- package/dist/ChartFrame.svelte +20 -3
- package/dist/ChartFrame.svelte.d.ts +13 -0
- package/dist/ColorScale.svelte +15 -2
- package/dist/ColorScale.svelte.d.ts +6 -0
- package/dist/DensityChart.svelte +115 -21
- package/dist/DensityChart.svelte.d.ts +57 -0
- package/dist/DonutChart.svelte +45 -7
- package/dist/DonutChart.svelte.d.ts +20 -0
- package/dist/Histogram.svelte +39 -5
- package/dist/Histogram.svelte.d.ts +17 -0
- package/dist/LineChart.svelte +44 -7
- package/dist/LineChart.svelte.d.ts +19 -0
- package/dist/ScatterChart.svelte +53 -9
- package/dist/ScatterChart.svelte.d.ts +23 -0
- package/dist/StatTile.svelte +39 -5
- package/dist/StatTile.svelte.d.ts +15 -0
- package/dist/index.d.ts +8 -0
- package/dist/labels.d.ts +6 -0
- package/dist/labels.js +23 -0
- package/package.json +1 -1
package/dist/BarChart.svelte
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { FRAME_DEFAULTS, type ChartFrameLabels } from './ChartFrame.svelte';
|
|
3
|
+
|
|
4
|
+
export type BarChartLabels = ChartFrameLabels & {
|
|
5
|
+
/** Name of the chart in its accessible name when there is no `title`. */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Accessible name of the chart: its title (or `name`) and the hint that a table view exists. */
|
|
8
|
+
tableHint: (name: string) => string;
|
|
9
|
+
/** Header of the category column in the table view. */
|
|
10
|
+
category: string;
|
|
11
|
+
/** Header of the extra-text column in the table view (`details`). */
|
|
12
|
+
details: string;
|
|
13
|
+
/** Row header of a reference line that has no label. */
|
|
14
|
+
reference: string;
|
|
15
|
+
};
|
|
16
|
+
const DEFAULTS: BarChartLabels = {
|
|
17
|
+
...FRAME_DEFAULTS,
|
|
18
|
+
name: 'Bar chart',
|
|
19
|
+
tableHint: (name) => `${name}. A table view is available.`,
|
|
20
|
+
category: 'Category',
|
|
21
|
+
details: 'Details',
|
|
22
|
+
reference: 'Reference'
|
|
23
|
+
};
|
|
24
|
+
</script>
|
|
25
|
+
|
|
1
26
|
<script lang="ts">
|
|
2
27
|
import ChartFrame from './ChartFrame.svelte';
|
|
28
|
+
import { useLabels } from './labels.js';
|
|
3
29
|
import { cssvars } from './cssvars.js';
|
|
4
30
|
import { watchFill } from './fill.js';
|
|
5
31
|
import Tooltip from './Tooltip.svelte';
|
|
@@ -18,7 +44,8 @@
|
|
|
18
44
|
reference,
|
|
19
45
|
details,
|
|
20
46
|
yFormat: yFormatProp,
|
|
21
|
-
onselect
|
|
47
|
+
onselect,
|
|
48
|
+
labels
|
|
22
49
|
}: {
|
|
23
50
|
categories: string[];
|
|
24
51
|
/** Up to 8 series (fixed-order palette). Negative values are allowed everywhere, including stacked bars. */
|
|
@@ -45,8 +72,12 @@
|
|
|
45
72
|
yFormat?: (n: number) => string;
|
|
46
73
|
/** Called with the bar's `category`, `series`, category `index` and raw `value` when a bar is clicked or activated with Enter / Space (bars are focusable). Also makes the table view's value cells buttons. Sets a pointer cursor on the bars. */
|
|
47
74
|
onselect?: (d: ChartSelection) => void;
|
|
75
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
76
|
+
labels?: Partial<BarChartLabels>;
|
|
48
77
|
} = $props();
|
|
49
78
|
|
|
79
|
+
const L = useLabels('BarChart', DEFAULTS, () => labels);
|
|
80
|
+
|
|
50
81
|
type Ref = { value: number; label?: string };
|
|
51
82
|
const yFormat = $derived(yFormatProp ?? fmtValue);
|
|
52
83
|
const yTick = $derived(yFormatProp ?? fmtAxis);
|
|
@@ -138,7 +169,7 @@
|
|
|
138
169
|
</script>
|
|
139
170
|
|
|
140
171
|
{#snippet chart()}
|
|
141
|
-
<ChartFrame {title} {subtitle} {items} ontoggle={toggle}>
|
|
172
|
+
<ChartFrame {title} {subtitle} {items} ontoggle={toggle} labels={{ chart: L.chart, table: L.table, legend: L.legend }}>
|
|
142
173
|
{#snippet plot(w)}
|
|
143
174
|
{@const height = H}
|
|
144
175
|
{@const m = horizontal ? { top: refs.length ? 24 : 10, right: showValues ? 56 : 14, bottom: 26, left: labelWidth } : { top: showValues ? 22 : 12, right: 12, bottom: 28, left: 46 }}
|
|
@@ -152,7 +183,7 @@
|
|
|
152
183
|
{@const cluster = isStack ? thick : thick * nb + 2 * (nb - 1)}
|
|
153
184
|
{@const catPos = (c: number) => (horizontal ? m.top : m.left) + band * c + band / 2}
|
|
154
185
|
|
|
155
|
-
<svg width={w} height={plotH} role="img" aria-label=
|
|
186
|
+
<svg width={w} height={plotH} role="img" aria-label={L.tableHint(title ?? L.name)} onpointerleave={() => (tip = null)}>
|
|
156
187
|
{#each scale.ticks as t}
|
|
157
188
|
{#if horizontal}
|
|
158
189
|
<line class="grid" x1={V(t)} x2={V(t)} y1={m.top} y2={plotH - m.bottom} data-zero={t === 0} />
|
|
@@ -240,7 +271,7 @@
|
|
|
240
271
|
|
|
241
272
|
{#snippet table()}
|
|
242
273
|
<table>
|
|
243
|
-
<thead><tr><th>
|
|
274
|
+
<thead><tr><th>{L.category}</th>{#each all as s}<th>{s.name}</th>{/each}{#if details}<th>{L.details}</th>{/if}</tr></thead>
|
|
244
275
|
<tbody>
|
|
245
276
|
{#each categories as c, i}
|
|
246
277
|
<tr><td>{c}</td>{#each all as s}<td>{#if s.values[i] == null}—{:else if onselect}<button type="button" class="act" onclick={() => pick(i, s.name, s.values[i]!)}>{yFormat(s.values[i]!)}</button>{:else}{yFormat(s.values[i]!)}{/if}</td>{/each}{#if details}<td>{details[i] ?? ''}</td>{/if}</tr>
|
|
@@ -248,7 +279,7 @@
|
|
|
248
279
|
</tbody>
|
|
249
280
|
{#if refs.length}
|
|
250
281
|
<tfoot>
|
|
251
|
-
{#each refs as r}<tr><th scope="row">{r.label ??
|
|
282
|
+
{#each refs as r}<tr><th scope="row">{r.label ?? L.reference}</th><td colspan={all.length + 1}>{fmt(r.value)}</td></tr>{/each}
|
|
252
283
|
</tfoot>
|
|
253
284
|
{/if}
|
|
254
285
|
</table>
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import { type ChartFrameLabels } from './ChartFrame.svelte';
|
|
2
|
+
export type BarChartLabels = ChartFrameLabels & {
|
|
3
|
+
/** Name of the chart in its accessible name when there is no `title`. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Accessible name of the chart: its title (or `name`) and the hint that a table view exists. */
|
|
6
|
+
tableHint: (name: string) => string;
|
|
7
|
+
/** Header of the category column in the table view. */
|
|
8
|
+
category: string;
|
|
9
|
+
/** Header of the extra-text column in the table view (`details`). */
|
|
10
|
+
details: string;
|
|
11
|
+
/** Row header of a reference line that has no label. */
|
|
12
|
+
reference: string;
|
|
13
|
+
};
|
|
1
14
|
import type { ChartSelection, Series } from './types.js';
|
|
2
15
|
type Ref = {
|
|
3
16
|
value: number;
|
|
@@ -29,6 +42,8 @@ type $$ComponentProps = {
|
|
|
29
42
|
yFormat?: (n: number) => string;
|
|
30
43
|
/** Called with the bar's `category`, `series`, category `index` and raw `value` when a bar is clicked or activated with Enter / Space (bars are focusable). Also makes the table view's value cells buttons. Sets a pointer cursor on the bars. */
|
|
31
44
|
onselect?: (d: ChartSelection) => void;
|
|
45
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
46
|
+
labels?: Partial<BarChartLabels>;
|
|
32
47
|
};
|
|
33
48
|
declare const BarChart: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
34
49
|
type BarChart = ReturnType<typeof BarChart>;
|
package/dist/ChartFrame.svelte
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
/** The three words the frame shows around every chart. Each chart carries them under the same keys in its own labels and passes them in. */
|
|
3
|
+
export type ChartFrameLabels = {
|
|
4
|
+
/** Table-view toggle while the table is shown: back to the chart. */
|
|
5
|
+
chart: string;
|
|
6
|
+
/** Table-view toggle while the chart is shown. */
|
|
7
|
+
table: string;
|
|
8
|
+
/** Accessible name of the legend list. */
|
|
9
|
+
legend: string;
|
|
10
|
+
};
|
|
11
|
+
/** English defaults, spread into each chart's own defaults. */
|
|
12
|
+
export const FRAME_DEFAULTS: ChartFrameLabels = { chart: 'Chart', table: 'Table', legend: 'Legend' };
|
|
13
|
+
</script>
|
|
14
|
+
|
|
1
15
|
<script lang="ts">
|
|
2
16
|
import type { Snippet } from 'svelte';
|
|
3
17
|
import { cssvars } from './cssvars.js';
|
|
@@ -11,7 +25,8 @@
|
|
|
11
25
|
items = [],
|
|
12
26
|
ontoggle,
|
|
13
27
|
plot,
|
|
14
|
-
table
|
|
28
|
+
table,
|
|
29
|
+
labels
|
|
15
30
|
}: {
|
|
16
31
|
title?: string;
|
|
17
32
|
subtitle?: string;
|
|
@@ -21,6 +36,8 @@
|
|
|
21
36
|
plot: Snippet<[width: number]>;
|
|
22
37
|
/** Table alternative — every value reachable without hover. */
|
|
23
38
|
table: Snippet;
|
|
39
|
+
/** The frame's own texts, resolved by the chart that renders it. */
|
|
40
|
+
labels: ChartFrameLabels;
|
|
24
41
|
} = $props();
|
|
25
42
|
|
|
26
43
|
let width = $state(640);
|
|
@@ -34,13 +51,13 @@
|
|
|
34
51
|
{#if subtitle}<div class="sub">{subtitle}</div>{/if}
|
|
35
52
|
</div>
|
|
36
53
|
<button type="button" class="tv" aria-pressed={showTable} onclick={() => (showTable = !showTable)}>
|
|
37
|
-
{showTable ?
|
|
54
|
+
{showTable ? labels.chart : labels.table}
|
|
38
55
|
</button>
|
|
39
56
|
</figcaption>
|
|
40
57
|
|
|
41
58
|
{#if items.length > 1}
|
|
42
59
|
<SsrStyle {uid} rules={Object.fromEntries(items.map((it, k) => [` li:nth-child(${k + 1}) .key`, `background:${it.color}`]))} />
|
|
43
|
-
<ul class="legend" data-sv={uid} aria-label=
|
|
60
|
+
<ul class="legend" data-sv={uid} aria-label={labels.legend}>
|
|
44
61
|
{#each items as it (it.name)}
|
|
45
62
|
<li>
|
|
46
63
|
<button type="button" aria-pressed={!it.hidden} onclick={() => ontoggle?.(it.name)}>
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/** The three words the frame shows around every chart. Each chart carries them under the same keys in its own labels and passes them in. */
|
|
2
|
+
export type ChartFrameLabels = {
|
|
3
|
+
/** Table-view toggle while the table is shown: back to the chart. */
|
|
4
|
+
chart: string;
|
|
5
|
+
/** Table-view toggle while the chart is shown. */
|
|
6
|
+
table: string;
|
|
7
|
+
/** Accessible name of the legend list. */
|
|
8
|
+
legend: string;
|
|
9
|
+
};
|
|
10
|
+
/** English defaults, spread into each chart's own defaults. */
|
|
11
|
+
export declare const FRAME_DEFAULTS: ChartFrameLabels;
|
|
1
12
|
import type { Snippet } from 'svelte';
|
|
2
13
|
import type { LegendItem } from './types.js';
|
|
3
14
|
type $$ComponentProps = {
|
|
@@ -9,6 +20,8 @@ type $$ComponentProps = {
|
|
|
9
20
|
plot: Snippet<[width: number]>;
|
|
10
21
|
/** Table alternative — every value reachable without hover. */
|
|
11
22
|
table: Snippet;
|
|
23
|
+
/** The frame's own texts, resolved by the chart that renders it. */
|
|
24
|
+
labels: ChartFrameLabels;
|
|
12
25
|
};
|
|
13
26
|
declare const ChartFrame: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
14
27
|
type ChartFrame = ReturnType<typeof ChartFrame>;
|
package/dist/ColorScale.svelte
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export type ColorScaleLabels = {
|
|
3
|
+
/** Accessible name when `label` is not set: the visible `caption` (undefined when there is none) and the two ends, e.g. "Error rate: 0% to 40+%". */
|
|
4
|
+
name: (caption: string | undefined, low: string, high: string) => string;
|
|
5
|
+
};
|
|
6
|
+
const DEFAULTS: ColorScaleLabels = { name: (caption, low, high) => `${caption ? `${caption}: ` : ''}${low} to ${high}` };
|
|
7
|
+
</script>
|
|
8
|
+
|
|
1
9
|
<script lang="ts">
|
|
10
|
+
import { useLabels } from './labels.js';
|
|
2
11
|
import { cssvars } from './cssvars.js';
|
|
3
12
|
import SsrStyle from './SsrStyle.svelte';
|
|
4
13
|
const uid = $props.id();
|
|
@@ -14,7 +23,8 @@
|
|
|
14
23
|
gradient,
|
|
15
24
|
stops,
|
|
16
25
|
vertical = false,
|
|
17
|
-
size = 200
|
|
26
|
+
size = 200,
|
|
27
|
+
labels
|
|
18
28
|
}: {
|
|
19
29
|
/** Label at the low end, e.g. `0%`. */
|
|
20
30
|
low: string;
|
|
@@ -43,9 +53,12 @@
|
|
|
43
53
|
vertical?: boolean;
|
|
44
54
|
/** Bar length in px. */
|
|
45
55
|
size?: number;
|
|
56
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
57
|
+
labels?: Partial<ColorScaleLabels>;
|
|
46
58
|
} = $props();
|
|
47
59
|
|
|
48
|
-
const
|
|
60
|
+
const L = useLabels('ColorScale', DEFAULTS, () => labels);
|
|
61
|
+
const name = $derived(label ?? L.name(caption, low, high));
|
|
49
62
|
// precedence: gradient > stops (2 or more) > palette
|
|
50
63
|
const bg = $derived.by(() => {
|
|
51
64
|
const dir = vertical ? 'to top' : 'to right';
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export type ColorScaleLabels = {
|
|
2
|
+
/** Accessible name when `label` is not set: the visible `caption` (undefined when there is none) and the two ends, e.g. "Error rate: 0% to 40+%". */
|
|
3
|
+
name: (caption: string | undefined, low: string, high: string) => string;
|
|
4
|
+
};
|
|
1
5
|
import { type ScaleKind } from './util.js';
|
|
2
6
|
type $$ComponentProps = {
|
|
3
7
|
/** Label at the low end, e.g. `0%`. */
|
|
@@ -27,6 +31,8 @@ type $$ComponentProps = {
|
|
|
27
31
|
vertical?: boolean;
|
|
28
32
|
/** Bar length in px. */
|
|
29
33
|
size?: number;
|
|
34
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
35
|
+
labels?: Partial<ColorScaleLabels>;
|
|
30
36
|
};
|
|
31
37
|
declare const ColorScale: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
32
38
|
type ColorScale = ReturnType<typeof ColorScale>;
|
package/dist/DensityChart.svelte
CHANGED
|
@@ -1,4 +1,93 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { FRAME_DEFAULTS, type ChartFrameLabels } from './ChartFrame.svelte';
|
|
3
|
+
|
|
4
|
+
export type DensityChartLabels = ChartFrameLabels & {
|
|
5
|
+
/** Name of the chart in its accessible name when there is no `title`. */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Accessible name of the chart: its title (or `name`), the number of points and the keyboard and pointer hints. `total` is already formatted. */
|
|
8
|
+
keys: (name: string, total: string) => string;
|
|
9
|
+
/** Name of the `highlight` set when it has no `name`. */
|
|
10
|
+
highlighted: string;
|
|
11
|
+
/** Legend entry for the points when highlights exist and the points have no groups; also the count column of the table view. */
|
|
12
|
+
points: string;
|
|
13
|
+
/** Tooltip title of a heatmap cell. */
|
|
14
|
+
bin: string;
|
|
15
|
+
/** Name of the count in a heatmap cell's tooltip (lower case, after the number). */
|
|
16
|
+
pointsLower: string;
|
|
17
|
+
/** Tooltip title of a point that has no label or group; header of the first column of the highlight table. */
|
|
18
|
+
point: string;
|
|
19
|
+
/** Name of the x axis in the readout and tooltip when there is no `xLabel`. */
|
|
20
|
+
x: string;
|
|
21
|
+
/** Name of the y axis in the readout and tooltip when there is no `yLabel`. */
|
|
22
|
+
y: string;
|
|
23
|
+
/** Header of the x column in the tables when there is no `xLabel`. */
|
|
24
|
+
xHeader: string;
|
|
25
|
+
/** Header of the y column in the tables when there is no `yLabel`. */
|
|
26
|
+
yHeader: string;
|
|
27
|
+
/** Button that returns to the full view. */
|
|
28
|
+
resetView: string;
|
|
29
|
+
/** Caption of the colour key under the plot. */
|
|
30
|
+
colorKey: string;
|
|
31
|
+
/** Live-region text: how many points are in view (formatted), the total (formatted), and how they are drawn (`markers` true: as individual markers, false: as a density heatmap). */
|
|
32
|
+
readout: (inView: string, total: string, markers: boolean) => string;
|
|
33
|
+
/** Live-region text: the visible range of each axis (the axis names, then the formatted limits). */
|
|
34
|
+
readoutRange: (xName: string, x0: string, x1: string, yName: string, y0: string, y1: string) => string;
|
|
35
|
+
/** Live-region text: how many of the highlighted points are in view (formatted). */
|
|
36
|
+
highlightReadout: (name: string, inView: string) => string;
|
|
37
|
+
/** A range of values: from and to (formatted), in the table's region cells. */
|
|
38
|
+
span: (from: string, to: string) => string;
|
|
39
|
+
/** Caption of the table: the points in view (formatted) and into how many regions they are grouped. */
|
|
40
|
+
summary: (n: string, regions: number) => string;
|
|
41
|
+
/** Added to that caption when only the busiest regions are listed; `shown` is how many. */
|
|
42
|
+
busiest: (shown: number) => string;
|
|
43
|
+
/** Header of the percentage column in the table view. */
|
|
44
|
+
share: string;
|
|
45
|
+
/** Table row when no point is in view. */
|
|
46
|
+
noPoints: string;
|
|
47
|
+
/** Caption of the highlight table: the set's name and its state (`hidden`, or `inView` with `firstShown` added when the list is cut). */
|
|
48
|
+
highlightCaption: (name: string, text: string) => string;
|
|
49
|
+
/** State of a hidden highlight set. */
|
|
50
|
+
hidden: string;
|
|
51
|
+
/** State of a visible highlight set: how many points are in view (formatted). */
|
|
52
|
+
inView: (n: string) => string;
|
|
53
|
+
/** Added to that state when the table lists only the first rows; `shown` is how many. */
|
|
54
|
+
firstShown: (shown: number) => string;
|
|
55
|
+
/** Highlight table row when no highlighted point is in view. */
|
|
56
|
+
noHighlights: string;
|
|
57
|
+
};
|
|
58
|
+
const DEFAULTS: DensityChartLabels = {
|
|
59
|
+
...FRAME_DEFAULTS,
|
|
60
|
+
name: 'Density chart',
|
|
61
|
+
keys: (name, total) => `${name}, ${total} points. Drag or arrow keys pan, wheel or plus and minus zoom, 0 resets the view.`,
|
|
62
|
+
highlighted: 'Highlighted',
|
|
63
|
+
points: 'Points',
|
|
64
|
+
bin: 'Bin',
|
|
65
|
+
pointsLower: 'points',
|
|
66
|
+
point: 'Point',
|
|
67
|
+
x: 'x',
|
|
68
|
+
y: 'y',
|
|
69
|
+
xHeader: 'X',
|
|
70
|
+
yHeader: 'Y',
|
|
71
|
+
resetView: 'Reset view',
|
|
72
|
+
colorKey: 'Points per cell, log scale',
|
|
73
|
+
readout: (inView, total, markers) => `${inView} of ${total} points in view, drawn as ${markers ? 'individual markers' : 'a density heatmap'}.`,
|
|
74
|
+
readoutRange: (xName, x0, x1, yName, y0, y1) => `${xName} ${x0} to ${x1}, ${yName} ${y0} to ${y1}.`,
|
|
75
|
+
highlightReadout: (name, inView) => `${name}: ${inView} in view.`,
|
|
76
|
+
span: (from, to) => `${from} to ${to}`,
|
|
77
|
+
summary: (n, regions) => `${n} points in view, grouped into ${regions} regions`,
|
|
78
|
+
busiest: (shown) => `(busiest ${shown} shown)`,
|
|
79
|
+
share: 'Share',
|
|
80
|
+
noPoints: 'No points in view',
|
|
81
|
+
highlightCaption: (name, text) => `${name}: ${text}`,
|
|
82
|
+
hidden: 'hidden',
|
|
83
|
+
inView: (n) => `${n} in view`,
|
|
84
|
+
firstShown: (shown) => `(first ${shown} shown)`,
|
|
85
|
+
noHighlights: 'No highlighted points in view'
|
|
86
|
+
};
|
|
87
|
+
</script>
|
|
88
|
+
|
|
1
89
|
<script lang="ts">
|
|
90
|
+
import { useLabels } from './labels.js';
|
|
2
91
|
import type { Snippet } from 'svelte';
|
|
3
92
|
import { startDrag } from '@ruckc/truss-ui';
|
|
4
93
|
import ChartFrame from './ChartFrame.svelte';
|
|
@@ -32,7 +121,8 @@
|
|
|
32
121
|
tooltip,
|
|
33
122
|
colorKey = true,
|
|
34
123
|
maxCount = $bindable(0),
|
|
35
|
-
ramp = $bindable([])
|
|
124
|
+
ramp = $bindable([]),
|
|
125
|
+
labels
|
|
36
126
|
}: {
|
|
37
127
|
/** Object input, convenient up to ~10^5 points. `group` picks the palette colour of markers and a legend entry (max 8). */
|
|
38
128
|
points?: DensityPoint[];
|
|
@@ -80,20 +170,24 @@
|
|
|
80
170
|
maxCount?: number;
|
|
81
171
|
/** Bindable: the resolved heatmap ramp, low to high, as CSS colours (from `--trc-seq-*` or the built-in fallback). */
|
|
82
172
|
ramp?: string[];
|
|
173
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
174
|
+
labels?: Partial<DensityChartLabels>;
|
|
83
175
|
} = $props();
|
|
84
176
|
|
|
177
|
+
const L = useLabels('DensityChart', DEFAULTS, () => labels);
|
|
178
|
+
|
|
85
179
|
const full = $derived(prepare(points, xs, ys, groupIds, groupNames));
|
|
86
180
|
let hidden = $state<string[]>([]);
|
|
87
|
-
const hlName = $derived(highlight?.name ??
|
|
181
|
+
const hlName = $derived(highlight?.name ?? L.highlighted);
|
|
88
182
|
const hlHidden = $derived(hidden.includes(hlName));
|
|
89
183
|
// an ungrouped set gets a "Points" legend entry once highlights exist, so the two can be toggled independently
|
|
90
184
|
const dotsEntry = $derived(!!highlight && full.names.length === 0);
|
|
91
|
-
const dotsHidden = $derived(dotsEntry && hidden.includes(
|
|
185
|
+
const dotsHidden = $derived(dotsEntry && hidden.includes(L.points));
|
|
92
186
|
const data = $derived<Prepared>(dotsHidden ? { ...full, n: 0 } : full);
|
|
93
187
|
const hid = $derived(Uint8Array.from({ length: 8 }, (_, i) => (hidden.includes(full.names[i]) ? 1 : 0)));
|
|
94
188
|
const hl = $derived<Prepared | null>(highlight ? { xs: highlight.xs, ys: highlight.ys, g: null, names: [], n: Math.min(highlight.xs.length, highlight.ys.length), extent: null } : null);
|
|
95
189
|
const items = $derived([
|
|
96
|
-
...(dotsEntry ? [{ name:
|
|
190
|
+
...(dotsEntry ? [{ name: L.points, color: seriesColor(0), hidden: dotsHidden }] : full.names.map((name, i) => ({ name, color: seriesColor(i), hidden: hidden.includes(name) }))),
|
|
97
191
|
...(highlight ? [{ name: hlName, color: 'var(--tr-on-surface)', hidden: hlHidden }] : [])
|
|
98
192
|
]);
|
|
99
193
|
const noHid = new Uint8Array(8);
|
|
@@ -141,9 +235,9 @@
|
|
|
141
235
|
});
|
|
142
236
|
|
|
143
237
|
const readout = $derived(
|
|
144
|
-
`${fmtValue(inView)
|
|
145
|
-
|
|
146
|
-
(hl ? ` ${hlName
|
|
238
|
+
`${L.readout(fmtValue(inView), fmtValue(total), mode === 'markers')} ` +
|
|
239
|
+
L.readoutRange(xLabel ?? L.x, xFormat(cur.x0), xFormat(cur.x1), yLabel ?? L.y, yFormat(cur.y0), yFormat(cur.y1)) +
|
|
240
|
+
(hl ? ` ${L.highlightReadout(hlName, fmtValue(hlIn))}` : '')
|
|
147
241
|
);
|
|
148
242
|
|
|
149
243
|
// ── drawing (redraw once per frame, whatever changed)
|
|
@@ -353,7 +447,7 @@
|
|
|
353
447
|
const x = m.left + ((src.xs[i] - v.x0) / (v.x1 - v.x0)) * pw, y = m.top + ph - ((src.ys[i] - v.y0) / (v.y1 - v.y0)) * ph;
|
|
354
448
|
const group = hi >= 0 ? hlName : data.g ? data.names[data.g[i]] : undefined;
|
|
355
449
|
hover = {
|
|
356
|
-
x, y, head: label ?? group ??
|
|
450
|
+
x, y, head: label ?? group ?? L.point, rows: [[xFormat(src.xs[i]), xLabel ?? L.x], [yFormat(src.ys[i]), yLabel ?? L.y]], rx: x - 6, ry: y - 6, rw: 12, rh: 12,
|
|
357
451
|
item: { kind: 'point', index: i, x: src.xs[i], y: src.ys[i], group, highlight: hi >= 0, label }
|
|
358
452
|
};
|
|
359
453
|
return;
|
|
@@ -366,8 +460,8 @@
|
|
|
366
460
|
const sx = (v.x1 - v.x0) / gCols, sy = (v.y1 - v.y0) / gRows;
|
|
367
461
|
const bx = v.x0 + k * sx, by = v.y1 - (q + 1) * sy;
|
|
368
462
|
hover = {
|
|
369
|
-
x: px, y: py, head:
|
|
370
|
-
rows: [[fmtValue(cnt),
|
|
463
|
+
x: px, y: py, head: L.bin,
|
|
464
|
+
rows: [[fmtValue(cnt), L.pointsLower], [L.span(xFormat(bx), xFormat(bx + sx)), xLabel ?? L.x], [L.span(yFormat(by), yFormat(by + sy)), yLabel ?? L.y]],
|
|
371
465
|
rx: m.left + k * cw1, ry: m.top + q * ch1, rw: cw1, rh: ch1,
|
|
372
466
|
item: { kind: 'bin', count: cnt, x0: bx, x1: bx + sx, y0: by, y1: by + sy }
|
|
373
467
|
};
|
|
@@ -397,7 +491,7 @@
|
|
|
397
491
|
for (let i = 0; i < out.length; i++)
|
|
398
492
|
if (out[i]) {
|
|
399
493
|
const c = i % TC, r = (i - c) / TC;
|
|
400
|
-
rows.push({ x:
|
|
494
|
+
rows.push({ x: L.span(xFormat(cur.x0 + c * sx), xFormat(cur.x0 + (c + 1) * sx)), y: L.span(yFormat(cur.y0 + r * sy), yFormat(cur.y0 + (r + 1) * sy)), count: out[i], share: `${((out[i] / n) * 100).toFixed(1)}%` });
|
|
401
495
|
}
|
|
402
496
|
rows.sort((a, b) => b.count - a.count);
|
|
403
497
|
return { n, regions: rows.length, rows: rows.slice(0, 12) };
|
|
@@ -417,13 +511,13 @@
|
|
|
417
511
|
</script>
|
|
418
512
|
|
|
419
513
|
{#snippet chart()}
|
|
420
|
-
<ChartFrame {title} {subtitle} {items} ontoggle={toggle}>
|
|
514
|
+
<ChartFrame {title} {subtitle} {items} ontoggle={toggle} labels={{ chart: L.chart, table: L.table, legend: L.legend }}>
|
|
421
515
|
{#snippet plot(w)}
|
|
422
516
|
<SsrStyle {uid} rules={{ ' canvas': `height:${H}px` }} />
|
|
423
517
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
|
|
424
518
|
<div
|
|
425
519
|
class="dc" data-sv={uid} role="group" tabindex="0" bind:this={box} bind:clientWidth={cw}
|
|
426
|
-
aria-label=
|
|
520
|
+
aria-label={L.keys(title ?? L.name, fmtValue(total))}
|
|
427
521
|
onpointerdown={down} onpointermove={move}
|
|
428
522
|
onpointerleave={() => (hover = null)} onblur={() => (hover = null)} onkeydown={key}
|
|
429
523
|
ondblclick={(e) => { const r = box!.getBoundingClientRect(); zoomAt(e.clientX - r.left, e.clientY - r.top, 2); }}
|
|
@@ -431,7 +525,7 @@
|
|
|
431
525
|
<canvas bind:this={canvas} {@attach cssvars(() => ({ height: `${H}px` }))} aria-hidden="true" data-mode={mode || undefined}></canvas>
|
|
432
526
|
{#if hover}<div class="ring" {@attach csstext(() => `left: ${hover!.rx}px; top: ${hover!.ry}px; width: ${hover!.rw}px; height: ${hover!.rh}px`)}></div>{/if}
|
|
433
527
|
</div>
|
|
434
|
-
<button type="button" class="reset" disabled={zoom === null} onclick={reset}>
|
|
528
|
+
<button type="button" class="reset" disabled={zoom === null} onclick={reset}>{L.resetView}</button>
|
|
435
529
|
<div class="sr" role="status" aria-live="polite">{readout}</div>
|
|
436
530
|
|
|
437
531
|
{#if hover}
|
|
@@ -448,31 +542,31 @@
|
|
|
448
542
|
{/if}
|
|
449
543
|
|
|
450
544
|
{#if colorKey && mode === 'heatmap'}
|
|
451
|
-
<div class="key"><ColorScale caption=
|
|
545
|
+
<div class="key"><ColorScale caption={L.colorKey} low="1" mid={fmtValue(Math.max(1, Math.round(Math.sqrt(peak + 1) - 1)))} high={fmtValue(peak)} size={180} /></div>
|
|
452
546
|
{/if}
|
|
453
547
|
{/snippet}
|
|
454
548
|
|
|
455
549
|
{#snippet table()}
|
|
456
550
|
<table>
|
|
457
|
-
<caption>{fmtValue(summary.n)
|
|
458
|
-
<thead><tr><th>{xLabel ??
|
|
551
|
+
<caption>{L.summary(fmtValue(summary.n), summary.regions)}{summary.regions > summary.rows.length ? ` ${L.busiest(summary.rows.length)}` : ''}</caption>
|
|
552
|
+
<thead><tr><th>{xLabel ?? L.xHeader}</th><th>{yLabel ?? L.yHeader}</th><th>{L.points}</th><th>{L.share}</th></tr></thead>
|
|
459
553
|
<tbody>
|
|
460
554
|
{#each summary.rows as r}
|
|
461
555
|
<tr><td>{r.x}</td><td>{r.y}</td><td>{fmtValue(r.count)}</td><td>{r.share}</td></tr>
|
|
462
556
|
{:else}
|
|
463
|
-
<tr><td colspan="4">
|
|
557
|
+
<tr><td colspan="4">{L.noPoints}</td></tr>
|
|
464
558
|
{/each}
|
|
465
559
|
</tbody>
|
|
466
560
|
</table>
|
|
467
561
|
{#if highlight}
|
|
468
562
|
<table class="hl">
|
|
469
|
-
<caption>{hlName
|
|
470
|
-
<thead><tr><th>
|
|
563
|
+
<caption>{L.highlightCaption(hlName, hlHidden ? L.hidden : `${L.inView(fmtValue(hlRows.inside))}${hlRows.inside > hlRows.rows.length ? ` ${L.firstShown(hlRows.rows.length)}` : ''}`)}</caption>
|
|
564
|
+
<thead><tr><th>{L.point}</th><th>{xLabel ?? L.xHeader}</th><th>{yLabel ?? L.yHeader}</th></tr></thead>
|
|
471
565
|
<tbody>
|
|
472
566
|
{#each hlRows.rows as r}
|
|
473
567
|
<tr><td>{r.label}</td><td>{r.x}</td><td>{r.y}</td></tr>
|
|
474
568
|
{:else}
|
|
475
|
-
<tr><td colspan="3">
|
|
569
|
+
<tr><td colspan="3">{L.noHighlights}</td></tr>
|
|
476
570
|
{/each}
|
|
477
571
|
</tbody>
|
|
478
572
|
</table>
|
|
@@ -1,3 +1,58 @@
|
|
|
1
|
+
import { type ChartFrameLabels } from './ChartFrame.svelte';
|
|
2
|
+
export type DensityChartLabels = ChartFrameLabels & {
|
|
3
|
+
/** Name of the chart in its accessible name when there is no `title`. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Accessible name of the chart: its title (or `name`), the number of points and the keyboard and pointer hints. `total` is already formatted. */
|
|
6
|
+
keys: (name: string, total: string) => string;
|
|
7
|
+
/** Name of the `highlight` set when it has no `name`. */
|
|
8
|
+
highlighted: string;
|
|
9
|
+
/** Legend entry for the points when highlights exist and the points have no groups; also the count column of the table view. */
|
|
10
|
+
points: string;
|
|
11
|
+
/** Tooltip title of a heatmap cell. */
|
|
12
|
+
bin: string;
|
|
13
|
+
/** Name of the count in a heatmap cell's tooltip (lower case, after the number). */
|
|
14
|
+
pointsLower: string;
|
|
15
|
+
/** Tooltip title of a point that has no label or group; header of the first column of the highlight table. */
|
|
16
|
+
point: string;
|
|
17
|
+
/** Name of the x axis in the readout and tooltip when there is no `xLabel`. */
|
|
18
|
+
x: string;
|
|
19
|
+
/** Name of the y axis in the readout and tooltip when there is no `yLabel`. */
|
|
20
|
+
y: string;
|
|
21
|
+
/** Header of the x column in the tables when there is no `xLabel`. */
|
|
22
|
+
xHeader: string;
|
|
23
|
+
/** Header of the y column in the tables when there is no `yLabel`. */
|
|
24
|
+
yHeader: string;
|
|
25
|
+
/** Button that returns to the full view. */
|
|
26
|
+
resetView: string;
|
|
27
|
+
/** Caption of the colour key under the plot. */
|
|
28
|
+
colorKey: string;
|
|
29
|
+
/** Live-region text: how many points are in view (formatted), the total (formatted), and how they are drawn (`markers` true: as individual markers, false: as a density heatmap). */
|
|
30
|
+
readout: (inView: string, total: string, markers: boolean) => string;
|
|
31
|
+
/** Live-region text: the visible range of each axis (the axis names, then the formatted limits). */
|
|
32
|
+
readoutRange: (xName: string, x0: string, x1: string, yName: string, y0: string, y1: string) => string;
|
|
33
|
+
/** Live-region text: how many of the highlighted points are in view (formatted). */
|
|
34
|
+
highlightReadout: (name: string, inView: string) => string;
|
|
35
|
+
/** A range of values: from and to (formatted), in the table's region cells. */
|
|
36
|
+
span: (from: string, to: string) => string;
|
|
37
|
+
/** Caption of the table: the points in view (formatted) and into how many regions they are grouped. */
|
|
38
|
+
summary: (n: string, regions: number) => string;
|
|
39
|
+
/** Added to that caption when only the busiest regions are listed; `shown` is how many. */
|
|
40
|
+
busiest: (shown: number) => string;
|
|
41
|
+
/** Header of the percentage column in the table view. */
|
|
42
|
+
share: string;
|
|
43
|
+
/** Table row when no point is in view. */
|
|
44
|
+
noPoints: string;
|
|
45
|
+
/** Caption of the highlight table: the set's name and its state (`hidden`, or `inView` with `firstShown` added when the list is cut). */
|
|
46
|
+
highlightCaption: (name: string, text: string) => string;
|
|
47
|
+
/** State of a hidden highlight set. */
|
|
48
|
+
hidden: string;
|
|
49
|
+
/** State of a visible highlight set: how many points are in view (formatted). */
|
|
50
|
+
inView: (n: string) => string;
|
|
51
|
+
/** Added to that state when the table lists only the first rows; `shown` is how many. */
|
|
52
|
+
firstShown: (shown: number) => string;
|
|
53
|
+
/** Highlight table row when no highlighted point is in view. */
|
|
54
|
+
noHighlights: string;
|
|
55
|
+
};
|
|
1
56
|
import type { Snippet } from 'svelte';
|
|
2
57
|
import { type DensityHighlight, type DensityHover, type DensityPoint } from './density.js';
|
|
3
58
|
type $$ComponentProps = {
|
|
@@ -47,6 +102,8 @@ type $$ComponentProps = {
|
|
|
47
102
|
maxCount?: number;
|
|
48
103
|
/** Bindable: the resolved heatmap ramp, low to high, as CSS colours (from `--trc-seq-*` or the built-in fallback). */
|
|
49
104
|
ramp?: string[];
|
|
105
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
106
|
+
labels?: Partial<DensityChartLabels>;
|
|
50
107
|
};
|
|
51
108
|
declare const DensityChart: import("svelte").Component<$$ComponentProps, {}, "maxCount" | "ramp">;
|
|
52
109
|
type DensityChart = ReturnType<typeof DensityChart>;
|