@ruckc/truss-chart 1.53.0 → 1.54.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.
@@ -27,6 +27,7 @@
27
27
  import ChartFrame from './ChartFrame.svelte';
28
28
  import { useLabels } from './labels.js';
29
29
  import { cssvars } from './cssvars.js';
30
+ import { themeNumber } from './themevar.js';
30
31
  import { watchFill } from './fill.js';
31
32
  import Tooltip from './Tooltip.svelte';
32
33
  import type { ChartSelection, Series } from './types.js';
@@ -153,6 +154,8 @@
153
154
 
154
155
  const pick = (c: number, name: string, v: number) => onselect?.({ index: c, category: categories[c], series: name, value: v });
155
156
 
157
+ /** Corner radius of a bar's data end: the --tr-chart-bar-radius hook (a square-bar theme sets 0), read at the plot. */
158
+ let barRadius = $state(4);
156
159
  const GAP = 1; // each side of a shared edge yields a 2px surface gap
157
160
  const labelWidth = $derived(Math.min(168, Math.max(48, Math.max(0, ...categories.map((c) => c.length)) * 6.4 + 14)));
158
161
  const trunc = (s: string, px: number) => (s.length * 6.4 > px ? `${s.slice(0, Math.max(1, Math.floor(px / 6.4) - 1))}…` : s);
@@ -183,7 +186,7 @@
183
186
  {@const cluster = isStack ? thick : thick * nb + 2 * (nb - 1)}
184
187
  {@const catPos = (c: number) => (horizontal ? m.top : m.left) + band * c + band / 2}
185
188
 
186
- <svg width={w} height={plotH} role="img" aria-label={L.tableHint(title ?? L.name)} onpointerleave={() => (tip = null)}>
189
+ <svg width={w} height={plotH} role="img" aria-label={L.tableHint(title ?? L.name)} onpointerleave={() => (tip = null)} {@attach themeNumber('--tr-chart-bar-radius', (v) => (barRadius = v ?? 4))}>
187
190
  {#each scale.ticks as t}
188
191
  {#if horizontal}
189
192
  <line class="grid" x1={V(t)} x2={V(t)} y1={m.top} y2={plotH - m.bottom} data-zero={t === 0} />
@@ -214,8 +217,8 @@
214
217
  {@const a = Math.min(p0, p1) + (horizontal ? (gapLo ? GAP : 0) : gapHi ? GAP : 0)}
215
218
  {@const bEnd = Math.max(p0, p1) - (horizontal ? (gapHi ? GAP : 0) : gapLo ? GAP : 0)}
216
219
  {@const d = horizontal
217
- ? rr(a, start, bEnd - a, thick, 4, s.outer ? (s.sign === 1 ? { tr: true, br: true } : { tl: true, bl: true }) : {})
218
- : rr(start, a, thick, bEnd - a, 4, s.outer ? (s.sign === 1 ? { tl: true, tr: true } : { bl: true, br: true }) : {})}
220
+ ? rr(a, start, bEnd - a, thick, barRadius, s.outer ? (s.sign === 1 ? { tr: true, br: true } : { tl: true, bl: true }) : {})
221
+ : rr(start, a, thick, bEnd - a, barRadius, s.outer ? (s.sign === 1 ? { tl: true, tr: true } : { bl: true, br: true }) : {})}
219
222
  {@const tx = horizontal ? (s.sign === 1 ? Math.max(p0, p1) : Math.min(p0, p1)) : start + thick / 2}
220
223
  {@const ty = horizontal ? start + thick / 2 : s.sign === 1 ? Math.min(p0, p1) : Math.max(p0, p1)}
221
224
  {#if d}
@@ -233,6 +236,8 @@
233
236
  {/if}
234
237
  {/each}
235
238
 
239
+ <path class="axisline" d="M{m.left},{m.top}V{plotH - m.bottom}H{w - m.right}" />
240
+
236
241
  {#each refs as r}
237
242
  {#if horizontal}
238
243
  <line class="ref" x1={V(r.value)} x2={V(r.value)} y1={m.top} y2={plotH - m.bottom} />
@@ -298,6 +303,8 @@
298
303
  svg { display: block; overflow: visible; }
299
304
  .grid { stroke: var(--tr-chart-grid-color, var(--tr-outline-variant)); stroke-opacity: var(--tr-chart-grid-opacity, 0.6); stroke-dasharray: var(--tr-chart-grid-dash, none); }
300
305
  .grid[data-zero='true'] { stroke-opacity: 1; }
306
+ /* the axis lines (left and bottom edge of the plot): none in classic, ink in a theme that draws them */
307
+ .axisline { fill: none; stroke: var(--tr-chart-axis-color, none); stroke-width: var(--tr-chart-axis-width, 1); shape-rendering: crispEdges; pointer-events: none; }
301
308
  .tick { fill: var(--tr-chart-tick-color, var(--tr-on-surface-variant)); font-family: var(--tr-chart-tick-font, inherit); font-size: var(--tr-text-xs); font-variant-numeric: tabular-nums; }
302
309
  .val { fill: var(--tr-on-surface-variant); font-size: var(--tr-text-xs); font-weight: 600; font-variant-numeric: tabular-nums; }
303
310
  .bar { outline: none; transition: filter var(--tr-dur-fast) var(--tr-ease); }
@@ -82,10 +82,12 @@
82
82
  .tv { height: 24px; padding: 0 10px; border: 1px solid var(--tr-outline-variant); border-radius: var(--tr-radius-sm); background: none; color: var(--tr-on-surface-variant); font: 600 var(--tr-text-sm) var(--tr-font-sans); cursor: pointer; }
83
83
  .tv:hover { background: var(--tr-surface-container-high); }
84
84
  .tv:focus-visible, .legend button:focus-visible { outline: none; box-shadow: var(--tr-focus-ring); }
85
- .legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 6px; padding: 0; list-style: none; }
86
- .legend button { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px; border: 0; border-radius: var(--tr-radius-sm); background: none; color: var(--tr-on-surface-variant); font: var(--tr-text-sm) var(--tr-font-sans); cursor: pointer; }
85
+ .legend { display: flex; flex-wrap: wrap; gap: var(--tr-chart-legend-gap, 4px 12px); margin: 0 0 6px; padding: 0; list-style: none; }
86
+ /* the legend buttons: plain text in classic, pills (radius, fill, height, padding) in a theme that sets the hooks */
87
+ .legend button { display: inline-flex; align-items: center; gap: 6px; height: var(--tr-chart-legend-height, auto); padding: var(--tr-chart-legend-padding, 2px 4px); border: 0; border-radius: var(--tr-chart-legend-radius, var(--tr-radius-sm)); background: var(--tr-chart-legend-bg, none); color: var(--tr-chart-legend-color, var(--tr-on-surface-variant)); font: var(--tr-chart-legend-weight, normal) var(--tr-text-sm) var(--tr-font-sans); cursor: pointer; }
88
+ .legend button:hover { background: var(--tr-chart-legend-bg-hover, var(--tr-chart-legend-bg, none)); }
87
89
  .legend button[aria-pressed='false'] { opacity: 0.45; text-decoration: line-through; }
88
- .key { width: 10px; height: 10px; border-radius: var(--tr-chart-key-radius, 2px); }
90
+ .key { width: var(--tr-chart-key-width, 10px); height: var(--tr-chart-key-height, 10px); border-radius: var(--tr-chart-key-radius, 2px); }
89
91
  .body { position: relative; }
90
92
  .tbl { max-height: 320px; overflow: auto; }
91
93
  .tbl:focus-visible { outline: none; box-shadow: inset var(--tr-focus-ring); }
@@ -256,7 +256,7 @@
256
256
 
257
257
  const cssVar = (st: CSSStyleDeclaration, name: string, fallback: string) => st.getPropertyValue(name).trim() || fallback;
258
258
  const COLOR_TOKENS = [
259
- '--tr-on-surface', '--tr-on-surface-variant', '--tr-outline-variant', '--tr-surface', '--tr-chart-tick-color', '--tr-chart-grid-color',
259
+ '--tr-on-surface', '--tr-on-surface-variant', '--tr-outline-variant', '--tr-surface', '--tr-chart-tick-color', '--tr-chart-grid-color', '--tr-chart-axis-color',
260
260
  ...Array.from({ length: 8 }, (_, i) => `--trc-s${i + 1}`), ...Array.from({ length: 9 }, (_, i) => `--trc-seq-${i + 1}`)
261
261
  ];
262
262
 
@@ -369,6 +369,17 @@
369
369
  }
370
370
  }
371
371
  ctx.restore();
372
+ // the axis lines (left and bottom edge of the plot), over the data: only where a theme sets --tr-chart-axis-color
373
+ const axis = col['--tr-chart-axis-color'];
374
+ if (axis) {
375
+ const aw = Number.parseFloat(cssVar(st, '--tr-chart-axis-width', '1'));
376
+ const lw = Number.isFinite(aw) ? aw : 1, o = (lw % 2) / 2;
377
+ const x = Math.round(m.left) - o, y = Math.round(m.top + ph) + o;
378
+ ctx.globalAlpha = 1;
379
+ ctx.strokeStyle = axis;
380
+ ctx.lineWidth = lw;
381
+ ctx.beginPath(); ctx.moveTo(x, m.top); ctx.lineTo(x, y); ctx.lineTo(m.left + pw, y); ctx.stroke();
382
+ }
372
383
  if (markers && maxCount !== 0) maxCount = 0;
373
384
  inView = n;
374
385
  mode = markers ? 'markers' : 'heatmap';
@@ -33,6 +33,7 @@
33
33
  import { watchFill } from './fill.js';
34
34
  import Tooltip from './Tooltip.svelte';
35
35
  import type { ChartSelection } from './types.js';
36
+ import { themeNumber } from './themevar.js';
36
37
  import { activate, barPath, fmtAxis, fmtValue, linear, niceTicks, seriesColor, str } from './util.js';
37
38
 
38
39
  let {
@@ -75,6 +76,8 @@
75
76
  const L = useLabels('Histogram', DEFAULTS, () => labels);
76
77
 
77
78
  let hover = $state<number | null>(null);
79
+ /** Corner radius of a bar's data end: the --tr-chart-bar-radius hook (a square-bar theme sets 0), read at the plot. */
80
+ let barRadius = $state(4);
78
81
  let drag = $state<{ a: number; b: number } | null>(null);
79
82
  let stop: (() => void) | undefined; // the running brush, abandoned if the chart unmounts mid-drag
80
83
  $effect(() => () => stop?.());
@@ -135,6 +138,7 @@
135
138
  <!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
136
139
  <svg
137
140
  width={w} {height} role="group" tabindex="0"
141
+ {@attach themeNumber('--tr-chart-bar-radius', (v) => (barRadius = v ?? 4))}
138
142
  aria-label={L.keys(title ?? L.name)}
139
143
  onpointerleave={() => (hover = null)}
140
144
  onblur={() => (hover = null)}
@@ -157,8 +161,9 @@
157
161
  {/each}
158
162
 
159
163
  {#each counts as c, i}
160
- <path class="bar" d={barPath(X(edges[i]) + 1, Y(0), Y(c), bw, 4)} fill={color} data-dim={!!sel && !(edges[i + 1] > sel[0] && edges[i] < sel[1])} data-hover={hover === i} />
164
+ <path class="bar" d={barPath(X(edges[i]) + 1, Y(0), Y(c), bw, barRadius)} fill={color} data-dim={!!sel && !(edges[i + 1] > sel[0] && edges[i] < sel[1])} data-hover={hover === i} />
161
165
  {/each}
166
+ <path class="axisline" d="M{m.left},{m.top}V{height - m.bottom}H{w - m.right}" />
162
167
 
163
168
  {#if sel}
164
169
  <rect class="brush" x={X(sel[0])} y={m.top} width={Math.max(0, X(sel[1]) - X(sel[0]))} height={height - m.top - m.bottom} />
@@ -230,6 +235,8 @@
230
235
  svg { display: block; outline: none; overflow: visible; }
231
236
  svg:focus-visible { border-radius: var(--tr-radius-sm); box-shadow: var(--tr-focus-ring); }
232
237
  .grid { stroke: var(--tr-chart-grid-color, var(--tr-outline-variant)); stroke-opacity: var(--tr-chart-grid-opacity, 0.6); stroke-dasharray: var(--tr-chart-grid-dash, none); }
238
+ /* the axis lines (left and bottom edge of the plot): none in classic, ink in a theme that draws them */
239
+ .axisline { fill: none; stroke: var(--tr-chart-axis-color, none); stroke-width: var(--tr-chart-axis-width, 1); shape-rendering: crispEdges; pointer-events: none; }
233
240
  .tick { fill: var(--tr-chart-tick-color, var(--tr-on-surface-variant)); font-family: var(--tr-chart-tick-font, inherit); font-size: var(--tr-text-xs); font-variant-numeric: tabular-nums; }
234
241
  .bar { transition: opacity var(--tr-dur-fast) var(--tr-ease), filter var(--tr-dur-fast) var(--tr-ease); }
235
242
  .bar[data-hover='true'] { filter: brightness(1.12) saturate(1.1); }
@@ -183,8 +183,9 @@
183
183
  const el = svgEl, names = all.map((s) => s.name);
184
184
  let live = true;
185
185
  const measure = () => {
186
- if (!live) return;
187
- const probes = [...el.querySelectorAll<SVGTextElement>('text.dprobe')];
186
+ // fonts.ready can settle after the probes have left (the labels re-laid out): nothing to measure then
187
+ const probes = live ? [...el.querySelectorAll<SVGTextElement>('text.dprobe')] : [];
188
+ if (probes.length < names.length) return;
188
189
  const cs = getComputedStyle(probes[0]);
189
190
  meas = { lh: parseFloat(cs.lineHeight) || parseFloat(cs.fontSize) * 1.4, w: Object.fromEntries(names.map((n, i) => [n, probes[i].getComputedTextLength()])) };
190
191
  };
@@ -291,8 +292,9 @@
291
292
  d={areaPath(seg, X, Y, si)} />
292
293
  {/each}
293
294
  {/if}
294
- <path class="line" stroke={s.color} color={s.color} d={segments(s.values).map((seg) => seg.map((i, k) => `${k ? 'L' : 'M'}${X(xs[i]).toFixed(1)},${Y(bands[si][i]!.hi).toFixed(1)}`).join(' ')).join(' ')} />
295
+ <path class="line" pathLength="1" stroke={s.color} color={s.color} d={segments(s.values).map((seg) => seg.map((i, k) => `${k ? 'L' : 'M'}${X(xs[i]).toFixed(1)},${Y(bands[si][i]!.hi).toFixed(1)}`).join(' ')).join(' ')} />
295
296
  {/each}
297
+ <path class="axisline" d="M{m.left},{m.top}V{height - m.bottom}H{w - m.right}" />
296
298
 
297
299
  {#each refs as r}
298
300
  <line class="ref" x1={m.left} x2={w - m.right} y1={Y(r.value)} y2={Y(r.value)} />
@@ -362,11 +364,20 @@
362
364
  svg.act { cursor: pointer; }
363
365
  svg:focus-visible { border-radius: var(--tr-radius-sm); box-shadow: var(--tr-focus-ring); }
364
366
  .grid { stroke: var(--tr-chart-grid-color, var(--tr-outline-variant)); stroke-opacity: var(--tr-chart-grid-opacity, 0.6); stroke-dasharray: var(--tr-chart-grid-dash, none); stroke-width: 1; }
367
+ /* the axis lines (left and bottom edge of the plot): none in classic, ink in a theme that draws them */
368
+ .axisline { fill: none; stroke: var(--tr-chart-axis-color, none); stroke-width: var(--tr-chart-axis-width, 1); shape-rendering: crispEdges; pointer-events: none; }
365
369
  .tick { fill: var(--tr-chart-tick-color, var(--tr-on-surface-variant)); font-family: var(--tr-chart-tick-font, inherit); font-size: var(--tr-text-xs); font-variant-numeric: tabular-nums; }
366
370
  .line { fill: none; stroke-width: var(--tr-chart-line-width, 2); stroke-linejoin: round; stroke-linecap: round; filter: var(--tr-chart-line-glow, none); }
367
371
  /* an unstacked area: its tint, and an optional fade toward the baseline (a mask image, e.g. linear-gradient(#000, transparent)) */
368
372
  .area { fill-opacity: var(--tr-chart-area-opacity, 0.14); -webkit-mask-image: var(--tr-chart-area-fade, none); mask-image: var(--tr-chart-area-fade, none); }
369
373
  .area.stack { fill-opacity: 0.55; -webkit-mask-image: none; mask-image: none; }
374
+ /* the load orchestration a theme can opt into (--tr-load-dur, 0s by default; no travel under reduced motion): the lines draw in
375
+ along their length (pathLength 1) and the areas rise from the baseline. Nothing stays applied once it ends. */
376
+ .line, .area { animation-duration: calc(var(--tr-load-dur, 0s) * var(--tr-motion-distance)); animation-timing-function: var(--tr-load-ease, var(--tr-ease)); animation-fill-mode: backwards; }
377
+ .line { animation-name: tr-draw; }
378
+ .area { animation-name: tr-rise; transform-box: fill-box; transform-origin: 50% 100%; }
379
+ @keyframes tr-draw { from { stroke-dasharray: 1; stroke-dashoffset: 1; } to { stroke-dasharray: 1; stroke-dashoffset: 0; } }
380
+ @keyframes tr-rise { from { opacity: 0; transform: scaleY(0.6); } }
370
381
  .band { fill-opacity: 0.18; stroke: none; }
371
382
  .ref { stroke: var(--tr-on-surface); stroke-width: 1.5; stroke-dasharray: 6 3; }
372
383
  .reflabel { fill: var(--tr-on-surface); font-size: var(--tr-text-xs); font-weight: 600; }
@@ -194,6 +194,8 @@
194
194
  {#if xLabel}<text class="axis" x={(m.left + w - m.right) / 2} y={height - 6} text-anchor="middle">{xLabel}</text>{/if}
195
195
  {#if yLabel}<text class="axis" transform="translate(12 {(m.top + height - m.bottom) / 2}) rotate(-90)" text-anchor="middle">{yLabel}</text>{/if}
196
196
 
197
+ <path class="axisline" d="M{m.left},{m.top}V{height - m.bottom}H{w - m.right}" />
198
+
197
199
  {#each vis as p, i (p.idx)}
198
200
  <circle class="pt" class:on={i === active} cx={X(p.x)} cy={Y(p.y)} r={diameter(p.size) / 2} fill={colorOf(p.group)} />
199
201
  {/each}
@@ -238,6 +240,8 @@
238
240
  svg.act { cursor: pointer; }
239
241
  svg:focus-visible { border-radius: var(--tr-radius-sm); box-shadow: var(--tr-focus-ring); }
240
242
  .grid { stroke: var(--tr-chart-grid-color, var(--tr-outline-variant)); stroke-opacity: var(--tr-chart-grid-opacity, 0.6); stroke-dasharray: var(--tr-chart-grid-dash, none); stroke-width: 1; }
243
+ /* the axis lines (left and bottom edge of the plot): none in classic, ink in a theme that draws them */
244
+ .axisline { fill: none; stroke: var(--tr-chart-axis-color, none); stroke-width: var(--tr-chart-axis-width, 1); shape-rendering: crispEdges; pointer-events: none; }
241
245
  .tick { fill: var(--tr-chart-tick-color, var(--tr-on-surface-variant)); font-family: var(--tr-chart-tick-font, inherit); font-size: var(--tr-text-xs); font-variant-numeric: tabular-nums; }
242
246
  .axis { fill: var(--tr-on-surface-variant); font-size: var(--tr-text-sm); font-weight: 600; }
243
247
  .pt { fill-opacity: 0.85; stroke: var(--tr-surface-container-low); stroke-width: 2; }
@@ -19,8 +19,13 @@
19
19
  </script>
20
20
 
21
21
  <svg {width} {height} role="img" aria-label={ariaLabel}>
22
- <path d={pts.map((p, k) => `${k ? 'L' : 'M'}${X(p.i).toFixed(1)},${Y(p.v).toFixed(1)}`).join(' ')} fill="none" stroke={color} stroke-width="2" stroke-linejoin="round" stroke-linecap="round" />
22
+ <path pathLength="1" d={pts.map((p, k) => `${k ? 'L' : 'M'}${X(p.i).toFixed(1)},${Y(p.v).toFixed(1)}`).join(' ')} fill="none" stroke={color} stroke-width="2" stroke-linejoin="round" stroke-linecap="round" />
23
23
  {#if last}<circle cx={X(last.i)} cy={Y(last.v)} r="3.5" fill={color} stroke="var(--tr-surface-container-low)" stroke-width="2" />{/if}
24
24
  </svg>
25
25
 
26
- <style>svg { display: inline-block; vertical-align: middle; overflow: visible; }</style>
26
+ <style>
27
+ svg { display: inline-block; vertical-align: middle; overflow: visible; }
28
+ /* the opt-in load orchestration (--tr-load-dur): the trend line draws in along its length; see LineChart */
29
+ path { animation: tr-draw calc(var(--tr-load-dur, 0s) * var(--tr-motion-distance)) var(--tr-load-ease, var(--tr-ease)) backwards; }
30
+ @keyframes tr-draw { from { stroke-dasharray: 1; stroke-dashoffset: 1; } to { stroke-dasharray: 1; stroke-dashoffset: 0; } }
31
+ </style>
@@ -21,6 +21,7 @@
21
21
  </script>
22
22
 
23
23
  <script lang="ts">
24
+ import { onMount } from 'svelte';
24
25
  import { useLabels } from './labels.js';
25
26
  import Sparkline from './Sparkline.svelte';
26
27
  import { fmtValue } from './util.js';
@@ -61,6 +62,39 @@
61
62
  const deltaLabel = $derived(deltaLabelProp ?? L.vsPrevious);
62
63
 
63
64
  const shown = $derived(typeof value === 'number' ? (format ?? fmtValue)(value) : value);
65
+
66
+ // The opt-in count-up of the load orchestration (--tr-load-dur, 0s unless a theme sets it; none under reduced motion): the visible
67
+ // number runs from 0 to the value once, on mount. Only the aria-hidden digits move: the tile's accessible name (the summary) carries
68
+ // the final value from the start, and the server renders it too. The clock is a Web Animation, so anything that waits for the page's
69
+ // animations to finish (a screenshot, a test) sees the final number.
70
+ let valueEl = $state<HTMLElement>();
71
+ let counting = $state<{ to: number; text: string } | null>(null);
72
+ const display = $derived(counting && counting.to === value ? counting.text : shown);
73
+ const toMs = (t: string) => (/ms\s*$/.test(t) ? 1 : 1000) * parseFloat(t);
74
+ onMount(() => {
75
+ if (typeof value !== 'number') return;
76
+ const cs = getComputedStyle(valueEl!);
77
+ const dur = toMs(cs.getPropertyValue('--_load')) * Number(cs.getPropertyValue('--tr-motion-distance'));
78
+ if (!(dur > 0)) return;
79
+ const to = value;
80
+ const fmt = format ?? fmtValue;
81
+ const dec = (String(to).split('.')[1] ?? '').length;
82
+ let clock: Animation;
83
+ try {
84
+ clock = valueEl!.animate(null, { duration: dur, easing: cs.getPropertyValue('--_load-ease').trim() });
85
+ } catch {
86
+ clock = valueEl!.animate(null, { duration: dur, easing: 'ease-out' }); // an easing the Web Animations API does not take
87
+ }
88
+ let raf = 0;
89
+ const step = () => {
90
+ counting = { to, text: fmt(Number((to * (clock.effect!.getComputedTiming().progress ?? 1)).toFixed(dec))) };
91
+ raf = requestAnimationFrame(step);
92
+ };
93
+ const done = () => { cancelAnimationFrame(raf); counting = null; };
94
+ clock.finished.then(done, done);
95
+ step();
96
+ return () => clock.cancel();
97
+ });
64
98
  const dir = $derived(delta == null || delta === 0 ? 'flat' : delta > 0 ? 'up' : 'down');
65
99
  const tone = $derived(dir === 'flat' ? 'neutral' : dir === deltaGoodDirection ? 'good' : 'bad');
66
100
  const signed = (d: number) => `${d > 0 ? '+' : d < 0 ? '−' : ''}${fmtValue(Math.abs(d))}%`;
@@ -81,7 +115,7 @@
81
115
  <div class="tile" class:sm={size === 'sm'} class:featured role="group" aria-label={summary}>
82
116
  <div class="label" aria-hidden="true">{label}</div>
83
117
  <div class="row" aria-hidden="true">
84
- <div class="value">{shown}</div>
118
+ <div class="value" bind:this={valueEl}>{display}</div>
85
119
  {#if spark && spark.length > 1}<Sparkline values={spark} {label} color={featured ? 'currentColor' : undefined} />{/if}
86
120
  </div>
87
121
  {#if delta != null}
@@ -112,7 +146,7 @@
112
146
  .tile.sm .value { font-size: var(--trc-stat-value-size, var(--tr-text-xl)); }
113
147
  .label { color: var(--tr-on-surface-variant); font-size: var(--tr-text-sm); font-weight: 600; }
114
148
  .row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; }
115
- .value { font-size: var(--trc-stat-value-size, 28px); font-family: var(--tr-font-display, inherit); font-weight: var(--tr-display-weight, 700); font-variation-settings: var(--tr-display-axes, normal); line-height: 1.2; font-variant-numeric: tabular-nums; }
149
+ .value { --_load: var(--tr-load-dur, 0s); --_load-ease: var(--tr-load-ease, var(--tr-ease)); font-size: var(--trc-stat-value-size, 28px); font-family: var(--tr-font-display, inherit); font-weight: var(--tr-display-weight, 700); font-variation-settings: var(--tr-display-axes, normal); line-height: 1.2; font-variant-numeric: tabular-nums; }
116
150
  .delta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--tr-text-sm); font-variant-numeric: tabular-nums; }
117
151
  .delta.good { color: var(--tr-success); }
118
152
  .delta.bad { color: var(--tr-danger); }
package/dist/charts.css CHANGED
@@ -2,18 +2,23 @@
2
2
  * Categorical series palette (8 slots, fixed order — never cycled).
3
3
  * Validated adjacent-pair CVD / normal-vision separation in both modes.
4
4
  * Chart chrome reuses truss tokens, so it themes with the rest of the app.
5
+ * Every palette is also declared on each [data-truss-theme] element (#290), so a theme nested in another theme starts from these
6
+ * values rather than the outer theme's; a theme's own rules, specificity (0,3,0), still win (these are (0,1,0)).
5
7
  */
6
- :root {
8
+ :root,
9
+ [data-truss-theme] {
7
10
  --trc-s1: #2a78d6; --trc-s2: #eb6834; --trc-s3: #1baf7a; --trc-s4: #eda100;
8
11
  --trc-s5: #e87ba4; --trc-s6: #008300; --trc-s7: #6250d6; --trc-s8: #e34948;
9
12
  }
10
13
  @media (prefers-color-scheme: dark) {
11
- :root:not([data-theme='light']) {
14
+ :root:not([data-theme='light']),
15
+ :where(:root:not([data-theme='light'])) [data-truss-theme] {
12
16
  --trc-s1: #3987e5; --trc-s2: #d95926; --trc-s3: #199e70; --trc-s4: #c98500;
13
17
  --trc-s5: #d55181; --trc-s6: #008300; --trc-s7: #9085e9; --trc-s8: #e66767;
14
18
  }
15
19
  }
16
- :root[data-theme='dark'] {
20
+ :root[data-theme='dark'],
21
+ :where(:root[data-theme='dark']) [data-truss-theme] {
17
22
  --trc-s1: #3987e5; --trc-s2: #d95926; --trc-s3: #199e70; --trc-s4: #c98500;
18
23
  --trc-s5: #d55181; --trc-s6: #008300; --trc-s7: #9085e9; --trc-s8: #e66767;
19
24
  }
@@ -25,21 +30,24 @@
25
30
  * Diverging: blue (div-1) through a neutral midpoint (div-4) to orange (div-7). Each half is monotonic in lightness toward the
26
31
  * neutral, and the poles stay distinguishable under protan, deutan and tritan simulation (OKLab delta-E >= 0.19).
27
32
  */
28
- :root {
33
+ :root,
34
+ [data-truss-theme] {
29
35
  --trc-seq-1: #eaf3fe; --trc-seq-2: #c5ddfc; --trc-seq-3: #97c1f7; --trc-seq-4: #64a1ee;
30
36
  --trc-seq-5: #3a81d7; --trc-seq-6: #1d60ad; --trc-seq-7: #10427b;
31
37
  --trc-div-1: #11458c; --trc-div-2: #3c79d1; --trc-div-3: #94b9f1; --trc-div-4: #f0eeeb;
32
38
  --trc-div-5: #ebaf86; --trc-div-6: #d26c28; --trc-div-7: #993e02;
33
39
  }
34
40
  @media (prefers-color-scheme: dark) {
35
- :root:not([data-theme='light']) {
41
+ :root:not([data-theme='light']),
42
+ :where(:root:not([data-theme='light'])) [data-truss-theme] {
36
43
  --trc-seq-1: #0e294a; --trc-seq-2: #113d70; --trc-seq-3: #1b589e; --trc-seq-4: #3077cd;
37
44
  --trc-seq-5: #589aed; --trc-seq-6: #8fbefa; --trc-seq-7: #c5ddfc;
38
45
  --trc-div-1: #86bafe; --trc-div-2: #4c8edf; --trc-div-3: #285994; --trc-div-4: #2a2926;
39
46
  --trc-div-5: #944e21; --trc-div-6: #dc7b40; --trc-div-7: #f9a870;
40
47
  }
41
48
  }
42
- :root[data-theme='dark'] {
49
+ :root[data-theme='dark'],
50
+ :where(:root[data-theme='dark']) [data-truss-theme] {
43
51
  --trc-seq-1: #0e294a; --trc-seq-2: #113d70; --trc-seq-3: #1b589e; --trc-seq-4: #3077cd;
44
52
  --trc-seq-5: #589aed; --trc-seq-6: #8fbefa; --trc-seq-7: #c5ddfc;
45
53
  --trc-div-1: #86bafe; --trc-div-2: #4c8edf; --trc-div-3: #285994; --trc-div-4: #2a2926;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * An attachment that reads a numeric theme hook (e.g. the chart bar radius) at the element, now and whenever the theme there
3
+ * changes, and hands it to `set` (`null` when the hook is unset or not a number). For geometry drawn from script, where a CSS
4
+ * `var()` cannot reach (#291). The server and the first paint keep the caller's default.
5
+ */
6
+ export declare const themeNumber: (name: string, set: (v: number | null) => void) => (el: Element) => () => void;
@@ -0,0 +1,14 @@
1
+ import { onThemeChange } from '@ruckc/truss-ui';
2
+ /**
3
+ * An attachment that reads a numeric theme hook (e.g. the chart bar radius) at the element, now and whenever the theme there
4
+ * changes, and hands it to `set` (`null` when the hook is unset or not a number). For geometry drawn from script, where a CSS
5
+ * `var()` cannot reach (#291). The server and the first paint keep the caller's default.
6
+ */
7
+ export const themeNumber = (name, set) => (el) => {
8
+ const read = () => {
9
+ const v = Number.parseFloat(getComputedStyle(el).getPropertyValue(name));
10
+ set(Number.isFinite(v) ? v : null);
11
+ };
12
+ read();
13
+ return onThemeChange(el, read);
14
+ };
package/dist/util.js CHANGED
@@ -90,6 +90,9 @@ export function barPath(x, y0, y1, w, r, round = true) {
90
90
  if (h < 0.5)
91
91
  return '';
92
92
  const rr = round ? Math.min(r, w / 2, h) : 0;
93
+ // square (a radius of 0 from the theme's bar-radius hook, or round = false): a plain rectangle, no degenerate curves
94
+ if (rr <= 0)
95
+ return `M${x},${y0}V${y1}H${x + w}V${y0}Z`;
93
96
  return y1 < y0
94
97
  ? `M${x},${y0}V${top + rr}Q${x},${top} ${x + rr},${top}H${x + w - rr}Q${x + w},${top} ${x + w},${top + rr}V${y0}Z`
95
98
  : `M${x},${y0}V${top + h - rr}Q${x},${top + h} ${x + rr},${top + h}H${x + w - rr}Q${x + w},${top + h} ${x + w},${top + h - rr}V${y0}Z`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruckc/truss-chart",
3
- "version": "1.53.0",
3
+ "version": "1.54.0",
4
4
  "description": "Zero-dependency SVG charts for Truss UI",
5
5
  "type": "module",
6
6
  "license": "MIT",