@ruckc/truss-chart 1.41.0 → 1.42.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
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
showValues = false,
|
|
17
17
|
reference,
|
|
18
18
|
details,
|
|
19
|
-
yFormat
|
|
19
|
+
yFormat: yFormatProp
|
|
20
20
|
}: {
|
|
21
21
|
categories: string[];
|
|
22
22
|
/** Up to 8 series (fixed-order palette). Negative values are allowed everywhere, including stacked bars. */
|
|
@@ -39,10 +39,14 @@
|
|
|
39
39
|
reference?: Ref | Ref[];
|
|
40
40
|
/** Extra text per category (same order as `categories`), shown under the category name in the tooltip and as a Details column in the table view. */
|
|
41
41
|
details?: string[];
|
|
42
|
+
/** Formats values for the value-axis ticks, labels, tooltip and table. Default: compact ticks (1.2K), plain numbers elsewhere. */
|
|
42
43
|
yFormat?: (n: number) => string;
|
|
43
44
|
} = $props();
|
|
44
45
|
|
|
45
46
|
type Ref = { value: number; label?: string };
|
|
47
|
+
const yFormat = $derived(yFormatProp ?? fmtValue);
|
|
48
|
+
const yTick = $derived(yFormatProp ?? fmtAxis);
|
|
49
|
+
|
|
46
50
|
let hidden = $state<string[]>([]);
|
|
47
51
|
type Tip = { x: number; y: number; cat: string; name: string; value: number; color: string; share?: number; detail?: string };
|
|
48
52
|
let tip = $state<Tip | null>(null);
|
|
@@ -146,10 +150,10 @@
|
|
|
146
150
|
{#each scale.ticks as t}
|
|
147
151
|
{#if horizontal}
|
|
148
152
|
<line class="grid" x1={V(t)} x2={V(t)} y1={m.top} y2={plotH - m.bottom} data-zero={t === 0} />
|
|
149
|
-
<text class="tick" x={V(t)} y={plotH - 8} text-anchor="middle">{percent ? `${t}%` :
|
|
153
|
+
<text class="tick" x={V(t)} y={plotH - 8} text-anchor="middle">{percent ? `${t}%` : yTick(t)}</text>
|
|
150
154
|
{:else}
|
|
151
155
|
<line class="grid" x1={m.left} x2={w - m.right} y1={V(t)} y2={V(t)} data-zero={t === 0} />
|
|
152
|
-
<text class="tick" x={m.left - 8} y={V(t)} text-anchor="end" dominant-baseline="middle">{percent ? `${t}%` :
|
|
156
|
+
<text class="tick" x={m.left - 8} y={V(t)} text-anchor="end" dominant-baseline="middle">{percent ? `${t}%` : yTick(t)}</text>
|
|
153
157
|
{/if}
|
|
154
158
|
{/each}
|
|
155
159
|
|
|
@@ -25,6 +25,7 @@ type $$ComponentProps = {
|
|
|
25
25
|
reference?: Ref | Ref[];
|
|
26
26
|
/** Extra text per category (same order as `categories`), shown under the category name in the tooltip and as a Details column in the table view. */
|
|
27
27
|
details?: string[];
|
|
28
|
+
/** Formats values for the value-axis ticks, labels, tooltip and table. Default: compact ticks (1.2K), plain numbers elsewhere. */
|
|
28
29
|
yFormat?: (n: number) => string;
|
|
29
30
|
};
|
|
30
31
|
declare const BarChart: import("svelte").Component<$$ComponentProps, {}, "">;
|
package/dist/LineChart.svelte
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
stacked = false,
|
|
16
16
|
zeroBaseline = false,
|
|
17
17
|
directLabels = 'auto',
|
|
18
|
-
yFormat
|
|
18
|
+
yFormat: yFormatProp,
|
|
19
19
|
xFormat,
|
|
20
20
|
band,
|
|
21
21
|
referenceLines = [],
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
* legend-only. The label text uses a text token; a series-colour marker links it to its line.
|
|
48
48
|
*/
|
|
49
49
|
directLabels?: boolean | 'auto';
|
|
50
|
+
/** Formats y values for axis ticks, tooltip, table and reference lines. Default: compact ticks (1.2K), plain numbers elsewhere. */
|
|
50
51
|
yFormat?: (n: number) => string;
|
|
51
52
|
/** Formats x values (a Date when `x` holds Dates) for axis ticks, tooltip and table. Default: number or date-aware short format. */
|
|
52
53
|
xFormat?: (x: number | Date) => string;
|
|
@@ -72,6 +73,9 @@
|
|
|
72
73
|
yScale?: 'linear' | 'log';
|
|
73
74
|
} = $props();
|
|
74
75
|
|
|
76
|
+
const yFormat = $derived(yFormatProp ?? fmtValue);
|
|
77
|
+
const yTick = $derived(yFormatProp ?? fmtAxis);
|
|
78
|
+
|
|
75
79
|
let hidden = $state<string[]>([]);
|
|
76
80
|
let hover = $state<number | null>(null);
|
|
77
81
|
|
|
@@ -212,7 +216,7 @@
|
|
|
212
216
|
>
|
|
213
217
|
{#each yDom.ticks as t}
|
|
214
218
|
<line class="grid" x1={m.left} x2={w - m.right} y1={Y(t)} y2={Y(t)} />
|
|
215
|
-
<text class="tick" x={m.left - 8} y={Y(t)} text-anchor="end" dominant-baseline="middle">{
|
|
219
|
+
<text class="tick" x={m.left - 8} y={Y(t)} text-anchor="end" dominant-baseline="middle">{yTick(t)}</text>
|
|
216
220
|
{/each}
|
|
217
221
|
{#each xTicks as t}
|
|
218
222
|
<text class="tick" x={X(t)} y={height - 8} text-anchor="middle">{fx(t)}</text>
|
|
@@ -25,6 +25,7 @@ type $$ComponentProps = {
|
|
|
25
25
|
* legend-only. The label text uses a text token; a series-colour marker links it to its line.
|
|
26
26
|
*/
|
|
27
27
|
directLabels?: boolean | 'auto';
|
|
28
|
+
/** Formats y values for axis ticks, tooltip, table and reference lines. Default: compact ticks (1.2K), plain numbers elsewhere. */
|
|
28
29
|
yFormat?: (n: number) => string;
|
|
29
30
|
/** Formats x values (a Date when `x` holds Dates) for axis ticks, tooltip and table. Default: number or date-aware short format. */
|
|
30
31
|
xFormat?: (x: number | Date) => string;
|
package/dist/ScatterChart.svelte
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { watchFill } from './fill.js';
|
|
4
4
|
import Tooltip from './Tooltip.svelte';
|
|
5
5
|
import type { ScatterPoint } from './types.js';
|
|
6
|
-
import { fmtAxis, fmtValue, linear, niceTicks, seriesColor, MAX_SERIES } from './util.js';
|
|
6
|
+
import { fmtAxis, fmtValue, isPos, linear, logLinear, logTicks, niceTicks, seriesColor, MAX_SERIES } from './util.js';
|
|
7
7
|
|
|
8
8
|
let {
|
|
9
9
|
points,
|
|
@@ -14,9 +14,11 @@
|
|
|
14
14
|
yLabel,
|
|
15
15
|
sizeLabel = 'Size',
|
|
16
16
|
sizeRange = [8, 24],
|
|
17
|
-
xFormat
|
|
18
|
-
yFormat
|
|
19
|
-
sizeFormat = fmtValue
|
|
17
|
+
xFormat,
|
|
18
|
+
yFormat,
|
|
19
|
+
sizeFormat = fmtValue,
|
|
20
|
+
xScale: xScaleKind = 'linear',
|
|
21
|
+
yScale: yScaleKind = 'linear'
|
|
20
22
|
}: {
|
|
21
23
|
/** `size` encodes a third value as marker diameter; `group` picks the (fixed-order, max 8) palette colour and legend entry. */
|
|
22
24
|
points: ScatterPoint[];
|
|
@@ -34,11 +36,26 @@
|
|
|
34
36
|
sizeLabel?: string;
|
|
35
37
|
/** Marker diameter in px for the smallest and largest `size`. Never drawn below 8px. */
|
|
36
38
|
sizeRange?: [number, number];
|
|
39
|
+
/** Formats x values for axis ticks, tooltip, table and the screen-reader readout. Default: compact ticks (1.2K), plain numbers elsewhere. */
|
|
37
40
|
xFormat?: (n: number) => string;
|
|
41
|
+
/** Formats y values for axis ticks, tooltip, table and the screen-reader readout. Default: compact ticks (1.2K), plain numbers elsewhere. */
|
|
38
42
|
yFormat?: (n: number) => string;
|
|
39
43
|
sizeFormat?: (n: number) => string;
|
|
44
|
+
/** `'log'` plots x on a base-10 log axis with ticks at powers of 10. Points with x <= 0 are dropped (not drawn, not in the tooltip or table). */
|
|
45
|
+
xScale?: 'linear' | 'log';
|
|
46
|
+
/** `'log'` plots y on a base-10 log axis with ticks at powers of 10. Points with y <= 0 are dropped (not drawn, not in the tooltip or table). */
|
|
47
|
+
yScale?: 'linear' | 'log';
|
|
40
48
|
} = $props();
|
|
41
49
|
|
|
50
|
+
const xLog = $derived(xScaleKind === 'log');
|
|
51
|
+
const yLog = $derived(yScaleKind === 'log');
|
|
52
|
+
const xTick = $derived(xFormat ?? fmtAxis);
|
|
53
|
+
const yTick = $derived(yFormat ?? fmtAxis);
|
|
54
|
+
const fx = $derived(xFormat ?? fmtValue);
|
|
55
|
+
const fy = $derived(yFormat ?? fmtValue);
|
|
56
|
+
/** A log axis can only place positive values; the others are dropped. */
|
|
57
|
+
const placeable = (p: { x: number; y: number }) => (!xLog || isPos(p.x)) && (!yLog || isPos(p.y));
|
|
58
|
+
|
|
42
59
|
let hidden = $state<string[]>([]);
|
|
43
60
|
let active = $state<number | null>(null);
|
|
44
61
|
|
|
@@ -52,7 +69,7 @@
|
|
|
52
69
|
const vis = $derived(
|
|
53
70
|
points
|
|
54
71
|
.map((p, idx) => ({ ...p, idx }))
|
|
55
|
-
.filter((p) => Number.isFinite(p.x) && Number.isFinite(p.y) && !(p.group != null && hidden.includes(p.group)))
|
|
72
|
+
.filter((p) => Number.isFinite(p.x) && Number.isFinite(p.y) && placeable(p) && !(p.group != null && hidden.includes(p.group)))
|
|
56
73
|
.sort((a, b) => a.x - b.x || a.y - b.y)
|
|
57
74
|
);
|
|
58
75
|
const sizes = $derived(vis.map((p) => p.size).filter((v): v is number => v != null && Number.isFinite(v)));
|
|
@@ -64,11 +81,13 @@
|
|
|
64
81
|
return lo + (sMax === sMin ? 0.5 : (s - sMin) / (sMax - sMin)) * (hi - lo);
|
|
65
82
|
};
|
|
66
83
|
|
|
67
|
-
const
|
|
68
|
-
|
|
84
|
+
const axis = (vals: number[], log: boolean, count: number) =>
|
|
85
|
+
vals.length ? (log ? logTicks(Math.min(...vals), Math.max(...vals)) : niceTicks(Math.min(...vals), Math.max(...vals), count)) : log ? logTicks(1, 10) : niceTicks(0, 1, 5);
|
|
86
|
+
const xAx = $derived(axis(vis.map((p) => p.x), xLog, 6));
|
|
87
|
+
const yAx = $derived(axis(vis.map((p) => p.y), yLog, 5));
|
|
69
88
|
const cur = $derived(active != null ? (vis[active] ?? null) : null);
|
|
70
89
|
const readout = (p: (typeof vis)[number]) =>
|
|
71
|
-
`${p.label ?? 'Point'}${p.group ? `, ${p.group}` : ''}: ${xLabel ?? 'x'} ${
|
|
90
|
+
`${p.label ?? 'Point'}${p.group ? `, ${p.group}` : ''}: ${xLabel ?? 'x'} ${fx(p.x)}, ${yLabel ?? 'y'} ${fy(p.y)}${p.size != null ? `, ${sizeLabel.toLowerCase()} ${sizeFormat(p.size)}` : ''}`;
|
|
72
91
|
|
|
73
92
|
// height='fill': plot = container height minus the frame's own chrome (title, legend, key, padding)
|
|
74
93
|
let wrap = $state<HTMLElement>();
|
|
@@ -86,8 +105,8 @@
|
|
|
86
105
|
{#snippet plot(w)}
|
|
87
106
|
{@const height = H}
|
|
88
107
|
{@const m = { top: 14, right: 16, bottom: xLabel ? 44 : 28, left: yLabel ? 62 : 48 }}
|
|
89
|
-
{@const X = linear(
|
|
90
|
-
{@const Y = linear(
|
|
108
|
+
{@const X = (xLog ? logLinear : linear)(xAx.min, xAx.max, m.left, w - m.right)}
|
|
109
|
+
{@const Y = (yLog ? logLinear : linear)(yAx.min, yAx.max, height - m.bottom, m.top)}
|
|
91
110
|
|
|
92
111
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
|
|
93
112
|
<svg
|
|
@@ -114,12 +133,12 @@
|
|
|
114
133
|
e.preventDefault();
|
|
115
134
|
}}
|
|
116
135
|
>
|
|
117
|
-
{#each
|
|
136
|
+
{#each yAx.ticks as t}
|
|
118
137
|
<line class="grid" x1={m.left} x2={w - m.right} y1={Y(t)} y2={Y(t)} />
|
|
119
|
-
<text class="tick" x={m.left - 8} y={Y(t)} text-anchor="end" dominant-baseline="middle">{
|
|
138
|
+
<text class="tick" x={m.left - 8} y={Y(t)} text-anchor="end" dominant-baseline="middle">{yTick(t)}</text>
|
|
120
139
|
{/each}
|
|
121
|
-
{#each
|
|
122
|
-
<text class="tick" x={X(t)} y={height - m.bottom + 16} text-anchor="middle">{
|
|
140
|
+
{#each xAx.ticks as t}
|
|
141
|
+
<text class="tick" x={X(t)} y={height - m.bottom + 16} text-anchor="middle">{xTick(t)}</text>
|
|
123
142
|
{/each}
|
|
124
143
|
{#if xLabel}<text class="axis" x={(m.left + w - m.right) / 2} y={height - 6} text-anchor="middle">{xLabel}</text>{/if}
|
|
125
144
|
{#if yLabel}<text class="axis" transform="translate(12 {(m.top + height - m.bottom) / 2}) rotate(-90)" text-anchor="middle">{yLabel}</text>{/if}
|
|
@@ -136,8 +155,8 @@
|
|
|
136
155
|
{#if cur}
|
|
137
156
|
<Tooltip x={X(cur.x)} y={Y(cur.y)} width={w}>
|
|
138
157
|
<div class="head">{cur.label ?? 'Point'}{#if cur.group} · {cur.group}{/if}</div>
|
|
139
|
-
<div class="row"><b>{
|
|
140
|
-
<div class="row"><b>{
|
|
158
|
+
<div class="row"><b>{fx(cur.x)}</b><span class="name">{xLabel ?? 'x'}</span></div>
|
|
159
|
+
<div class="row"><b>{fy(cur.y)}</b><span class="name">{yLabel ?? 'y'}</span></div>
|
|
141
160
|
{#if cur.size != null}<div class="row"><b>{sizeFormat(cur.size)}</b><span class="name">{sizeLabel}</span></div>{/if}
|
|
142
161
|
</Tooltip>
|
|
143
162
|
{/if}
|
|
@@ -147,8 +166,8 @@
|
|
|
147
166
|
<table>
|
|
148
167
|
<thead><tr><th>Point</th>{#if groups.length}<th>Group</th>{/if}<th>{xLabel ?? 'X'}</th><th>{yLabel ?? 'Y'}</th>{#if hasSize}<th>{sizeLabel}</th>{/if}</tr></thead>
|
|
149
168
|
<tbody>
|
|
150
|
-
{#each points as p}
|
|
151
|
-
<tr><td>{p.label ?? '—'}</td>{#if groups.length}<td>{p.group ?? '—'}</td>{/if}<td>{
|
|
169
|
+
{#each points.filter(placeable) as p}
|
|
170
|
+
<tr><td>{p.label ?? '—'}</td>{#if groups.length}<td>{p.group ?? '—'}</td>{/if}<td>{fx(p.x)}</td><td>{fy(p.y)}</td>{#if hasSize}<td>{p.size == null ? '—' : sizeFormat(p.size)}</td>{/if}</tr>
|
|
152
171
|
{/each}
|
|
153
172
|
</tbody>
|
|
154
173
|
</table>
|
|
@@ -16,9 +16,15 @@ type $$ComponentProps = {
|
|
|
16
16
|
sizeLabel?: string;
|
|
17
17
|
/** Marker diameter in px for the smallest and largest `size`. Never drawn below 8px. */
|
|
18
18
|
sizeRange?: [number, number];
|
|
19
|
+
/** Formats x values for axis ticks, tooltip, table and the screen-reader readout. Default: compact ticks (1.2K), plain numbers elsewhere. */
|
|
19
20
|
xFormat?: (n: number) => string;
|
|
21
|
+
/** Formats y values for axis ticks, tooltip, table and the screen-reader readout. Default: compact ticks (1.2K), plain numbers elsewhere. */
|
|
20
22
|
yFormat?: (n: number) => string;
|
|
21
23
|
sizeFormat?: (n: number) => string;
|
|
24
|
+
/** `'log'` plots x on a base-10 log axis with ticks at powers of 10. Points with x <= 0 are dropped (not drawn, not in the tooltip or table). */
|
|
25
|
+
xScale?: 'linear' | 'log';
|
|
26
|
+
/** `'log'` plots y on a base-10 log axis with ticks at powers of 10. Points with y <= 0 are dropped (not drawn, not in the tooltip or table). */
|
|
27
|
+
yScale?: 'linear' | 'log';
|
|
22
28
|
};
|
|
23
29
|
declare const ScatterChart: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
24
30
|
type ScatterChart = ReturnType<typeof ScatterChart>;
|