dssoca 0.9.0 → 0.11.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/components/Avatar.svelte +119 -0
- package/dist/components/Avatar.svelte.d.ts +18 -0
- package/dist/components/BoxPlot.svelte +427 -0
- package/dist/components/BoxPlot.svelte.d.ts +36 -0
- package/dist/components/BumpChart.svelte +351 -0
- package/dist/components/BumpChart.svelte.d.ts +32 -0
- package/dist/components/Chart.svelte +527 -0
- package/dist/components/Chart.svelte.d.ts +42 -0
- package/dist/components/DateField.svelte +188 -0
- package/dist/components/DateField.svelte.d.ts +37 -0
- package/dist/components/FileDrop.svelte +355 -0
- package/dist/components/FileDrop.svelte.d.ts +24 -0
- package/dist/components/Heatmap.svelte +333 -0
- package/dist/components/Heatmap.svelte.d.ts +30 -0
- package/dist/components/Modal.svelte +223 -0
- package/dist/components/Modal.svelte.d.ts +29 -0
- package/dist/components/NumberField.svelte +260 -0
- package/dist/components/NumberField.svelte.d.ts +35 -0
- package/dist/components/Pagination.svelte +193 -0
- package/dist/components/Pagination.svelte.d.ts +22 -0
- package/dist/components/ScatterPlot.svelte +401 -0
- package/dist/components/ScatterPlot.svelte.d.ts +55 -0
- package/dist/components/Select.svelte +224 -0
- package/dist/components/Select.svelte.d.ts +42 -0
- package/dist/components/Switch.svelte +144 -0
- package/dist/components/Switch.svelte.d.ts +22 -0
- package/dist/components/Table.svelte +267 -0
- package/dist/components/Table.svelte.d.ts +52 -0
- package/dist/components/Tooltip.svelte +162 -0
- package/dist/components/Tooltip.svelte.d.ts +17 -0
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +11 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +17 -0
- package/package.json +9 -1
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export interface ScatterPoint {
|
|
3
|
+
/** Label shown next to the dot and in the tooltip / accessible name. */
|
|
4
|
+
label: string
|
|
5
|
+
x: number
|
|
6
|
+
y: number
|
|
7
|
+
/** Optional magnitude → bubble area (sqrt-scaled radius). Omit for a fixed dot. */
|
|
8
|
+
size?: number
|
|
9
|
+
/** Optional per-point colour; falls back to the cycling palette. */
|
|
10
|
+
color?: string
|
|
11
|
+
}
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import { scaleLinear, scaleSqrt } from 'd3-scale'
|
|
16
|
+
import { extent, max } from 'd3-array'
|
|
17
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
18
|
+
|
|
19
|
+
interface Props {
|
|
20
|
+
/** One dot per datum. Two encoded axes (x, y), optional `size` and `color`. */
|
|
21
|
+
points: ScatterPoint[]
|
|
22
|
+
/** X axis caption (drawn under the axis). */
|
|
23
|
+
xLabel?: string
|
|
24
|
+
/** Y axis caption (drawn rotated beside the axis). */
|
|
25
|
+
yLabel?: string
|
|
26
|
+
/** Draw a dashed vertical reference line at this x (e.g. the median) → quadrants. */
|
|
27
|
+
xRef?: number
|
|
28
|
+
/** Draw a dashed horizontal reference line at this y (e.g. the median) → quadrants. */
|
|
29
|
+
yRef?: number
|
|
30
|
+
/** Corner captions for the four quadrants (needs xRef + yRef to read well). */
|
|
31
|
+
quadrantLabels?: { tl?: string; tr?: string; bl?: string; br?: string }
|
|
32
|
+
/** Force the x domain; defaults to the padded data extent. */
|
|
33
|
+
xDomain?: [number, number]
|
|
34
|
+
/** Force the y domain; defaults to the padded data extent. */
|
|
35
|
+
yDomain?: [number, number]
|
|
36
|
+
/** Format an x value for ticks + tooltip. */
|
|
37
|
+
xFormat?: (x: number) => string
|
|
38
|
+
/** Format a y value for ticks + tooltip. */
|
|
39
|
+
yFormat?: (y: number) => string
|
|
40
|
+
/** Draw each point's label next to its dot. Default true. */
|
|
41
|
+
showLabels?: boolean
|
|
42
|
+
/** Intrinsic drawing height in px. Default 320. */
|
|
43
|
+
height?: number
|
|
44
|
+
/** Intrinsic drawing width in px. Default 420. */
|
|
45
|
+
width?: number
|
|
46
|
+
/** Stretch to the container width via the viewBox (width:100%). */
|
|
47
|
+
fluid?: boolean
|
|
48
|
+
/** Reveal a tooltip on hover/focus of a point. Default true. */
|
|
49
|
+
tooltip?: boolean
|
|
50
|
+
/** SR summary + accessible name; auto-generated when absent. */
|
|
51
|
+
summary?: string
|
|
52
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
53
|
+
size?: Size
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let {
|
|
57
|
+
points,
|
|
58
|
+
xLabel,
|
|
59
|
+
yLabel,
|
|
60
|
+
xRef,
|
|
61
|
+
yRef,
|
|
62
|
+
quadrantLabels,
|
|
63
|
+
xDomain,
|
|
64
|
+
yDomain,
|
|
65
|
+
xFormat,
|
|
66
|
+
yFormat,
|
|
67
|
+
showLabels = true,
|
|
68
|
+
height = 320,
|
|
69
|
+
width = 420,
|
|
70
|
+
fluid = false,
|
|
71
|
+
tooltip = true,
|
|
72
|
+
summary,
|
|
73
|
+
size,
|
|
74
|
+
}: Props = $props()
|
|
75
|
+
|
|
76
|
+
const PALETTE = [
|
|
77
|
+
'var(--ss-primary)',
|
|
78
|
+
'var(--ss-blue)',
|
|
79
|
+
'var(--ss-purple)',
|
|
80
|
+
'var(--ss-cyan)',
|
|
81
|
+
'var(--ss-yellow)',
|
|
82
|
+
'var(--ss-lime)',
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
const M = { top: 12, right: 16, bottom: 36, left: 48 }
|
|
86
|
+
|
|
87
|
+
const clean = $derived(
|
|
88
|
+
(points ?? []).filter((p) => p && Number.isFinite(p.x) && Number.isFinite(p.y)),
|
|
89
|
+
)
|
|
90
|
+
const isEmpty = $derived(clean.length === 0)
|
|
91
|
+
|
|
92
|
+
function colorFor(p: ScatterPoint, i: number): string {
|
|
93
|
+
return p.color ?? PALETTE[i % PALETTE.length]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const innerW = $derived(Math.max(0, width - M.left - M.right))
|
|
97
|
+
const innerH = $derived(Math.max(0, height - M.top - M.bottom))
|
|
98
|
+
|
|
99
|
+
const fmtX = $derived(xFormat ?? ((x: number) => String(x)))
|
|
100
|
+
const fmtY = $derived(yFormat ?? ((y: number) => String(y)))
|
|
101
|
+
|
|
102
|
+
/** Data extent padded by 8% each side; a flat axis is expanded to ±1. */
|
|
103
|
+
function paddedExtent(values: number[]): [number, number] {
|
|
104
|
+
const e = extent(values) as [number, number]
|
|
105
|
+
if (e[0] === undefined) return [0, 1]
|
|
106
|
+
if (e[0] === e[1]) return [e[0] - 1, e[1] + 1]
|
|
107
|
+
const pad = (e[1] - e[0]) * 0.08
|
|
108
|
+
return [e[0] - pad, e[1] + pad]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const xDom = $derived(xDomain ?? paddedExtent(clean.map((p) => p.x)))
|
|
112
|
+
const yDom = $derived(yDomain ?? paddedExtent(clean.map((p) => p.y)))
|
|
113
|
+
|
|
114
|
+
const xScaleObj = $derived(scaleLinear().domain(xDom).nice().range([0, innerW]))
|
|
115
|
+
const yScaleObj = $derived(scaleLinear().domain(yDom).nice().range([innerH, 0]))
|
|
116
|
+
|
|
117
|
+
// Bubble radius: sqrt scale (area-true) when any point carries a size, else fixed.
|
|
118
|
+
const hasSizes = $derived(clean.some((p) => typeof p.size === 'number'))
|
|
119
|
+
const rScaleObj = $derived(
|
|
120
|
+
scaleSqrt()
|
|
121
|
+
.domain([0, max(clean, (p) => p.size ?? 0) || 1])
|
|
122
|
+
.range([4, 16]),
|
|
123
|
+
)
|
|
124
|
+
function radiusFor(p: ScatterPoint): number {
|
|
125
|
+
return hasSizes ? rScaleObj(p.size ?? 0) : 5
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const xTicks = $derived(xScaleObj.ticks(5))
|
|
129
|
+
const yTicks = $derived(yScaleObj.ticks(5))
|
|
130
|
+
|
|
131
|
+
const marks = $derived(
|
|
132
|
+
clean.map((p, i) => ({
|
|
133
|
+
cx: xScaleObj(p.x),
|
|
134
|
+
cy: yScaleObj(p.y),
|
|
135
|
+
r: radiusFor(p),
|
|
136
|
+
color: colorFor(p, i),
|
|
137
|
+
label: p.label,
|
|
138
|
+
x: p.x,
|
|
139
|
+
y: p.y,
|
|
140
|
+
})),
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
const corners = $derived.by(() => {
|
|
144
|
+
if (!quadrantLabels) return [] as { x: number; y: number; anchor: string; text: string }[]
|
|
145
|
+
const pad = 4
|
|
146
|
+
const out: { x: number; y: number; anchor: string; text: string }[] = []
|
|
147
|
+
if (quadrantLabels.tl)
|
|
148
|
+
out.push({ x: pad, y: pad + 8, anchor: 'start', text: quadrantLabels.tl })
|
|
149
|
+
if (quadrantLabels.tr)
|
|
150
|
+
out.push({ x: innerW - pad, y: pad + 8, anchor: 'end', text: quadrantLabels.tr })
|
|
151
|
+
if (quadrantLabels.bl)
|
|
152
|
+
out.push({ x: pad, y: innerH - pad, anchor: 'start', text: quadrantLabels.bl })
|
|
153
|
+
if (quadrantLabels.br)
|
|
154
|
+
out.push({ x: innerW - pad, y: innerH - pad, anchor: 'end', text: quadrantLabels.br })
|
|
155
|
+
return out
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
const autoSummary = $derived.by(() => {
|
|
159
|
+
if (isEmpty) return 'No data'
|
|
160
|
+
const names = clean.map((p) => p.label).join(', ')
|
|
161
|
+
return `Scatter plot with ${clean.length} points (${names}).`
|
|
162
|
+
})
|
|
163
|
+
const srText = $derived(summary ?? autoSummary)
|
|
164
|
+
|
|
165
|
+
const resolvedSize = $derived(resolveComponentSize('Chart', size))
|
|
166
|
+
|
|
167
|
+
let active = $state<{ label: string; x: number; y: number; cx: number; cy: number } | null>(null)
|
|
168
|
+
function show(label: string, x: number, y: number, cx: number, cy: number) {
|
|
169
|
+
if (tooltip) active = { label, x, y, cx, cy }
|
|
170
|
+
}
|
|
171
|
+
function hide() {
|
|
172
|
+
active = null
|
|
173
|
+
}
|
|
174
|
+
function datumLabel(label: string, x: number, y: number): string {
|
|
175
|
+
return `${label}: ${fmtX(x)}, ${fmtY(y)}`
|
|
176
|
+
}
|
|
177
|
+
</script>
|
|
178
|
+
|
|
179
|
+
<div
|
|
180
|
+
class="ss-scatter"
|
|
181
|
+
class:fluid
|
|
182
|
+
data-size-variant={resolvedSize}
|
|
183
|
+
role="group"
|
|
184
|
+
aria-label={srText}
|
|
185
|
+
>
|
|
186
|
+
{#if isEmpty}
|
|
187
|
+
<span class="empty" aria-hidden="true">—</span>
|
|
188
|
+
<span class="sr-only">No data</span>
|
|
189
|
+
{:else}
|
|
190
|
+
<div class="plot">
|
|
191
|
+
<svg
|
|
192
|
+
class="canvas"
|
|
193
|
+
viewBox="0 0 {width} {height}"
|
|
194
|
+
width={fluid ? undefined : width}
|
|
195
|
+
height={fluid ? undefined : height}
|
|
196
|
+
preserveAspectRatio="xMidYMid meet"
|
|
197
|
+
role="presentation"
|
|
198
|
+
>
|
|
199
|
+
<g transform="translate({M.left},{M.top})">
|
|
200
|
+
<!-- gridlines + y axis -->
|
|
201
|
+
{#each yTicks as t}
|
|
202
|
+
<line class="grid" x1="0" x2={innerW} y1={yScaleObj(t)} y2={yScaleObj(t)} />
|
|
203
|
+
<text class="tick y" x="-6" y={yScaleObj(t)} dy="0.32em" text-anchor="end"
|
|
204
|
+
>{fmtY(t)}</text
|
|
205
|
+
>
|
|
206
|
+
{/each}
|
|
207
|
+
{#each xTicks as t}
|
|
208
|
+
<text class="tick x" x={xScaleObj(t)} y={innerH + 16} text-anchor="middle"
|
|
209
|
+
>{fmtX(t)}</text
|
|
210
|
+
>
|
|
211
|
+
{/each}
|
|
212
|
+
<line class="axis" x1="0" x2="0" y1="0" y2={innerH} />
|
|
213
|
+
<line class="axis" x1="0" x2={innerW} y1={innerH} y2={innerH} />
|
|
214
|
+
|
|
215
|
+
<!-- quadrant reference lines -->
|
|
216
|
+
{#if xRef !== undefined}
|
|
217
|
+
<line class="ref" x1={xScaleObj(xRef)} x2={xScaleObj(xRef)} y1="0" y2={innerH} />
|
|
218
|
+
{/if}
|
|
219
|
+
{#if yRef !== undefined}
|
|
220
|
+
<line class="ref" x1="0" x2={innerW} y1={yScaleObj(yRef)} y2={yScaleObj(yRef)} />
|
|
221
|
+
{/if}
|
|
222
|
+
|
|
223
|
+
<!-- quadrant captions -->
|
|
224
|
+
{#each corners as c}
|
|
225
|
+
<text class="quadrant" x={c.x} y={c.y} text-anchor={c.anchor}>{c.text}</text>
|
|
226
|
+
{/each}
|
|
227
|
+
|
|
228
|
+
<!-- points -->
|
|
229
|
+
{#each marks as m}
|
|
230
|
+
<circle
|
|
231
|
+
class="point"
|
|
232
|
+
cx={m.cx}
|
|
233
|
+
cy={m.cy}
|
|
234
|
+
r={m.r}
|
|
235
|
+
style="fill:{m.color}"
|
|
236
|
+
tabindex="0"
|
|
237
|
+
role="button"
|
|
238
|
+
aria-label={datumLabel(m.label, m.x, m.y)}
|
|
239
|
+
onfocus={() => show(m.label, m.x, m.y, m.cx, m.cy)}
|
|
240
|
+
onblur={hide}
|
|
241
|
+
onmouseenter={() => show(m.label, m.x, m.y, m.cx, m.cy)}
|
|
242
|
+
onmouseleave={hide}
|
|
243
|
+
/>
|
|
244
|
+
{#if showLabels}
|
|
245
|
+
<text class="point-label" x={m.cx + m.r + 4} y={m.cy} dy="0.32em">{m.label}</text>
|
|
246
|
+
{/if}
|
|
247
|
+
{/each}
|
|
248
|
+
|
|
249
|
+
<!-- axis captions -->
|
|
250
|
+
{#if xLabel}
|
|
251
|
+
<text class="axis-label x" x={innerW / 2} y={innerH + 32} text-anchor="middle"
|
|
252
|
+
>{xLabel}</text
|
|
253
|
+
>
|
|
254
|
+
{/if}
|
|
255
|
+
{#if yLabel}
|
|
256
|
+
<text
|
|
257
|
+
class="axis-label y"
|
|
258
|
+
transform="translate({-M.left + 12},{innerH / 2}) rotate(-90)"
|
|
259
|
+
text-anchor="middle">{yLabel}</text
|
|
260
|
+
>
|
|
261
|
+
{/if}
|
|
262
|
+
</g>
|
|
263
|
+
</svg>
|
|
264
|
+
|
|
265
|
+
{#if tooltip && active}
|
|
266
|
+
<div
|
|
267
|
+
class="tooltip"
|
|
268
|
+
role="status"
|
|
269
|
+
style="left:{((active.cx + M.left) / width) * 100}%;top:{((active.cy + M.top) / height) *
|
|
270
|
+
100}%"
|
|
271
|
+
>
|
|
272
|
+
<span class="t-label">{active.label}</span>
|
|
273
|
+
<span class="t-val">{fmtX(active.x)} · {fmtY(active.y)}</span>
|
|
274
|
+
</div>
|
|
275
|
+
{/if}
|
|
276
|
+
</div>
|
|
277
|
+
{/if}
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
<style>.ss-scatter {
|
|
281
|
+
display: inline-flex;
|
|
282
|
+
flex-direction: column;
|
|
283
|
+
gap: var(--ss-gap-sm);
|
|
284
|
+
font-family: var(--ss-font-body);
|
|
285
|
+
color: var(--ss-fg);
|
|
286
|
+
max-width: 100%;
|
|
287
|
+
}
|
|
288
|
+
.ss-scatter.fluid {
|
|
289
|
+
display: flex;
|
|
290
|
+
width: 100%;
|
|
291
|
+
}
|
|
292
|
+
.ss-scatter .plot {
|
|
293
|
+
position: relative;
|
|
294
|
+
width: 100%;
|
|
295
|
+
}
|
|
296
|
+
.ss-scatter .canvas {
|
|
297
|
+
display: block;
|
|
298
|
+
max-width: 100%;
|
|
299
|
+
height: auto;
|
|
300
|
+
overflow: visible;
|
|
301
|
+
}
|
|
302
|
+
.ss-scatter.fluid .canvas {
|
|
303
|
+
width: 100%;
|
|
304
|
+
}
|
|
305
|
+
.ss-scatter .empty {
|
|
306
|
+
align-self: center;
|
|
307
|
+
margin: auto;
|
|
308
|
+
padding: var(--ss-gap-sm);
|
|
309
|
+
color: var(--ss-fg-muted);
|
|
310
|
+
font-family: var(--ss-font-mono);
|
|
311
|
+
line-height: 1;
|
|
312
|
+
min-height: var(--ss-chart-h, 240px);
|
|
313
|
+
display: flex;
|
|
314
|
+
align-items: center;
|
|
315
|
+
}
|
|
316
|
+
.ss-scatter .sr-only {
|
|
317
|
+
position: absolute;
|
|
318
|
+
width: 1px;
|
|
319
|
+
height: 1px;
|
|
320
|
+
padding: 0;
|
|
321
|
+
margin: -1px;
|
|
322
|
+
overflow: hidden;
|
|
323
|
+
clip: rect(0, 0, 0, 0);
|
|
324
|
+
white-space: nowrap;
|
|
325
|
+
border: 0;
|
|
326
|
+
}
|
|
327
|
+
.ss-scatter .grid {
|
|
328
|
+
stroke: var(--ss-line);
|
|
329
|
+
stroke-width: 1;
|
|
330
|
+
opacity: 0.5;
|
|
331
|
+
shape-rendering: crispEdges;
|
|
332
|
+
}
|
|
333
|
+
.ss-scatter .axis {
|
|
334
|
+
stroke: var(--ss-line);
|
|
335
|
+
stroke-width: 1;
|
|
336
|
+
shape-rendering: crispEdges;
|
|
337
|
+
}
|
|
338
|
+
.ss-scatter .ref {
|
|
339
|
+
stroke: var(--ss-line-strong);
|
|
340
|
+
stroke-width: 1;
|
|
341
|
+
stroke-dasharray: 3 3;
|
|
342
|
+
shape-rendering: crispEdges;
|
|
343
|
+
}
|
|
344
|
+
.ss-scatter .tick {
|
|
345
|
+
font-family: var(--ss-font-mono);
|
|
346
|
+
font-size: var(--ss-ui-xs);
|
|
347
|
+
fill: var(--ss-fg-muted);
|
|
348
|
+
}
|
|
349
|
+
.ss-scatter .quadrant {
|
|
350
|
+
font-family: var(--ss-font-mono);
|
|
351
|
+
font-size: var(--ss-ui-xs);
|
|
352
|
+
fill: var(--ss-fg-muted);
|
|
353
|
+
opacity: 0.75;
|
|
354
|
+
}
|
|
355
|
+
.ss-scatter .axis-label {
|
|
356
|
+
font-family: var(--ss-font-mono);
|
|
357
|
+
font-size: var(--ss-ui-xs);
|
|
358
|
+
fill: var(--ss-fg-muted);
|
|
359
|
+
}
|
|
360
|
+
.ss-scatter .point {
|
|
361
|
+
cursor: pointer;
|
|
362
|
+
fill-opacity: 0.85;
|
|
363
|
+
transition: fill-opacity var(--ss-dur-fast) var(--ss-ease);
|
|
364
|
+
}
|
|
365
|
+
.ss-scatter .point:hover {
|
|
366
|
+
fill-opacity: 1;
|
|
367
|
+
}
|
|
368
|
+
.ss-scatter .point:focus-visible {
|
|
369
|
+
outline: none;
|
|
370
|
+
stroke: var(--ss-fg);
|
|
371
|
+
stroke-width: 2;
|
|
372
|
+
}
|
|
373
|
+
.ss-scatter .point-label {
|
|
374
|
+
font-family: var(--ss-font-mono);
|
|
375
|
+
font-size: var(--ss-ui-xs);
|
|
376
|
+
fill: var(--ss-fg);
|
|
377
|
+
pointer-events: none;
|
|
378
|
+
}
|
|
379
|
+
.ss-scatter .tooltip {
|
|
380
|
+
position: absolute;
|
|
381
|
+
transform: translate(-50%, calc(-100% - 8px));
|
|
382
|
+
pointer-events: none;
|
|
383
|
+
background: var(--ss-bg-elev);
|
|
384
|
+
border: 1px solid var(--ss-line-strong);
|
|
385
|
+
padding: var(--ss-gap-sm);
|
|
386
|
+
font-size: var(--ss-ui-xs);
|
|
387
|
+
line-height: 1.3;
|
|
388
|
+
white-space: nowrap;
|
|
389
|
+
display: flex;
|
|
390
|
+
flex-direction: column;
|
|
391
|
+
gap: 2px;
|
|
392
|
+
z-index: 2;
|
|
393
|
+
}
|
|
394
|
+
.ss-scatter .tooltip .t-label {
|
|
395
|
+
font-family: var(--ss-font-mono);
|
|
396
|
+
color: var(--ss-fg);
|
|
397
|
+
}
|
|
398
|
+
.ss-scatter .tooltip .t-val {
|
|
399
|
+
font-family: var(--ss-font-mono);
|
|
400
|
+
color: var(--ss-fg-muted);
|
|
401
|
+
}</style>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface ScatterPoint {
|
|
2
|
+
/** Label shown next to the dot and in the tooltip / accessible name. */
|
|
3
|
+
label: string;
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
/** Optional magnitude → bubble area (sqrt-scaled radius). Omit for a fixed dot. */
|
|
7
|
+
size?: number;
|
|
8
|
+
/** Optional per-point colour; falls back to the cycling palette. */
|
|
9
|
+
color?: string;
|
|
10
|
+
}
|
|
11
|
+
import { type Size } from '../config.js';
|
|
12
|
+
interface Props {
|
|
13
|
+
/** One dot per datum. Two encoded axes (x, y), optional `size` and `color`. */
|
|
14
|
+
points: ScatterPoint[];
|
|
15
|
+
/** X axis caption (drawn under the axis). */
|
|
16
|
+
xLabel?: string;
|
|
17
|
+
/** Y axis caption (drawn rotated beside the axis). */
|
|
18
|
+
yLabel?: string;
|
|
19
|
+
/** Draw a dashed vertical reference line at this x (e.g. the median) → quadrants. */
|
|
20
|
+
xRef?: number;
|
|
21
|
+
/** Draw a dashed horizontal reference line at this y (e.g. the median) → quadrants. */
|
|
22
|
+
yRef?: number;
|
|
23
|
+
/** Corner captions for the four quadrants (needs xRef + yRef to read well). */
|
|
24
|
+
quadrantLabels?: {
|
|
25
|
+
tl?: string;
|
|
26
|
+
tr?: string;
|
|
27
|
+
bl?: string;
|
|
28
|
+
br?: string;
|
|
29
|
+
};
|
|
30
|
+
/** Force the x domain; defaults to the padded data extent. */
|
|
31
|
+
xDomain?: [number, number];
|
|
32
|
+
/** Force the y domain; defaults to the padded data extent. */
|
|
33
|
+
yDomain?: [number, number];
|
|
34
|
+
/** Format an x value for ticks + tooltip. */
|
|
35
|
+
xFormat?: (x: number) => string;
|
|
36
|
+
/** Format a y value for ticks + tooltip. */
|
|
37
|
+
yFormat?: (y: number) => string;
|
|
38
|
+
/** Draw each point's label next to its dot. Default true. */
|
|
39
|
+
showLabels?: boolean;
|
|
40
|
+
/** Intrinsic drawing height in px. Default 320. */
|
|
41
|
+
height?: number;
|
|
42
|
+
/** Intrinsic drawing width in px. Default 420. */
|
|
43
|
+
width?: number;
|
|
44
|
+
/** Stretch to the container width via the viewBox (width:100%). */
|
|
45
|
+
fluid?: boolean;
|
|
46
|
+
/** Reveal a tooltip on hover/focus of a point. Default true. */
|
|
47
|
+
tooltip?: boolean;
|
|
48
|
+
/** SR summary + accessible name; auto-generated when absent. */
|
|
49
|
+
summary?: string;
|
|
50
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
51
|
+
size?: Size;
|
|
52
|
+
}
|
|
53
|
+
declare const ScatterPlot: import("svelte").Component<Props, {}, "">;
|
|
54
|
+
type ScatterPlot = ReturnType<typeof ScatterPlot>;
|
|
55
|
+
export default ScatterPlot;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
/** A single selectable option. */
|
|
3
|
+
export interface SelectOption {
|
|
4
|
+
value: string
|
|
5
|
+
label: string
|
|
6
|
+
disabled?: boolean
|
|
7
|
+
}
|
|
8
|
+
/** A labelled group of options, rendered as an <optgroup>. */
|
|
9
|
+
export interface SelectOptGroup {
|
|
10
|
+
label: string
|
|
11
|
+
options: SelectOption[]
|
|
12
|
+
}
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script lang="ts">
|
|
16
|
+
import type { HTMLSelectAttributes } from 'svelte/elements'
|
|
17
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
18
|
+
|
|
19
|
+
interface Props {
|
|
20
|
+
label?: string
|
|
21
|
+
id?: string
|
|
22
|
+
name?: string
|
|
23
|
+
value?: string
|
|
24
|
+
/** Flat options, or grouped options (detected by an `options` array on the first element). */
|
|
25
|
+
options?: SelectOption[] | SelectOptGroup[]
|
|
26
|
+
/** Renders a disabled, hidden first option, selected while the value is empty. */
|
|
27
|
+
placeholder?: string
|
|
28
|
+
required?: boolean
|
|
29
|
+
disabled?: boolean
|
|
30
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
31
|
+
size?: Size
|
|
32
|
+
/** Marks the field invalid for assistive tech (aria-invalid). */
|
|
33
|
+
invalid?: boolean
|
|
34
|
+
/** Supplementary helper text rendered under the select. */
|
|
35
|
+
hint?: string
|
|
36
|
+
/** Error text rendered under the select; its presence implies aria-invalid and is announced. */
|
|
37
|
+
error?: string
|
|
38
|
+
/** id(s) of element(s) describing the field (aria-describedby) — e.g. hint/error text. */
|
|
39
|
+
describedby?: string
|
|
40
|
+
onchange?: (e: Event & { currentTarget: HTMLSelectElement }) => void
|
|
41
|
+
/** Any remaining native select attributes / event handlers are forwarded. */
|
|
42
|
+
[key: string]: unknown
|
|
43
|
+
}
|
|
44
|
+
let {
|
|
45
|
+
label,
|
|
46
|
+
id,
|
|
47
|
+
name,
|
|
48
|
+
value = $bindable(''),
|
|
49
|
+
options = [],
|
|
50
|
+
placeholder,
|
|
51
|
+
required = false,
|
|
52
|
+
disabled = false,
|
|
53
|
+
size,
|
|
54
|
+
invalid,
|
|
55
|
+
hint,
|
|
56
|
+
error,
|
|
57
|
+
describedby,
|
|
58
|
+
onchange,
|
|
59
|
+
...rest
|
|
60
|
+
}: Props = $props()
|
|
61
|
+
|
|
62
|
+
// Guarantee a label↔select association even when no `id` is passed.
|
|
63
|
+
const uid = $props.id()
|
|
64
|
+
const selectId = $derived(id ?? uid)
|
|
65
|
+
const hintId = $derived(`${selectId}-hint`)
|
|
66
|
+
const errorId = $derived(`${selectId}-error`)
|
|
67
|
+
|
|
68
|
+
// error wins, then hint, then any caller-supplied describedby — order matters for AT.
|
|
69
|
+
const describedBy = $derived(
|
|
70
|
+
[error ? errorId : null, hint ? hintId : null, describedby].filter(Boolean).join(' ') ||
|
|
71
|
+
undefined,
|
|
72
|
+
)
|
|
73
|
+
const isInvalid = $derived(invalid || Boolean(error) || undefined)
|
|
74
|
+
const resolvedSize = $derived(resolveComponentSize('Select', size))
|
|
75
|
+
|
|
76
|
+
// Grouped input is detected by an `options` array on the first element.
|
|
77
|
+
const grouped = $derived(
|
|
78
|
+
options.length > 0 && Array.isArray((options[0] as SelectOptGroup).options),
|
|
79
|
+
)
|
|
80
|
+
const groups = $derived(grouped ? (options as SelectOptGroup[]) : [])
|
|
81
|
+
const flat = $derived(grouped ? [] : (options as SelectOption[]))
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<div class="ss-select" data-size-variant={resolvedSize} class:invalid={isInvalid} class:disabled>
|
|
85
|
+
{#if label}
|
|
86
|
+
<label class="lbl" for={selectId}>
|
|
87
|
+
{label}
|
|
88
|
+
{#if required}<span class="req" aria-hidden="true">*</span>{/if}
|
|
89
|
+
</label>
|
|
90
|
+
{/if}
|
|
91
|
+
|
|
92
|
+
<div class="control">
|
|
93
|
+
<select
|
|
94
|
+
class="select"
|
|
95
|
+
id={selectId}
|
|
96
|
+
{name}
|
|
97
|
+
bind:value
|
|
98
|
+
{required}
|
|
99
|
+
{disabled}
|
|
100
|
+
aria-invalid={isInvalid}
|
|
101
|
+
aria-describedby={describedBy}
|
|
102
|
+
{onchange}
|
|
103
|
+
{...rest}
|
|
104
|
+
>
|
|
105
|
+
{#if placeholder}
|
|
106
|
+
<option value="" disabled hidden selected={!value}>{placeholder}</option>
|
|
107
|
+
{/if}
|
|
108
|
+
{#if grouped}
|
|
109
|
+
{#each groups as group (group.label)}
|
|
110
|
+
<optgroup label={group.label}>
|
|
111
|
+
{#each group.options as opt (opt.value)}
|
|
112
|
+
<option value={opt.value} disabled={opt.disabled}>{opt.label}</option>
|
|
113
|
+
{/each}
|
|
114
|
+
</optgroup>
|
|
115
|
+
{/each}
|
|
116
|
+
{:else}
|
|
117
|
+
{#each flat as opt (opt.value)}
|
|
118
|
+
<option value={opt.value} disabled={opt.disabled}>{opt.label}</option>
|
|
119
|
+
{/each}
|
|
120
|
+
{/if}
|
|
121
|
+
</select>
|
|
122
|
+
<span class="chevron" aria-hidden="true"></span>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
{#if error}<span class="msg error" id={errorId} role="alert">{error}</span>{/if}
|
|
126
|
+
{#if hint}<span class="msg hint" id={hintId}>{hint}</span>{/if}
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<style>.ss-select {
|
|
130
|
+
display: flex;
|
|
131
|
+
flex-direction: column;
|
|
132
|
+
gap: 6px;
|
|
133
|
+
}
|
|
134
|
+
.ss-select .lbl {
|
|
135
|
+
font-family: var(--ss-font-mono);
|
|
136
|
+
font-size: var(--ss-ui-xs);
|
|
137
|
+
color: var(--ss-fg-muted);
|
|
138
|
+
text-transform: uppercase;
|
|
139
|
+
letter-spacing: 0.08em;
|
|
140
|
+
}
|
|
141
|
+
.ss-select .lbl .req {
|
|
142
|
+
color: var(--ss-red);
|
|
143
|
+
margin-left: 2px;
|
|
144
|
+
}
|
|
145
|
+
.ss-select .control {
|
|
146
|
+
position: relative;
|
|
147
|
+
display: flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
background: transparent;
|
|
150
|
+
color: var(--ss-fg);
|
|
151
|
+
border: 1px solid var(--ss-line);
|
|
152
|
+
padding: 0 var(--ss-input-px);
|
|
153
|
+
transition: border-color var(--ss-dur-fast) var(--ss-ease), box-shadow var(--ss-dur-fast) var(--ss-ease);
|
|
154
|
+
}
|
|
155
|
+
.ss-select .control:focus-within {
|
|
156
|
+
border-color: var(--ss-primary);
|
|
157
|
+
box-shadow: 0 0 0 3px var(--ss-primary-soft);
|
|
158
|
+
}
|
|
159
|
+
.ss-select.invalid .control {
|
|
160
|
+
border-color: var(--ss-red);
|
|
161
|
+
}
|
|
162
|
+
.ss-select.invalid .control:focus-within {
|
|
163
|
+
border-color: var(--ss-red);
|
|
164
|
+
box-shadow: 0 0 0 3px rgba(var(--ss-red-rgb), 0.22);
|
|
165
|
+
}
|
|
166
|
+
.ss-select.disabled .control {
|
|
167
|
+
border-color: var(--ss-line);
|
|
168
|
+
}
|
|
169
|
+
.ss-select .chevron {
|
|
170
|
+
flex: none;
|
|
171
|
+
pointer-events: none;
|
|
172
|
+
width: 0;
|
|
173
|
+
height: 0;
|
|
174
|
+
margin-left: var(--ss-gap-sm);
|
|
175
|
+
border-left: var(--ss-select-chevron, 5px) solid transparent;
|
|
176
|
+
border-right: var(--ss-select-chevron, 5px) solid transparent;
|
|
177
|
+
border-top: var(--ss-select-chevron, 5px) solid var(--ss-fg-muted);
|
|
178
|
+
transition: border-top-color var(--ss-dur-fast) var(--ss-ease);
|
|
179
|
+
}
|
|
180
|
+
.ss-select:not(.disabled) .control:focus-within .chevron {
|
|
181
|
+
border-top-color: var(--ss-fg);
|
|
182
|
+
}
|
|
183
|
+
.ss-select.disabled .chevron {
|
|
184
|
+
border-top-color: var(--ss-fg-faint);
|
|
185
|
+
}
|
|
186
|
+
.ss-select .msg {
|
|
187
|
+
font-family: var(--ss-font-mono);
|
|
188
|
+
font-size: var(--ss-ui-xs);
|
|
189
|
+
letter-spacing: 0.02em;
|
|
190
|
+
}
|
|
191
|
+
.ss-select .msg.hint {
|
|
192
|
+
color: var(--ss-fg-faint);
|
|
193
|
+
}
|
|
194
|
+
.ss-select .msg.error {
|
|
195
|
+
color: var(--ss-red);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.select {
|
|
199
|
+
appearance: none;
|
|
200
|
+
-webkit-appearance: none;
|
|
201
|
+
font-family: var(--ss-font-body);
|
|
202
|
+
font-size: var(--ss-input-font);
|
|
203
|
+
background: transparent;
|
|
204
|
+
color: var(--ss-fg);
|
|
205
|
+
border: none;
|
|
206
|
+
padding: var(--ss-input-py) 0;
|
|
207
|
+
width: 100%;
|
|
208
|
+
min-width: 0;
|
|
209
|
+
cursor: pointer;
|
|
210
|
+
transition: color var(--ss-dur-fast) var(--ss-ease);
|
|
211
|
+
}
|
|
212
|
+
.select:focus {
|
|
213
|
+
outline: none;
|
|
214
|
+
}
|
|
215
|
+
.select:disabled {
|
|
216
|
+
color: var(--ss-fg-faint);
|
|
217
|
+
cursor: not-allowed;
|
|
218
|
+
-webkit-text-fill-color: var(--ss-fg-faint);
|
|
219
|
+
}
|
|
220
|
+
.select option,
|
|
221
|
+
.select optgroup {
|
|
222
|
+
background: var(--ss-bg-elev);
|
|
223
|
+
color: var(--ss-fg);
|
|
224
|
+
}</style>
|