dssoca 0.10.0 → 0.12.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.
Files changed (43) hide show
  1. package/dist/components/Accordion.svelte +35 -15
  2. package/dist/components/Accordion.svelte.d.ts +7 -0
  3. package/dist/components/Avatar.svelte +5 -9
  4. package/dist/components/Badge.svelte +27 -53
  5. package/dist/components/Badge.svelte.d.ts +2 -5
  6. package/dist/components/BottomNav.svelte +2 -2
  7. package/dist/components/BoxPlot.svelte +421 -0
  8. package/dist/components/BoxPlot.svelte.d.ts +36 -0
  9. package/dist/components/BumpChart.svelte +345 -0
  10. package/dist/components/BumpChart.svelte.d.ts +32 -0
  11. package/dist/components/Button.svelte +50 -34
  12. package/dist/components/Button.svelte.d.ts +8 -2
  13. package/dist/components/Chart.svelte +2 -8
  14. package/dist/components/DateField.svelte +1 -1
  15. package/dist/components/FileDrop.svelte +1 -1
  16. package/dist/components/Heatmap.svelte +333 -0
  17. package/dist/components/Heatmap.svelte.d.ts +30 -0
  18. package/dist/components/Icon.svelte +29 -7
  19. package/dist/components/Icon.svelte.d.ts +14 -2
  20. package/dist/components/Input.svelte +1 -1
  21. package/dist/components/LogStream.svelte +3 -3
  22. package/dist/components/Menu.svelte +1 -1
  23. package/dist/components/NumberField.svelte +1 -1
  24. package/dist/components/ScatterPlot.svelte +395 -0
  25. package/dist/components/ScatterPlot.svelte.d.ts +55 -0
  26. package/dist/components/Select.svelte +1 -1
  27. package/dist/components/ServiceCard.svelte +13 -2
  28. package/dist/components/Sidebar.svelte +1 -1
  29. package/dist/components/Spinner.svelte +26 -19
  30. package/dist/components/Spinner.svelte.d.ts +14 -4
  31. package/dist/components/Textarea.svelte +1 -1
  32. package/dist/components/Topbar.svelte +2 -2
  33. package/dist/config.d.ts +44 -3
  34. package/dist/config.js +52 -3
  35. package/dist/dssoca.config.d.ts +38 -1
  36. package/dist/dssoca.config.js +47 -0
  37. package/dist/index.d.ts +10 -5
  38. package/dist/index.js +11 -4
  39. package/dist/palette.d.ts +10 -0
  40. package/dist/palette.js +17 -0
  41. package/dist/theme.css +158 -158
  42. package/dist/tokens.css +158 -158
  43. package/package.json +3 -2
@@ -0,0 +1,421 @@
1
+ <script module lang="ts">
2
+ export interface BoxGroup {
3
+ /** Group caption shown under its band and in the tooltip / accessible name. */
4
+ label: string
5
+ /** Raw values for this group; whiskers + quartiles are computed from these. */
6
+ values: number[]
7
+ /** Optional per-group colour; falls back to the cycling palette. */
8
+ color?: string
9
+ }
10
+ </script>
11
+
12
+ <script lang="ts">
13
+ import { CHART_PALETTE } from '../palette.js'
14
+ import { scaleBand, scaleLinear } from 'd3-scale'
15
+ import { extent, quantile } from 'd3-array'
16
+ import { resolveComponentSize, type Size } from '../config.js'
17
+
18
+ interface Props {
19
+ /** One box per group. Each group has a `label`, `values`, and optional `color`. */
20
+ groups: BoxGroup[]
21
+ /** Overlay every value as a small jittered dot. Default true. */
22
+ showPoints?: boolean
23
+ /** Y axis caption (drawn rotated beside the axis). */
24
+ yLabel?: string
25
+ /** Force the y domain; defaults to the padded data extent across all values. */
26
+ yDomain?: [number, number]
27
+ /** Format a y value for ticks + tooltip. */
28
+ yFormat?: (y: number) => string
29
+ /** Intrinsic drawing height in px. Default 300. */
30
+ height?: number
31
+ /** Intrinsic drawing width in px. Default 420. */
32
+ width?: number
33
+ /** Stretch to the container width via the viewBox (width:100%). */
34
+ fluid?: boolean
35
+ /** Reveal a tooltip on hover/focus of a box. Default true. */
36
+ tooltip?: boolean
37
+ /** SR summary + accessible name; auto-generated when absent. */
38
+ summary?: string
39
+ /** Token size (sm|md|lg); inherits the global size when unset. */
40
+ size?: Size
41
+ }
42
+
43
+ let {
44
+ groups,
45
+ showPoints = true,
46
+ yLabel,
47
+ yDomain,
48
+ yFormat,
49
+ height = 300,
50
+ width = 420,
51
+ fluid = false,
52
+ tooltip = true,
53
+ summary,
54
+ size,
55
+ }: Props = $props()
56
+
57
+ const PALETTE = CHART_PALETTE
58
+
59
+ const M = { top: 12, right: 16, bottom: 36, left: 48 }
60
+
61
+ // Keep only groups carrying at least one finite value.
62
+ const clean = $derived(
63
+ (groups ?? [])
64
+ .filter((g) => g && Array.isArray(g.values))
65
+ .map((g) => ({
66
+ label: g.label,
67
+ color: g.color,
68
+ values: g.values.filter((v) => Number.isFinite(v)),
69
+ }))
70
+ .filter((g) => g.values.length > 0),
71
+ )
72
+ const isEmpty = $derived(clean.length === 0)
73
+
74
+ function colorFor(g: { color?: string }, i: number): string {
75
+ return g.color ?? PALETTE[i % PALETTE.length]
76
+ }
77
+
78
+ const innerW = $derived(Math.max(0, width - M.left - M.right))
79
+ const innerH = $derived(Math.max(0, height - M.top - M.bottom))
80
+
81
+ const fmtY = $derived(yFormat ?? ((y: number) => String(y)))
82
+
83
+ /** Data extent padded by 8% each side; a flat axis is expanded to ±1. */
84
+ function paddedExtent(values: number[]): [number, number] {
85
+ const e = extent(values) as [number, number]
86
+ if (e[0] === undefined) return [0, 1]
87
+ if (e[0] === e[1]) return [e[0] - 1, e[1] + 1]
88
+ const pad = (e[1] - e[0]) * 0.08
89
+ return [e[0] - pad, e[1] + pad]
90
+ }
91
+
92
+ const allValues = $derived(clean.flatMap((g) => g.values))
93
+ const yDom = $derived(yDomain ?? paddedExtent(allValues))
94
+
95
+ const xScaleObj = $derived(
96
+ scaleBand<string>()
97
+ .domain(clean.map((g) => g.label))
98
+ .range([0, innerW])
99
+ .padding(0.3),
100
+ )
101
+ const yScaleObj = $derived(scaleLinear().domain(yDom).nice().range([innerH, 0]))
102
+
103
+ const yTicks = $derived(yScaleObj.ticks(5))
104
+
105
+ /** Deterministic horizontal offset for dot i within a band (no Math.random → SSR-safe). */
106
+ function jitter(i: number, bandW: number): number {
107
+ // Cheap integer hash → [0,1), mapped into the inner 70% of the band.
108
+ const h = (((Math.sin(i * 127.1) * 43758.5453) % 1) + 1) % 1
109
+ return (h - 0.5) * bandW * 0.7
110
+ }
111
+
112
+ // Five-number summary + Tukey whiskers per group.
113
+ const boxes = $derived.by(() => {
114
+ const bw = xScaleObj.bandwidth()
115
+ return clean.map((g, i) => {
116
+ const sorted = [...g.values].sort((a, b) => a - b)
117
+ const q1 = quantile(sorted, 0.25) as number
118
+ const median = quantile(sorted, 0.5) as number
119
+ const q3 = quantile(sorted, 0.75) as number
120
+ const iqr = q3 - q1
121
+ const loFence = q1 - 1.5 * iqr
122
+ const hiFence = q3 + 1.5 * iqr
123
+ const lo = sorted.find((v) => v >= loFence) ?? sorted[0]
124
+ const hi = [...sorted].reverse().find((v) => v <= hiFence) ?? sorted[sorted.length - 1]
125
+ const x = xScaleObj(g.label) ?? 0
126
+ const cx = x + bw / 2
127
+ const points = showPoints
128
+ ? g.values.map((v, j) => ({ cx: cx + jitter(j, bw), cy: yScaleObj(v) }))
129
+ : []
130
+ return {
131
+ label: g.label,
132
+ color: colorFor(g, i),
133
+ x,
134
+ cx,
135
+ w: bw,
136
+ q1,
137
+ median,
138
+ q3,
139
+ lo,
140
+ hi,
141
+ yQ1: yScaleObj(q1),
142
+ yMedian: yScaleObj(median),
143
+ yQ3: yScaleObj(q3),
144
+ yLo: yScaleObj(lo),
145
+ yHi: yScaleObj(hi),
146
+ points,
147
+ }
148
+ })
149
+ })
150
+
151
+ const autoSummary = $derived.by(() => {
152
+ if (isEmpty) return 'No data'
153
+ const names = clean.map((g) => g.label).join(', ')
154
+ return `Box plot with ${clean.length} groups (${names}).`
155
+ })
156
+ const srText = $derived(summary ?? autoSummary)
157
+
158
+ const resolvedSize = $derived(resolveComponentSize('Chart', size))
159
+
160
+ let active = $state<{
161
+ label: string
162
+ median: number
163
+ q1: number
164
+ q3: number
165
+ lo: number
166
+ hi: number
167
+ cx: number
168
+ cy: number
169
+ } | null>(null)
170
+ function show(b: (typeof boxes)[number]) {
171
+ if (tooltip)
172
+ active = {
173
+ label: b.label,
174
+ median: b.median,
175
+ q1: b.q1,
176
+ q3: b.q3,
177
+ lo: b.lo,
178
+ hi: b.hi,
179
+ cx: b.cx,
180
+ cy: b.yMedian,
181
+ }
182
+ }
183
+ function hide() {
184
+ active = null
185
+ }
186
+ function boxLabel(b: (typeof boxes)[number]): string {
187
+ return `${b.label}: median ${fmtY(b.median)} (Q1 ${fmtY(b.q1)}–Q3 ${fmtY(b.q3)})`
188
+ }
189
+ </script>
190
+
191
+ <div
192
+ class="ss-boxplot"
193
+ class:fluid
194
+ data-size-variant={resolvedSize}
195
+ role="group"
196
+ aria-label={srText}
197
+ >
198
+ {#if isEmpty}
199
+ <span class="empty" aria-hidden="true">—</span>
200
+ <span class="sr-only">No data</span>
201
+ {:else}
202
+ <div class="plot">
203
+ <svg
204
+ class="canvas"
205
+ viewBox="0 0 {width} {height}"
206
+ width={fluid ? undefined : width}
207
+ height={fluid ? undefined : height}
208
+ preserveAspectRatio="xMidYMid meet"
209
+ role="presentation"
210
+ >
211
+ <g transform="translate({M.left},{M.top})">
212
+ <!-- gridlines + y axis -->
213
+ {#each yTicks as t}
214
+ <line class="grid" x1="0" x2={innerW} y1={yScaleObj(t)} y2={yScaleObj(t)} />
215
+ <text class="tick y" x="-6" y={yScaleObj(t)} dy="0.32em" text-anchor="end"
216
+ >{fmtY(t)}</text
217
+ >
218
+ {/each}
219
+ <line class="axis" x1="0" x2="0" y1="0" y2={innerH} />
220
+ <line class="axis" x1="0" x2={innerW} y1={innerH} y2={innerH} />
221
+
222
+ <!-- boxes -->
223
+ {#each boxes as b}
224
+ <!-- whisker centre line + caps -->
225
+ <line class="whisker" x1={b.cx} x2={b.cx} y1={b.yLo} y2={b.yHi} />
226
+ <line class="whisker" x1={b.cx - b.w / 4} x2={b.cx + b.w / 4} y1={b.yLo} y2={b.yLo} />
227
+ <line class="whisker" x1={b.cx - b.w / 4} x2={b.cx + b.w / 4} y1={b.yHi} y2={b.yHi} />
228
+
229
+ <!-- box (q1..q3) -->
230
+ <rect
231
+ class="box"
232
+ x={b.x}
233
+ y={b.yQ3}
234
+ width={b.w}
235
+ height={Math.max(0, b.yQ1 - b.yQ3)}
236
+ style="fill:{b.color};stroke:{b.color}"
237
+ tabindex="0"
238
+ role="button"
239
+ aria-label={boxLabel(b)}
240
+ onfocus={() => show(b)}
241
+ onblur={hide}
242
+ onmouseenter={() => show(b)}
243
+ onmouseleave={hide}
244
+ />
245
+
246
+ <!-- median -->
247
+ <line
248
+ class="median"
249
+ x1={b.x}
250
+ x2={b.x + b.w}
251
+ y1={b.yMedian}
252
+ y2={b.yMedian}
253
+ style="stroke:{b.color}"
254
+ />
255
+
256
+ <!-- point overlay (decorative) -->
257
+ {#if showPoints}
258
+ {#each b.points as p}
259
+ <circle
260
+ class="point"
261
+ cx={p.cx}
262
+ cy={p.cy}
263
+ r="2.5"
264
+ style="fill:{b.color}"
265
+ aria-hidden="true"
266
+ />
267
+ {/each}
268
+ {/if}
269
+ {/each}
270
+
271
+ <!-- x axis labels -->
272
+ {#each boxes as b}
273
+ <text class="tick x" x={b.cx} y={innerH + 16} text-anchor="middle">{b.label}</text>
274
+ {/each}
275
+
276
+ <!-- y axis caption -->
277
+ {#if yLabel}
278
+ <text
279
+ class="axis-label y"
280
+ transform="translate({-M.left + 12},{innerH / 2}) rotate(-90)"
281
+ text-anchor="middle">{yLabel}</text
282
+ >
283
+ {/if}
284
+ </g>
285
+ </svg>
286
+
287
+ {#if tooltip && active}
288
+ <div
289
+ class="tooltip"
290
+ role="status"
291
+ style="left:{((active.cx + M.left) / width) * 100}%;top:{((active.cy + M.top) / height) *
292
+ 100}%"
293
+ >
294
+ <span class="t-label">{active.label}</span>
295
+ <span class="t-val">med {fmtY(active.median)}</span>
296
+ <span class="t-val">Q1 {fmtY(active.q1)} · Q3 {fmtY(active.q3)}</span>
297
+ <span class="t-val">min {fmtY(active.lo)} · max {fmtY(active.hi)}</span>
298
+ </div>
299
+ {/if}
300
+ </div>
301
+ {/if}
302
+ </div>
303
+
304
+ <style>.ss-boxplot {
305
+ display: inline-flex;
306
+ flex-direction: column;
307
+ gap: var(--ss-gap-sm);
308
+ font-family: var(--ss-font-body);
309
+ color: var(--ss-fg);
310
+ max-width: 100%;
311
+ }
312
+ .ss-boxplot.fluid {
313
+ display: flex;
314
+ width: 100%;
315
+ }
316
+ .ss-boxplot .plot {
317
+ position: relative;
318
+ width: 100%;
319
+ }
320
+ .ss-boxplot .canvas {
321
+ display: block;
322
+ max-width: 100%;
323
+ height: auto;
324
+ overflow: visible;
325
+ }
326
+ .ss-boxplot.fluid .canvas {
327
+ width: 100%;
328
+ }
329
+ .ss-boxplot .empty {
330
+ align-self: center;
331
+ margin: auto;
332
+ padding: var(--ss-gap-sm);
333
+ color: var(--ss-fg-muted);
334
+ font-family: var(--ss-font-mono);
335
+ line-height: 1;
336
+ min-height: var(--ss-chart-h, 240px);
337
+ display: flex;
338
+ align-items: center;
339
+ }
340
+ .ss-boxplot .sr-only {
341
+ position: absolute;
342
+ width: 1px;
343
+ height: 1px;
344
+ padding: 0;
345
+ margin: -1px;
346
+ overflow: hidden;
347
+ clip: rect(0, 0, 0, 0);
348
+ white-space: nowrap;
349
+ border: 0;
350
+ }
351
+ .ss-boxplot .grid {
352
+ stroke: var(--ss-line);
353
+ stroke-width: 1;
354
+ opacity: 0.5;
355
+ shape-rendering: crispEdges;
356
+ }
357
+ .ss-boxplot .axis {
358
+ stroke: var(--ss-line);
359
+ stroke-width: 1;
360
+ shape-rendering: crispEdges;
361
+ }
362
+ .ss-boxplot .tick {
363
+ font-family: var(--ss-font-mono);
364
+ font-size: var(--ss-ui-xs);
365
+ fill: var(--ss-fg-muted);
366
+ }
367
+ .ss-boxplot .axis-label {
368
+ font-family: var(--ss-font-mono);
369
+ font-size: var(--ss-ui-xs);
370
+ fill: var(--ss-fg-muted);
371
+ }
372
+ .ss-boxplot .whisker {
373
+ stroke: var(--ss-line-strong);
374
+ stroke-width: 1;
375
+ shape-rendering: crispEdges;
376
+ }
377
+ .ss-boxplot .box {
378
+ cursor: pointer;
379
+ fill-opacity: 0.18;
380
+ stroke-width: 1.5;
381
+ transition: fill-opacity var(--ss-dur-fast) var(--ss-ease);
382
+ }
383
+ .ss-boxplot .box:hover {
384
+ fill-opacity: 0.3;
385
+ }
386
+ .ss-boxplot .box:focus-visible {
387
+ outline: none;
388
+ stroke: var(--ss-fg);
389
+ stroke-width: 2;
390
+ }
391
+ .ss-boxplot .median {
392
+ stroke-width: 2;
393
+ shape-rendering: crispEdges;
394
+ }
395
+ .ss-boxplot .point {
396
+ fill-opacity: 0.6;
397
+ pointer-events: none;
398
+ }
399
+ .ss-boxplot .tooltip {
400
+ position: absolute;
401
+ transform: translate(-50%, calc(-100% - 8px));
402
+ pointer-events: none;
403
+ background: var(--ss-bg-elev);
404
+ border: 1px solid var(--ss-line-strong);
405
+ padding: var(--ss-gap-sm);
406
+ font-size: var(--ss-ui-xs);
407
+ line-height: 1.3;
408
+ white-space: nowrap;
409
+ display: flex;
410
+ flex-direction: column;
411
+ gap: 2px;
412
+ z-index: 2;
413
+ }
414
+ .ss-boxplot .tooltip .t-label {
415
+ font-family: var(--ss-font-mono);
416
+ color: var(--ss-fg);
417
+ }
418
+ .ss-boxplot .tooltip .t-val {
419
+ font-family: var(--ss-font-mono);
420
+ color: var(--ss-fg-muted);
421
+ }</style>
@@ -0,0 +1,36 @@
1
+ export interface BoxGroup {
2
+ /** Group caption shown under its band and in the tooltip / accessible name. */
3
+ label: string;
4
+ /** Raw values for this group; whiskers + quartiles are computed from these. */
5
+ values: number[];
6
+ /** Optional per-group colour; falls back to the cycling palette. */
7
+ color?: string;
8
+ }
9
+ import { type Size } from '../config.js';
10
+ interface Props {
11
+ /** One box per group. Each group has a `label`, `values`, and optional `color`. */
12
+ groups: BoxGroup[];
13
+ /** Overlay every value as a small jittered dot. Default true. */
14
+ showPoints?: boolean;
15
+ /** Y axis caption (drawn rotated beside the axis). */
16
+ yLabel?: string;
17
+ /** Force the y domain; defaults to the padded data extent across all values. */
18
+ yDomain?: [number, number];
19
+ /** Format a y value for ticks + tooltip. */
20
+ yFormat?: (y: number) => string;
21
+ /** Intrinsic drawing height in px. Default 300. */
22
+ height?: number;
23
+ /** Intrinsic drawing width in px. Default 420. */
24
+ width?: number;
25
+ /** Stretch to the container width via the viewBox (width:100%). */
26
+ fluid?: boolean;
27
+ /** Reveal a tooltip on hover/focus of a box. Default true. */
28
+ tooltip?: boolean;
29
+ /** SR summary + accessible name; auto-generated when absent. */
30
+ summary?: string;
31
+ /** Token size (sm|md|lg); inherits the global size when unset. */
32
+ size?: Size;
33
+ }
34
+ declare const BoxPlot: import("svelte").Component<Props, {}, "">;
35
+ type BoxPlot = ReturnType<typeof BoxPlot>;
36
+ export default BoxPlot;