@stacksjs/components 0.2.991 → 0.2.997
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/ApiOperation-369y1zgt.stx +114 -0
- package/dist/ApiReference-ww45jj32.stx +92 -0
- package/dist/ApiSchema-dsx4tsv4.stx +47 -0
- package/dist/AreaChart-8fy34adp.stx +77 -0
- package/dist/BarChart-4xdrjhhn.stx +77 -0
- package/dist/{Combobox-9n04ec5w.stx → Combobox-fgbpxbty.stx} +174 -5
- package/dist/ComboboxOptions-sfkc98a9.stx +36 -0
- package/dist/{CommandPalette-cj6pe5ph.stx → CommandPalette-sf03s7b2.stx} +3 -1
- package/dist/LineChart-ctebkkm8.stx +77 -0
- package/dist/{Notification-ke5vw4k8.stx → Notification-1pvt347q.stx} +11 -3
- package/dist/{Popover-jjt7p7sn.stx → Popover-gntg33xd.stx} +1 -1
- package/dist/PricingPlan-h7jt2696.stx +67 -0
- package/dist/PricingTable-v3vdn6av.stx +149 -0
- package/dist/SecretField-q2xgth94.stx +219 -0
- package/dist/{Select-36s22z6d.stx → Select-yhmtvqcx.stx} +7 -4
- package/dist/Sparkline-gp859n4h.stx +29 -0
- package/dist/StatCard-gff0yx6b.stx +93 -0
- package/dist/StatGroup-e0d5dmt7.stx +17 -0
- package/dist/components/CodeBlock.d.ts +4 -1
- package/dist/components/CodeGroup.d.ts +34 -0
- package/dist/components/code-group.d.ts +19 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +25 -22
- package/dist/ui/api-reference/ApiOperation.d.ts +17 -0
- package/dist/ui/api-reference/ApiReference.d.ts +28 -0
- package/dist/ui/api-reference/ApiSchema.d.ts +17 -0
- package/dist/ui/api-reference/index.d.ts +30 -0
- package/dist/ui/api-reference/openapi.d.ts +137 -0
- package/dist/ui/chart/AreaChart.d.ts +33 -0
- package/dist/ui/chart/BarChart.d.ts +33 -0
- package/dist/ui/chart/LineChart.d.ts +33 -0
- package/dist/ui/chart/Sparkline.d.ts +19 -0
- package/dist/ui/chart/core.d.ts +111 -0
- package/dist/ui/chart/index.d.ts +51 -0
- package/dist/ui/chart/interaction.d.ts +11 -0
- package/dist/ui/combobox/Combobox.d.ts +10 -1
- package/dist/ui/combobox/ComboboxOptions.d.ts +6 -0
- package/dist/ui/combobox/index.d.ts +7 -0
- package/dist/ui/command-palette/CommandPalette.d.ts +2 -0
- package/dist/ui/input/SecretField.d.ts +56 -0
- package/dist/ui/input/index.d.ts +21 -0
- package/dist/ui/notification/Notification.d.ts +2 -0
- package/dist/ui/pricing/PricingPlan.d.ts +21 -0
- package/dist/ui/pricing/PricingTable.d.ts +50 -0
- package/dist/ui/pricing/index.d.ts +38 -0
- package/dist/ui/pricing/pricing.d.ts +64 -0
- package/dist/ui/select/Select.d.ts +2 -0
- package/dist/ui/stat/StatCard.d.ts +42 -0
- package/dist/ui/stat/StatGroup.d.ts +12 -0
- package/dist/ui/stat/format.d.ts +37 -0
- package/dist/ui/stat/index.d.ts +23 -0
- package/package.json +3 -3
- package/src/components/CodeBlock.stx +4 -1
- package/src/components/CodeGroup.stx +217 -0
- package/src/components/code-group.ts +57 -0
- package/src/components/index.ts +2 -0
- package/src/index.ts +18 -0
- package/src/ui/api-reference/ApiOperation.stx +114 -0
- package/src/ui/api-reference/ApiReference.stx +92 -0
- package/src/ui/api-reference/ApiSchema.stx +47 -0
- package/src/ui/api-reference/README.md +44 -0
- package/src/ui/api-reference/index.ts +35 -0
- package/src/ui/api-reference/openapi.ts +825 -0
- package/src/ui/chart/AreaChart.stx +77 -0
- package/src/ui/chart/BarChart.stx +77 -0
- package/src/ui/chart/LineChart.stx +77 -0
- package/src/ui/chart/README.md +97 -0
- package/src/ui/chart/Sparkline.stx +29 -0
- package/src/ui/chart/core.ts +730 -0
- package/src/ui/chart/index.ts +71 -0
- package/src/ui/chart/interaction.ts +175 -0
- package/src/ui/combobox/Combobox.stx +174 -5
- package/src/ui/combobox/ComboboxOptions.stx +20 -0
- package/src/ui/combobox/README.md +41 -0
- package/src/ui/combobox/index.ts +13 -0
- package/src/ui/command-palette/CommandPalette.stx +3 -1
- package/src/ui/input/SecretField.stx +219 -0
- package/src/ui/input/index.ts +32 -0
- package/src/ui/notification/Notification.stx +11 -3
- package/src/ui/popover/Popover.stx +1 -1
- package/src/ui/pricing/PricingPlan.stx +67 -0
- package/src/ui/pricing/PricingTable.stx +149 -0
- package/src/ui/pricing/README.md +74 -0
- package/src/ui/pricing/index.ts +49 -0
- package/src/ui/pricing/pricing.ts +177 -0
- package/src/ui/select/Select.stx +7 -4
- package/src/ui/stat/README.md +60 -0
- package/src/ui/stat/StatCard.stx +93 -0
- package/src/ui/stat/StatGroup.stx +17 -0
- package/src/ui/stat/format.ts +147 -0
- package/src/ui/stat/index.ts +38 -0
- package/dist/ComboboxOptions-zhr9b6rx.stx +0 -16
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
import { prepareChart } from './core'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* <AreaChart> (stacksjs/stx#2318). The SVG is drawn here, on the server, so
|
|
6
|
+
* the chart shows before any script runs; the client script only lays it out
|
|
7
|
+
* again at its real width and adds the crosshair, tooltip and keyboard.
|
|
8
|
+
*
|
|
9
|
+
* The data and the accessors stay on the server (`serverOnlyProps`): the
|
|
10
|
+
* client gets the prepared model, every label already formatted, so a
|
|
11
|
+
* `formatY` function works and the records are not shipped twice.
|
|
12
|
+
*/
|
|
13
|
+
export const serverOnlyProps = ['data', 'x', 'y', 'series', 'formatX', 'formatY', 'colors', 'yDomain']
|
|
14
|
+
const chart = prepareChart('area', $props)
|
|
15
|
+
export const label = $props.label || 'Chart'
|
|
16
|
+
export const loading = $bool($props.loading)
|
|
17
|
+
export const emptyText = $props.emptyText || 'No data to show yet'
|
|
18
|
+
export const empty = chart.empty
|
|
19
|
+
export const svg = chart.svg
|
|
20
|
+
export const modelJson = chart.modelJson
|
|
21
|
+
export const summary = chart.summary
|
|
22
|
+
export const tableHead = chart.tableHead
|
|
23
|
+
export const tableRows = chart.tableRows
|
|
24
|
+
export const legend = chart.legend
|
|
25
|
+
export const height = chart.model.height
|
|
26
|
+
export const chartId = $props.id || `chart-${$uid}`
|
|
27
|
+
export const summaryId = `${chartId}-summary`
|
|
28
|
+
export const className = $props.className || ''
|
|
29
|
+
export const figureClasses = `relative ${className}`.trim()
|
|
30
|
+
export const surfaceClasses = 'relative rounded-control outline-none focus-visible:ring-2 focus-visible:ring-accent'
|
|
31
|
+
export const tooltipClasses = 'pointer-events-none absolute top-2 z-10 min-w-32 rounded-panel bg-inverse px-3 py-2 text-xs text-inverse-ink shadow-lg'
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<script client>
|
|
35
|
+
import { mountChart } from './interaction'
|
|
36
|
+
|
|
37
|
+
const emit = defineEmits(['hover'])
|
|
38
|
+
const chartId = {{ chartId }}
|
|
39
|
+
const model = {!! modelJson !!}
|
|
40
|
+
let dispose = null
|
|
41
|
+
|
|
42
|
+
onMount(() => {
|
|
43
|
+
const root = document.getElementById(chartId)
|
|
44
|
+
if (root) dispose = mountChart(root, model, { onHover: detail => emit('hover', detail) })
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
onDestroy(() => { if (dispose) dispose() })
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<figure id="{{ chartId }}" class="{{ figureClasses }}" data-stx-chart="area" @if(!empty && !loading)tabindex="0" role="group" aria-label="{{ label }}" aria-describedby="{{ summaryId }}"@endif>
|
|
51
|
+
@if(loading)
|
|
52
|
+
<div aria-busy="true"><span class="sr-only">Loading {{ label }}</span><Skeleton variant="rect" :height="height" width="100%" /></div>
|
|
53
|
+
@elseif(empty)
|
|
54
|
+
<EmptyState variant="bare" :title="emptyText" />
|
|
55
|
+
@else
|
|
56
|
+
@if(legend.length)
|
|
57
|
+
<ul class="mb-2 flex flex-wrap gap-x-4 gap-y-1 text-xs text-fg-soft" aria-hidden="true" data-stx-chart-legend>
|
|
58
|
+
@foreach(legend as item)
|
|
59
|
+
<li class="inline-flex items-center gap-1.5"><span class="inline-block h-2 w-2 rounded-full" style="background: {{ item.color }}"></span>{{ item.label }}</li>
|
|
60
|
+
@endforeach
|
|
61
|
+
</ul>
|
|
62
|
+
@endif
|
|
63
|
+
<div class="{{ surfaceClasses }}" data-stx-chart-surface>{!! svg !!}</div>
|
|
64
|
+
<div class="{{ tooltipClasses }}" data-stx-chart-tooltip hidden aria-hidden="true"></div>
|
|
65
|
+
<p id="{{ summaryId }}" class="sr-only">{{ summary }}. Use the arrow keys to step through the points.</p>
|
|
66
|
+
<table class="sr-only" data-stx-chart-table>
|
|
67
|
+
<caption>{{ label }}</caption>
|
|
68
|
+
<thead><tr>@foreach(tableHead as heading)<th scope="col">{{ heading }}</th>@endforeach</tr></thead>
|
|
69
|
+
<tbody>
|
|
70
|
+
@foreach(tableRows as row)
|
|
71
|
+
<tr>@foreach(row as cell)<td>{{ cell }}</td>@endforeach</tr>
|
|
72
|
+
@endforeach
|
|
73
|
+
</tbody>
|
|
74
|
+
</table>
|
|
75
|
+
<span class="sr-only" role="status" aria-live="polite" data-stx-chart-live></span>
|
|
76
|
+
@endif
|
|
77
|
+
</figure>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
import { prepareChart } from './core'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* <BarChart> (stacksjs/stx#2318). The SVG is drawn here, on the server, so
|
|
6
|
+
* the chart shows before any script runs; the client script only lays it out
|
|
7
|
+
* again at its real width and adds the crosshair, tooltip and keyboard.
|
|
8
|
+
*
|
|
9
|
+
* The data and the accessors stay on the server (`serverOnlyProps`): the
|
|
10
|
+
* client gets the prepared model, every label already formatted, so a
|
|
11
|
+
* `formatY` function works and the records are not shipped twice.
|
|
12
|
+
*/
|
|
13
|
+
export const serverOnlyProps = ['data', 'x', 'y', 'series', 'formatX', 'formatY', 'colors', 'yDomain']
|
|
14
|
+
const chart = prepareChart('bar', $props)
|
|
15
|
+
export const label = $props.label || 'Chart'
|
|
16
|
+
export const loading = $bool($props.loading)
|
|
17
|
+
export const emptyText = $props.emptyText || 'No data to show yet'
|
|
18
|
+
export const empty = chart.empty
|
|
19
|
+
export const svg = chart.svg
|
|
20
|
+
export const modelJson = chart.modelJson
|
|
21
|
+
export const summary = chart.summary
|
|
22
|
+
export const tableHead = chart.tableHead
|
|
23
|
+
export const tableRows = chart.tableRows
|
|
24
|
+
export const legend = chart.legend
|
|
25
|
+
export const height = chart.model.height
|
|
26
|
+
export const chartId = $props.id || `chart-${$uid}`
|
|
27
|
+
export const summaryId = `${chartId}-summary`
|
|
28
|
+
export const className = $props.className || ''
|
|
29
|
+
export const figureClasses = `relative ${className}`.trim()
|
|
30
|
+
export const surfaceClasses = 'relative rounded-control outline-none focus-visible:ring-2 focus-visible:ring-accent'
|
|
31
|
+
export const tooltipClasses = 'pointer-events-none absolute top-2 z-10 min-w-32 rounded-panel bg-inverse px-3 py-2 text-xs text-inverse-ink shadow-lg'
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<script client>
|
|
35
|
+
import { mountChart } from './interaction'
|
|
36
|
+
|
|
37
|
+
const emit = defineEmits(['hover'])
|
|
38
|
+
const chartId = {{ chartId }}
|
|
39
|
+
const model = {!! modelJson !!}
|
|
40
|
+
let dispose = null
|
|
41
|
+
|
|
42
|
+
onMount(() => {
|
|
43
|
+
const root = document.getElementById(chartId)
|
|
44
|
+
if (root) dispose = mountChart(root, model, { onHover: detail => emit('hover', detail) })
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
onDestroy(() => { if (dispose) dispose() })
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<figure id="{{ chartId }}" class="{{ figureClasses }}" data-stx-chart="bar" @if(!empty && !loading)tabindex="0" role="group" aria-label="{{ label }}" aria-describedby="{{ summaryId }}"@endif>
|
|
51
|
+
@if(loading)
|
|
52
|
+
<div aria-busy="true"><span class="sr-only">Loading {{ label }}</span><Skeleton variant="rect" :height="height" width="100%" /></div>
|
|
53
|
+
@elseif(empty)
|
|
54
|
+
<EmptyState variant="bare" :title="emptyText" />
|
|
55
|
+
@else
|
|
56
|
+
@if(legend.length)
|
|
57
|
+
<ul class="mb-2 flex flex-wrap gap-x-4 gap-y-1 text-xs text-fg-soft" aria-hidden="true" data-stx-chart-legend>
|
|
58
|
+
@foreach(legend as item)
|
|
59
|
+
<li class="inline-flex items-center gap-1.5"><span class="inline-block h-2 w-2 rounded-full" style="background: {{ item.color }}"></span>{{ item.label }}</li>
|
|
60
|
+
@endforeach
|
|
61
|
+
</ul>
|
|
62
|
+
@endif
|
|
63
|
+
<div class="{{ surfaceClasses }}" data-stx-chart-surface>{!! svg !!}</div>
|
|
64
|
+
<div class="{{ tooltipClasses }}" data-stx-chart-tooltip hidden aria-hidden="true"></div>
|
|
65
|
+
<p id="{{ summaryId }}" class="sr-only">{{ summary }}. Use the arrow keys to step through the points.</p>
|
|
66
|
+
<table class="sr-only" data-stx-chart-table>
|
|
67
|
+
<caption>{{ label }}</caption>
|
|
68
|
+
<thead><tr>@foreach(tableHead as heading)<th scope="col">{{ heading }}</th>@endforeach</tr></thead>
|
|
69
|
+
<tbody>
|
|
70
|
+
@foreach(tableRows as row)
|
|
71
|
+
<tr>@foreach(row as cell)<td>{{ cell }}</td>@endforeach</tr>
|
|
72
|
+
@endforeach
|
|
73
|
+
</tbody>
|
|
74
|
+
</table>
|
|
75
|
+
<span class="sr-only" role="status" aria-live="polite" data-stx-chart-live></span>
|
|
76
|
+
@endif
|
|
77
|
+
</figure>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
import { prepareChart } from './core'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* <LineChart> (stacksjs/stx#2318). The SVG is drawn here, on the server, so
|
|
6
|
+
* the chart shows before any script runs; the client script only lays it out
|
|
7
|
+
* again at its real width and adds the crosshair, tooltip and keyboard.
|
|
8
|
+
*
|
|
9
|
+
* The data and the accessors stay on the server (`serverOnlyProps`): the
|
|
10
|
+
* client gets the prepared model, every label already formatted, so a
|
|
11
|
+
* `formatY` function works and the records are not shipped twice.
|
|
12
|
+
*/
|
|
13
|
+
export const serverOnlyProps = ['data', 'x', 'y', 'series', 'formatX', 'formatY', 'colors', 'yDomain']
|
|
14
|
+
const chart = prepareChart('line', $props)
|
|
15
|
+
export const label = $props.label || 'Chart'
|
|
16
|
+
export const loading = $bool($props.loading)
|
|
17
|
+
export const emptyText = $props.emptyText || 'No data to show yet'
|
|
18
|
+
export const empty = chart.empty
|
|
19
|
+
export const svg = chart.svg
|
|
20
|
+
export const modelJson = chart.modelJson
|
|
21
|
+
export const summary = chart.summary
|
|
22
|
+
export const tableHead = chart.tableHead
|
|
23
|
+
export const tableRows = chart.tableRows
|
|
24
|
+
export const legend = chart.legend
|
|
25
|
+
export const height = chart.model.height
|
|
26
|
+
export const chartId = $props.id || `chart-${$uid}`
|
|
27
|
+
export const summaryId = `${chartId}-summary`
|
|
28
|
+
export const className = $props.className || ''
|
|
29
|
+
export const figureClasses = `relative ${className}`.trim()
|
|
30
|
+
export const surfaceClasses = 'relative rounded-control outline-none focus-visible:ring-2 focus-visible:ring-accent'
|
|
31
|
+
export const tooltipClasses = 'pointer-events-none absolute top-2 z-10 min-w-32 rounded-panel bg-inverse px-3 py-2 text-xs text-inverse-ink shadow-lg'
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<script client>
|
|
35
|
+
import { mountChart } from './interaction'
|
|
36
|
+
|
|
37
|
+
const emit = defineEmits(['hover'])
|
|
38
|
+
const chartId = {{ chartId }}
|
|
39
|
+
const model = {!! modelJson !!}
|
|
40
|
+
let dispose = null
|
|
41
|
+
|
|
42
|
+
onMount(() => {
|
|
43
|
+
const root = document.getElementById(chartId)
|
|
44
|
+
if (root) dispose = mountChart(root, model, { onHover: detail => emit('hover', detail) })
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
onDestroy(() => { if (dispose) dispose() })
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<figure id="{{ chartId }}" class="{{ figureClasses }}" data-stx-chart="line" @if(!empty && !loading)tabindex="0" role="group" aria-label="{{ label }}" aria-describedby="{{ summaryId }}"@endif>
|
|
51
|
+
@if(loading)
|
|
52
|
+
<div aria-busy="true"><span class="sr-only">Loading {{ label }}</span><Skeleton variant="rect" :height="height" width="100%" /></div>
|
|
53
|
+
@elseif(empty)
|
|
54
|
+
<EmptyState variant="bare" :title="emptyText" />
|
|
55
|
+
@else
|
|
56
|
+
@if(legend.length)
|
|
57
|
+
<ul class="mb-2 flex flex-wrap gap-x-4 gap-y-1 text-xs text-fg-soft" aria-hidden="true" data-stx-chart-legend>
|
|
58
|
+
@foreach(legend as item)
|
|
59
|
+
<li class="inline-flex items-center gap-1.5"><span class="inline-block h-2 w-2 rounded-full" style="background: {{ item.color }}"></span>{{ item.label }}</li>
|
|
60
|
+
@endforeach
|
|
61
|
+
</ul>
|
|
62
|
+
@endif
|
|
63
|
+
<div class="{{ surfaceClasses }}" data-stx-chart-surface>{!! svg !!}</div>
|
|
64
|
+
<div class="{{ tooltipClasses }}" data-stx-chart-tooltip hidden aria-hidden="true"></div>
|
|
65
|
+
<p id="{{ summaryId }}" class="sr-only">{{ summary }}. Use the arrow keys to step through the points.</p>
|
|
66
|
+
<table class="sr-only" data-stx-chart-table>
|
|
67
|
+
<caption>{{ label }}</caption>
|
|
68
|
+
<thead><tr>@foreach(tableHead as heading)<th scope="col">{{ heading }}</th>@endforeach</tr></thead>
|
|
69
|
+
<tbody>
|
|
70
|
+
@foreach(tableRows as row)
|
|
71
|
+
<tr>@foreach(row as cell)<td>{{ cell }}</td>@endforeach</tr>
|
|
72
|
+
@endforeach
|
|
73
|
+
</tbody>
|
|
74
|
+
</table>
|
|
75
|
+
<span class="sr-only" role="status" aria-live="polite" data-stx-chart-live></span>
|
|
76
|
+
@endif
|
|
77
|
+
</figure>
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Chart
|
|
2
|
+
|
|
3
|
+
Declarative charts drawn as SVG: `<LineChart>`, `<AreaChart>`, `<BarChart>` and `<Sparkline>`. No dependency, no canvas.
|
|
4
|
+
|
|
5
|
+
- **Server-rendered first.** The SVG is drawn on the server, so a chart is visible before any script runs. The client script only lays it out again at the container's real width (a `ResizeObserver`) and adds the crosshair, tooltip and keyboard.
|
|
6
|
+
- **Themed by role tokens.** Series default to the accent, info, success, warning, danger and secondary roles; grid and labels use `line` and `fg-soft`. Dark mode and an app's palette follow without configuration.
|
|
7
|
+
- **Accessible.** Each chart has a name (`label`), a one-sentence summary, a visually hidden data table, and keyboard stepping that announces each point.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```stx
|
|
12
|
+
<script server>
|
|
13
|
+
const latency = await Monitor.latency(monitor.id) // [{ checked_at, ms }, ...]
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<AreaChart :data="latency" x="checked_at" y="ms" formatY="duration" label="Response time" :height="200" />
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
That is the StatusHQ monitor latency chart: one tag instead of a page of scale and path math.
|
|
20
|
+
|
|
21
|
+
### Several series
|
|
22
|
+
|
|
23
|
+
```stx
|
|
24
|
+
<LineChart
|
|
25
|
+
:data="usage"
|
|
26
|
+
x="day"
|
|
27
|
+
:series="[{ key: 'requests', label: 'Requests' }, { key: 'errors', label: 'Errors', color: 'var(--stx-danger)' }]"
|
|
28
|
+
label="Requests and errors per day"
|
|
29
|
+
@hover="showDetail"
|
|
30
|
+
/>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Bars
|
|
34
|
+
|
|
35
|
+
```stx
|
|
36
|
+
<BarChart :data="spendByMonth" x="month" y="total" formatY="currency" label="Spend per month" />
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`x` values that are strings make a band axis; ISO dates are labelled as days.
|
|
40
|
+
|
|
41
|
+
### Sparkline
|
|
42
|
+
|
|
43
|
+
```stx
|
|
44
|
+
<Sparkline :data="[120, 180, 150, 210, 96, 240]" label="Requests this week" area />
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
A plain array of numbers is plotted against its index. `<StatCard :series="...">` draws one beside its value.
|
|
48
|
+
|
|
49
|
+
## Props
|
|
50
|
+
|
|
51
|
+
Shared by `LineChart`, `AreaChart` and `BarChart`:
|
|
52
|
+
|
|
53
|
+
| Prop | Type | Default | Description |
|
|
54
|
+
|------|------|---------|-------------|
|
|
55
|
+
| `data` | `object[] \| number[]` | - | The records, or numbers plotted by index |
|
|
56
|
+
| `x` | `string \| (d, i) => any` | `'x'` | Key or accessor for x |
|
|
57
|
+
| `y` | `string \| function \| string[]` | `'y'` | Key or accessor for y; an array of keys draws one series per key |
|
|
58
|
+
| `series` | `Array<string \| { key, label, color }>` | - | Series with labels and colours; overrides `y` |
|
|
59
|
+
| `height` | `number` | `240` | Pixel height |
|
|
60
|
+
| `xType` | `'time' \| 'linear' \| 'band'` | inferred | `band` for bars and string x, `time` for dates, else `linear` |
|
|
61
|
+
| `yDomain` | `[min, max]` | from data | A `null` end is taken from the data; bars and areas include zero |
|
|
62
|
+
| `curve` | `'monotone' \| 'linear' \| 'step'` | `'monotone'` | Line interpolation (`monotone` never overshoots a point) |
|
|
63
|
+
| `colors` | `string[]` | role tokens | Series colours |
|
|
64
|
+
| `formatX` | `(value, index) => string` | dates by span, numbers by locale | Tick and tooltip labels for x |
|
|
65
|
+
| `formatY` | `function \| 'number' \| 'percent' \| 'duration' \| 'bytes' \| 'currency'` | locale number | Tick and tooltip labels for y; a string uses the StatCard formats |
|
|
66
|
+
| `label` | `string` | `'Chart'` | Accessible name, and the caption of the data table |
|
|
67
|
+
| `xLabel` | `string` | `'Time'` / `'X'` | Header of the x column in the data table |
|
|
68
|
+
| `locale` | `string` | `'en-US'` | Number and date locale |
|
|
69
|
+
| `timeZone` | `string` | `'UTC'` | Zone for time labels, so the server and browser agree |
|
|
70
|
+
| `ticks` | `number` | `5` | Approximate ticks per axis |
|
|
71
|
+
| `loading` | `boolean` | `false` | Show a skeleton at the chart's height |
|
|
72
|
+
| `emptyText` | `string` | `'No data to show yet'` | Shown through `EmptyState` for an empty array |
|
|
73
|
+
| `id`, `className` | `string` | - | |
|
|
74
|
+
|
|
75
|
+
`Sparkline` takes `data`, `x`, `y`, `label`, `height` (32), `area`, `curve`, `colors`, `formatY` and `className`.
|
|
76
|
+
|
|
77
|
+
Formatter and accessor functions run on the server, so pass them as bound props (`:formatX="d => ..."`). The records and accessors are listed in `serverOnlyProps`: the client receives only the prepared model, with every label already formatted.
|
|
78
|
+
|
|
79
|
+
## Events
|
|
80
|
+
|
|
81
|
+
| Event | Payload |
|
|
82
|
+
|------|---------|
|
|
83
|
+
| `hover` | `{ index, datum, x, values: [{ series, value, label }] }` for the point under the pointer or keyboard focus, `null` when it leaves |
|
|
84
|
+
|
|
85
|
+
## Keyboard
|
|
86
|
+
|
|
87
|
+
The chart is a single tab stop. Arrow keys step point to point, Home and End jump to the ends, Escape clears. Each step is announced through a polite live region ("Nov 3, 2026: Requests 150, Errors 8").
|
|
88
|
+
|
|
89
|
+
## States
|
|
90
|
+
|
|
91
|
+
- **Empty**: an empty array renders `EmptyState` with `emptyText`.
|
|
92
|
+
- **Loading**: `loading` renders a `Skeleton` at the chart's height.
|
|
93
|
+
- **Gaps**: a `null` or missing y breaks the line; a point with no neighbour is drawn as a dot, so a single datum still shows.
|
|
94
|
+
|
|
95
|
+
## Out of scope
|
|
96
|
+
|
|
97
|
+
Pie, donut, scatter, candlestick and map charts; canvas or WebGL rendering; native-screen rendering.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script server cache>
|
|
2
|
+
import { prepareChart } from './core'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* <Sparkline> (stacksjs/stx#2318): a word-sized trend line with no axes and
|
|
6
|
+
* no script. `data` is an array of numbers, or records with `x` and `y`
|
|
7
|
+
* accessors like the other charts. It is an image to assistive technology,
|
|
8
|
+
* named by `label` and a sentence: "from 120 to 180, low 96, high 210".
|
|
9
|
+
*/
|
|
10
|
+
const chart = prepareChart('sparkline', {
|
|
11
|
+
...$props,
|
|
12
|
+
height: $num($props.height, 32),
|
|
13
|
+
area: $bool($props.area),
|
|
14
|
+
}, $num($props.width, 120))
|
|
15
|
+
export const label = $props.label || 'Trend'
|
|
16
|
+
export const empty = chart.empty
|
|
17
|
+
export const description = `${label}: ${chart.summary.replace(/^[^:]*:\s*/, '')}`
|
|
18
|
+
export const height = chart.model.height
|
|
19
|
+
export const className = $props.className || ''
|
|
20
|
+
export const svg = chart.empty ? '' : chart.svg
|
|
21
|
+
export const color = chart.model.series[0] ? chart.model.series[0].color : ''
|
|
22
|
+
export const sparkClasses = `block ${className}`.trim()
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
@if(empty)
|
|
26
|
+
<span class="{{ sparkClasses }}" style="height: {{ height }}px" role="img" aria-label="{{ label }}: no data" data-stx-sparkline data-empty="true"></span>
|
|
27
|
+
@else
|
|
28
|
+
<span class="{{ sparkClasses }}" role="img" aria-label="{{ description }}" data-stx-sparkline>{!! svg !!}</span>
|
|
29
|
+
@endif
|