@lostgradient/cinder 0.22.0 → 0.23.1
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/CHANGELOG.md +63 -0
- package/components.json +1 -1
- package/dist/_internal/chart/chart-bar-model.d.ts +24 -0
- package/dist/_internal/chart/chart-cartesian-model.d.ts +16 -0
- package/dist/_internal/chart/chart-layout.d.ts +23 -0
- package/dist/_internal/chart/chart-model-utilities.d.ts +157 -0
- package/dist/_internal/chart/chart-scale.d.ts +37 -0
- package/dist/_internal/chart/chart-utilities.d.ts +7 -164
- package/dist/_internal/chart/heatmap-utilities.d.ts +5 -4
- package/dist/components/_internal/chart-tooltip.css +21 -0
- package/dist/components/_internal/chart-tooltip.svelte.d.ts +11 -0
- package/dist/components/approval-card/index.js +5 -5
- package/dist/components/area-chart/area-chart.css +27 -23
- package/dist/components/area-chart/area-chart.schema.js +38 -1
- package/dist/components/area-chart/area-chart.types.d.ts +6 -2
- package/dist/components/area-chart/index.js +1589 -768
- package/dist/components/badge/badge.css +2 -2
- package/dist/components/badge/badge.schema.js +2 -2
- package/dist/components/badge/badge.types.d.ts +3 -3
- package/dist/components/badge/index.js +4 -4
- package/dist/components/bar-chart/bar-chart.css +27 -21
- package/dist/components/bar-chart/bar-chart.schema.js +38 -1
- package/dist/components/bar-chart/bar-chart.types.d.ts +7 -3
- package/dist/components/bar-chart/index.js +1544 -740
- package/dist/components/chart.types.d.ts +98 -2
- package/dist/components/json-schema-editor/index.js +4 -4
- package/dist/components/line-chart/index.js +1587 -785
- package/dist/components/line-chart/line-chart.css +25 -24
- package/dist/components/line-chart/line-chart.schema.js +38 -1
- package/dist/components/line-chart/line-chart.types.d.ts +6 -2
- package/dist/components/matrix-chart/index.js +1038 -429
- package/dist/components/matrix-chart/matrix-chart.css +12 -6
- package/dist/components/matrix-chart/matrix-chart.schema.js +26 -1
- package/dist/components/matrix-chart/matrix-chart.types.d.ts +5 -1
- package/dist/components/payload-inspector/index.js +4 -4
- package/dist/components/run-step-timeline/index.js +6 -6
- package/dist/components/sparkbar/index.js +1291 -4
- package/dist/components/sparkbar/sparkbar.css +5 -4
- package/dist/components/sparkbar/sparkbar.schema.js +26 -1
- package/dist/components/sparkbar/sparkbar.types.d.ts +5 -0
- package/dist/components/spectrogram/index.js +1076 -437
- package/dist/components/spectrogram/spectrogram.css +7 -6
- package/dist/components/spectrogram/spectrogram.schema.js +26 -1
- package/dist/components/spectrogram/spectrogram.types.d.ts +5 -1
- package/dist/components/spectrum-chart/index.js +1037 -423
- package/dist/components/spectrum-chart/spectrum-chart.css +8 -7
- package/dist/components/spectrum-chart/spectrum-chart.schema.js +26 -1
- package/dist/components/spectrum-chart/spectrum-chart.types.d.ts +5 -1
- package/dist/components/statistic/index.js +1288 -2
- package/dist/components/statistic/statistic.css +6 -5
- package/dist/components/statistic/statistic.schema.js +26 -1
- package/dist/components/statistic/statistic.types.d.ts +5 -0
- package/dist/components/statistic-group/index.js +1288 -2
- package/dist/components/waveform/index.js +1004 -404
- package/dist/components/waveform/waveform.css +8 -7
- package/dist/components/waveform/waveform.schema.js +26 -1
- package/dist/components/waveform/waveform.types.d.ts +5 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17734 -16540
- package/dist/server/components/approval-card/index.js +3 -3
- package/dist/server/components/area-chart/index.js +3 -3
- package/dist/server/components/badge/index.js +2 -2
- package/dist/server/components/bar-chart/index.js +3 -3
- package/dist/server/components/json-schema-editor/index.js +2 -2
- package/dist/server/components/line-chart/index.js +3 -3
- package/dist/server/components/matrix-chart/index.js +3 -3
- package/dist/server/components/payload-inspector/index.js +3 -3
- package/dist/server/components/run-step-timeline/index.js +2 -2
- package/dist/server/components/sparkbar/index.js +3 -2
- package/dist/server/components/spectrogram/index.js +3 -3
- package/dist/server/components/spectrum-chart/index.js +2 -2
- package/dist/server/components/statistic/index.js +4 -3
- package/dist/server/components/statistic-group/index.js +4 -3
- package/dist/server/components/waveform/index.js +2 -2
- package/dist/server/index.js +21 -21
- package/dist/server/{index.server-3dkwzkd3.js → index.server-10r7yf13.js} +110 -27
- package/dist/server/{index.server-pp2n6def.js → index.server-2y0xz53g.js} +37 -14
- package/dist/server/{index.server-bd8rcgf0.js → index.server-4hvjet4z.js} +1 -1
- package/dist/server/{index.server-bsm39gpy.js → index.server-5d83fkyg.js} +75 -21
- package/dist/server/{index.server-abqbstkt.js → index.server-9gj583qs.js} +41 -14
- package/dist/server/{index.server-2nmwsacy.js → index.server-9scm7zf9.js} +4 -4
- package/dist/server/{index.server-5j6jv7rm.js → index.server-9vwxyy06.js} +108 -29
- package/dist/server/{index.server-abjsjsw8.js → index.server-afpjvfz1.js} +111 -35
- package/dist/server/{index.server-wm8957be.js → index.server-bp0vzxby.js} +14 -1
- package/dist/server/{index.server-86sw5ea6.js → index.server-dw9bz17h.js} +4 -4
- package/dist/server/{index.server-d26jzn2m.js → index.server-en31rprd.js} +3 -3
- package/dist/server/{index.server-dx58qant.js → index.server-f3a0ecqg.js} +72 -9
- package/dist/server/{index.server-d63pwytk.js → index.server-kz8aeeq5.js} +18 -10
- package/dist/server/index.server-mmmrgvyd.js +1274 -0
- package/dist/server/{index.server-93943z3e.js → index.server-rx9aszk6.js} +1 -1
- package/dist/server/{index.server-1221p7e4.js → index.server-scahngwv.js} +13 -1
- package/dist/server/{index.server-nj8kk5bv.js → index.server-t73q59c1.js} +1 -1
- package/dist/server/{index.server-5schb2vt.js → index.server-tdrncj5e.js} +16 -6
- package/dist/server/{index.server-4wweyb2e.js → index.server-vnr1h5g5.js} +1 -1
- package/dist/server/{index.server-fphvzcfb.js → index.server-wqajghn9.js} +1 -1
- package/dist/server/{index.server-yd9shwqq.js → index.server-zjcjzcv6.js} +1 -1
- package/package.json +1 -1
- package/src/_internal/chart/chart-bar-model.ts +330 -0
- package/src/_internal/chart/chart-cartesian-model.ts +450 -0
- package/src/_internal/chart/chart-interaction.svelte.ts +25 -6
- package/src/_internal/chart/chart-layout.ts +348 -0
- package/src/_internal/chart/chart-model-utilities.ts +357 -0
- package/src/_internal/chart/chart-scale.ts +487 -0
- package/src/_internal/chart/chart-utilities.ts +22 -1078
- package/src/_internal/chart/heatmap-utilities.ts +21 -17
- package/src/components/_internal/chart-tooltip.css +21 -0
- package/src/components/_internal/chart-tooltip.svelte +44 -0
- package/src/components/approval-card/approval-card.svelte +1 -1
- package/src/components/area-chart/area-chart.css +27 -23
- package/src/components/area-chart/area-chart.examples.json +1 -1
- package/src/components/area-chart/area-chart.schema.json +37 -0
- package/src/components/area-chart/area-chart.schema.ts +40 -0
- package/src/components/area-chart/area-chart.svelte +103 -35
- package/src/components/area-chart/area-chart.types.ts +7 -1
- package/src/components/badge/badge.css +2 -2
- package/src/components/badge/badge.schema.json +1 -1
- package/src/components/badge/badge.schema.ts +1 -1
- package/src/components/badge/badge.svelte +2 -2
- package/src/components/badge/badge.types.ts +3 -3
- package/src/components/bar-chart/bar-chart.css +27 -21
- package/src/components/bar-chart/bar-chart.schema.json +37 -0
- package/src/components/bar-chart/bar-chart.schema.ts +40 -0
- package/src/components/bar-chart/bar-chart.svelte +94 -33
- package/src/components/bar-chart/bar-chart.types.ts +9 -2
- package/src/components/chart.types.ts +112 -2
- package/src/components/line-chart/line-chart.css +25 -24
- package/src/components/line-chart/line-chart.examples.json +1 -1
- package/src/components/line-chart/line-chart.schema.json +37 -0
- package/src/components/line-chart/line-chart.schema.ts +40 -0
- package/src/components/line-chart/line-chart.svelte +95 -40
- package/src/components/line-chart/line-chart.types.ts +7 -1
- package/src/components/matrix-chart/matrix-chart.css +12 -6
- package/src/components/matrix-chart/matrix-chart.schema.json +25 -0
- package/src/components/matrix-chart/matrix-chart.schema.ts +25 -0
- package/src/components/matrix-chart/matrix-chart.svelte +30 -12
- package/src/components/matrix-chart/matrix-chart.types.ts +5 -1
- package/src/components/run-step-timeline/run-step-timeline.svelte +2 -2
- package/src/components/sparkbar/sparkbar.css +5 -4
- package/src/components/sparkbar/sparkbar.schema.json +25 -0
- package/src/components/sparkbar/sparkbar.schema.ts +26 -0
- package/src/components/sparkbar/sparkbar.svelte +8 -1
- package/src/components/sparkbar/sparkbar.types.ts +5 -0
- package/src/components/spectrogram/spectrogram.css +7 -6
- package/src/components/spectrogram/spectrogram.schema.json +25 -0
- package/src/components/spectrogram/spectrogram.schema.ts +25 -0
- package/src/components/spectrogram/spectrogram.svelte +73 -28
- package/src/components/spectrogram/spectrogram.types.ts +5 -1
- package/src/components/spectrum-chart/spectrum-chart.css +8 -7
- package/src/components/spectrum-chart/spectrum-chart.schema.json +25 -0
- package/src/components/spectrum-chart/spectrum-chart.schema.ts +26 -0
- package/src/components/spectrum-chart/spectrum-chart.svelte +38 -12
- package/src/components/spectrum-chart/spectrum-chart.types.ts +5 -1
- package/src/components/statistic/statistic.css +6 -5
- package/src/components/statistic/statistic.schema.json +25 -0
- package/src/components/statistic/statistic.schema.ts +26 -0
- package/src/components/statistic/statistic.svelte +42 -1
- package/src/components/statistic/statistic.types.ts +5 -0
- package/src/components/waveform/waveform.css +8 -7
- package/src/components/waveform/waveform.schema.json +25 -0
- package/src/components/waveform/waveform.schema.ts +26 -0
- package/src/components/waveform/waveform.svelte +16 -3
- package/src/components/waveform/waveform.types.ts +5 -1
- package/src/index.ts +8 -0
- package/dist/server/index.server-6vbpz6dd.js +0 -690
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* two component implementations.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { chartPaletteColor } from './chart-utilities.ts';
|
|
11
|
+
|
|
10
12
|
export type HeatmapColorScale = 'sequential' | 'diverging';
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -125,35 +127,37 @@ export function heatmapCellFill(
|
|
|
125
127
|
value: number | null,
|
|
126
128
|
domain: HeatmapDomain,
|
|
127
129
|
scale: HeatmapColorScale = 'sequential',
|
|
130
|
+
palette?: readonly string[],
|
|
131
|
+
background = 'var(--cinder-surface-inset)',
|
|
128
132
|
): string {
|
|
129
|
-
if (value === null) return
|
|
133
|
+
if (value === null) return background;
|
|
130
134
|
const normalized = normalizeHeatmapValue(value, domain, scale);
|
|
131
135
|
|
|
132
136
|
if (scale === 'diverging') {
|
|
137
|
+
const coolColor = chartPaletteColor(4, palette);
|
|
138
|
+
let warmColor = chartPaletteColor(2, palette);
|
|
139
|
+
// Short custom palettes wrap around. Keep the two diverging ends distinct
|
|
140
|
+
// whenever callers provide at least two colors.
|
|
141
|
+
if (palette && palette.length >= 2 && warmColor === coolColor) {
|
|
142
|
+
warmColor = chartPaletteColor(1, palette);
|
|
143
|
+
}
|
|
133
144
|
if (normalized < 0.5) {
|
|
134
145
|
const ratio = (0.5 - normalized) * 2;
|
|
135
|
-
return `color-mix(in oklch,
|
|
146
|
+
return `color-mix(in oklch, ${coolColor} ${Math.round(ratio * 100)}%, ${background})`;
|
|
136
147
|
}
|
|
137
148
|
const ratio = (normalized - 0.5) * 2;
|
|
138
|
-
return `color-mix(in oklch,
|
|
149
|
+
return `color-mix(in oklch, ${warmColor} ${Math.round(ratio * 100)}%, ${background})`;
|
|
139
150
|
}
|
|
140
151
|
|
|
141
|
-
return `color-mix(in oklch,
|
|
152
|
+
return `color-mix(in oklch, ${chartPaletteColor(0, palette)} ${Math.round(normalized * 100)}%, ${background})`;
|
|
142
153
|
}
|
|
143
154
|
|
|
144
155
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
156
|
+
* Provide the opaque source colour used by the MatrixChart's difference blend.
|
|
157
|
+
* The browser composites this against the actual rendered cell, so arbitrary
|
|
158
|
+
* custom palettes remain readable without guessing their luminance in JavaScript.
|
|
147
159
|
*/
|
|
148
|
-
export function heatmapLabelFill(
|
|
149
|
-
value
|
|
150
|
-
|
|
151
|
-
scale: HeatmapColorScale = 'sequential',
|
|
152
|
-
): string {
|
|
153
|
-
if (value === null) return 'var(--cinder-text-muted)';
|
|
154
|
-
const intensity =
|
|
155
|
-
scale === 'diverging'
|
|
156
|
-
? Math.abs(normalizeHeatmapValue(value, domain, scale) - 0.5) * 2
|
|
157
|
-
: normalizeHeatmapValue(value, domain, scale);
|
|
158
|
-
return intensity > 0.5 ? 'var(--cinder-surface)' : 'var(--cinder-text)';
|
|
160
|
+
export function heatmapLabelFill(value: number | null, muted = 'currentColor'): string {
|
|
161
|
+
if (value === null) return muted;
|
|
162
|
+
return 'var(--cinder-text-inverse)';
|
|
159
163
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
|
|
2
|
+
@layer cinder.components {
|
|
3
|
+
.cinder-chart-tooltip-anchor {
|
|
4
|
+
position: absolute;
|
|
5
|
+
width: 1px;
|
|
6
|
+
height: 1px;
|
|
7
|
+
pointer-events: none;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.cinder-chart-tooltip {
|
|
11
|
+
display: grid;
|
|
12
|
+
gap: var(--cinder-space-1);
|
|
13
|
+
color: inherit;
|
|
14
|
+
font-size: var(--cinder-text-sm);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.cinder-chart-tooltip strong,
|
|
18
|
+
.cinder-chart-tooltip span {
|
|
19
|
+
display: block;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Popover from '@lostgradient/cinder/popover';
|
|
3
|
+
let { id, target, geometry, content, } = $props();
|
|
4
|
+
let anchorElement = $state(null);
|
|
5
|
+
const outsideClickIgnoreRefs = [() => anchorElement?.ownerDocument.body ?? null];
|
|
6
|
+
const customContent = $derived(typeof content === 'function' ? content : undefined);
|
|
7
|
+
const open = $derived(Boolean(anchorElement && target && content));
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<span
|
|
11
|
+
bind:this={anchorElement}
|
|
12
|
+
class="cinder-chart-tooltip-anchor"
|
|
13
|
+
aria-hidden="true"
|
|
14
|
+
style:left={`${geometry.marginLeft + (target?.x ?? 0)}px`}
|
|
15
|
+
style:top={`${geometry.marginTop + (target?.y ?? 0)}px`}
|
|
16
|
+
></span>
|
|
17
|
+
|
|
18
|
+
<!-- This non-interactive tooltip stays controlled by the chart's active target. -->
|
|
19
|
+
<Popover
|
|
20
|
+
id={`${id}-popover`}
|
|
21
|
+
{open}
|
|
22
|
+
triggerRef={anchorElement}
|
|
23
|
+
placement="right"
|
|
24
|
+
arrowVisible
|
|
25
|
+
role="group"
|
|
26
|
+
focusManagement="preserve"
|
|
27
|
+
{outsideClickIgnoreRefs}
|
|
28
|
+
wireTriggerAria={false}
|
|
29
|
+
closeOnEscape={false}
|
|
30
|
+
widthMode="content"
|
|
31
|
+
>
|
|
32
|
+
{#snippet children()}
|
|
33
|
+
{#if target}
|
|
34
|
+
<div {id} role="tooltip" class="cinder-chart-tooltip">
|
|
35
|
+
{#if customContent}
|
|
36
|
+
{@render customContent(target)}
|
|
37
|
+
{:else}
|
|
38
|
+
<strong>{target.seriesLabel}</strong>
|
|
39
|
+
<span>{target.xLabel}: {target.valueLabel}</span>
|
|
40
|
+
{/if}
|
|
41
|
+
</div>
|
|
42
|
+
{/if}
|
|
43
|
+
{/snippet}
|
|
44
|
+
</Popover>
|
|
@@ -221,7 +221,7 @@ function resolveIfActionable(resolution) {
|
|
|
221
221
|
>
|
|
222
222
|
{#each environmentNames as environmentName (environmentName)}
|
|
223
223
|
<li>
|
|
224
|
-
<Badge size="sm"
|
|
224
|
+
<Badge size="sm" monospace>{environmentName}</Badge>
|
|
225
225
|
</li>
|
|
226
226
|
{/each}
|
|
227
227
|
</ul>
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
|
|
2
2
|
@import '../table/table.css';
|
|
3
|
+
@import '../_internal/chart-tooltip.css';
|
|
3
4
|
@layer cinder.components {
|
|
4
5
|
.cinder-area-chart {
|
|
5
6
|
display: grid;
|
|
6
7
|
gap: var(--cinder-space-3);
|
|
7
|
-
color: var(--
|
|
8
|
+
color: var(--_cinder-chart-foreground, currentColor);
|
|
9
|
+
background: var(--_cinder-chart-background, transparent);
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
.cinder-area-chart__description {
|
|
11
13
|
margin: 0;
|
|
12
|
-
color: var(--
|
|
14
|
+
color: var(--_cinder-chart-muted, currentColor);
|
|
15
|
+
opacity: 0.72;
|
|
13
16
|
font-size: var(--cinder-text-sm);
|
|
14
17
|
}
|
|
15
18
|
|
|
@@ -25,8 +28,8 @@
|
|
|
25
28
|
gap: var(--cinder-space-1);
|
|
26
29
|
border: 1px solid var(--cinder-border);
|
|
27
30
|
border-radius: var(--cinder-radius-sm);
|
|
28
|
-
background: var(--
|
|
29
|
-
color:
|
|
31
|
+
background: var(--_cinder-chart-background, transparent);
|
|
32
|
+
color: inherit;
|
|
30
33
|
cursor: pointer;
|
|
31
34
|
font: inherit;
|
|
32
35
|
font-size: var(--cinder-text-sm);
|
|
@@ -54,22 +57,25 @@
|
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
.cinder-area-chart__area {
|
|
57
|
-
|
|
60
|
+
transition: d 0.3s ease;
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
.cinder-area-chart__line {
|
|
61
64
|
fill: none;
|
|
62
65
|
stroke-width: 2;
|
|
66
|
+
transition: d 0.3s ease;
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
.cinder-area-chart__gridline {
|
|
66
|
-
stroke: var(--
|
|
70
|
+
stroke: var(--_cinder-chart-grid, currentColor);
|
|
67
71
|
stroke-width: 1;
|
|
72
|
+
opacity: 0.22;
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
.cinder-area-chart__crosshair {
|
|
71
|
-
stroke: var(--
|
|
76
|
+
stroke: var(--_cinder-chart-muted, currentColor);
|
|
72
77
|
stroke-dasharray: 4 4;
|
|
78
|
+
opacity: 0.72;
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
.cinder-area-chart__hit-surface {
|
|
@@ -142,32 +148,30 @@
|
|
|
142
148
|
}
|
|
143
149
|
}
|
|
144
150
|
|
|
145
|
-
.cinder-area-chart__tick-label
|
|
146
|
-
|
|
151
|
+
.cinder-area-chart__tick-label,
|
|
152
|
+
.cinder-area-chart__axis-title {
|
|
153
|
+
fill: var(--_cinder-chart-muted, currentColor);
|
|
147
154
|
font-size: var(--cinder-text-xs);
|
|
148
155
|
}
|
|
149
156
|
|
|
157
|
+
.cinder-area-chart__tick-label {
|
|
158
|
+
opacity: 0.72;
|
|
159
|
+
}
|
|
160
|
+
|
|
150
161
|
.cinder-area-chart__state {
|
|
151
162
|
position: absolute;
|
|
152
163
|
inset: 0;
|
|
153
164
|
display: grid;
|
|
154
165
|
place-items: center;
|
|
155
|
-
color: var(--
|
|
156
|
-
background:
|
|
166
|
+
color: var(--_cinder-chart-muted, currentColor);
|
|
167
|
+
background: var(--_cinder-chart-background, transparent);
|
|
157
168
|
z-index: 1;
|
|
158
169
|
}
|
|
159
170
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
border: 1px solid var(--cinder-border);
|
|
166
|
-
border-radius: var(--cinder-radius-sm);
|
|
167
|
-
background: var(--cinder-surface-raised);
|
|
168
|
-
box-shadow: var(--cinder-shadow-md);
|
|
169
|
-
font-size: var(--cinder-text-sm);
|
|
170
|
-
padding: var(--cinder-space-2);
|
|
171
|
-
pointer-events: none;
|
|
171
|
+
@media (prefers-reduced-motion: reduce) {
|
|
172
|
+
.cinder-area-chart__area,
|
|
173
|
+
.cinder-area-chart__line {
|
|
174
|
+
transition: none;
|
|
175
|
+
}
|
|
172
176
|
}
|
|
173
177
|
}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"title": "Usage area",
|
|
21
21
|
"description": "A single-series area chart for product usage.",
|
|
22
22
|
"featured": true,
|
|
23
|
-
"code": "<script lang=\"ts\">\n import { AreaChart } from '@lostgradient/cinder/area-chart';\n\n const series = [\n {\n id: 'usage',\n label: 'Usage',\n data: [\n { x: 'Jan', y: 44 },\n { x: 'Feb', y: 61 },\n { x: 'Mar', y: 79 },\n ],\n },\n ];\n</script>\n\n<AreaChart label=\"Product usage\" {series} />\n"
|
|
23
|
+
"code": "<script lang=\"ts\">\n import { AreaChart } from '@lostgradient/cinder/area-chart';\n\n const series = [\n {\n id: 'usage',\n label: 'Usage',\n data: [\n { x: 'Jan', y: 44 },\n { x: 'Feb', y: 61 },\n { x: 'Mar', y: 79 },\n ],\n },\n ];\n</script>\n\n<AreaChart label=\"Product usage\" {series} tooltip />\n"
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
26
|
"id": "stacked",
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"tickCount": {
|
|
24
24
|
"type": "number"
|
|
25
|
+
},
|
|
26
|
+
"tickLabelRotation": {
|
|
27
|
+
"type": "number"
|
|
25
28
|
}
|
|
26
29
|
},
|
|
27
30
|
"additionalProperties": false,
|
|
@@ -67,6 +70,35 @@
|
|
|
67
70
|
"type": "number",
|
|
68
71
|
"description": "Maximum number of interactive focus targets before keyboard navigation is disabled. Default `500`."
|
|
69
72
|
},
|
|
73
|
+
"theme": {
|
|
74
|
+
"type": "object",
|
|
75
|
+
"properties": {
|
|
76
|
+
"foreground": {
|
|
77
|
+
"type": "string"
|
|
78
|
+
},
|
|
79
|
+
"muted": {
|
|
80
|
+
"type": "string"
|
|
81
|
+
},
|
|
82
|
+
"grid": {
|
|
83
|
+
"type": "string"
|
|
84
|
+
},
|
|
85
|
+
"background": {
|
|
86
|
+
"type": "string"
|
|
87
|
+
},
|
|
88
|
+
"palette": {
|
|
89
|
+
"type": "array",
|
|
90
|
+
"items": {
|
|
91
|
+
"type": "string"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"additionalProperties": false,
|
|
96
|
+
"description": "Partial visual theme override. Omitted fields inherit the surrounding application."
|
|
97
|
+
},
|
|
98
|
+
"tooltip": {
|
|
99
|
+
"type": "boolean",
|
|
100
|
+
"description": "Enable the default visual tooltip. Custom snippet tooltips are available in the TypeScript API."
|
|
101
|
+
},
|
|
70
102
|
"class": {
|
|
71
103
|
"type": "string",
|
|
72
104
|
"description": "Custom class applied to the root element."
|
|
@@ -137,6 +169,11 @@
|
|
|
137
169
|
{
|
|
138
170
|
"name": "loadingContent",
|
|
139
171
|
"reason": "function-or-snippet"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"name": "mark",
|
|
175
|
+
"reason": "function-or-snippet",
|
|
176
|
+
"description": "Per-series renderer override. The chart retains scales, guides, focus, and data-table semantics."
|
|
140
177
|
}
|
|
141
178
|
]
|
|
142
179
|
}
|
|
@@ -25,6 +25,9 @@ const schema = {
|
|
|
25
25
|
tickCount: {
|
|
26
26
|
type: 'number',
|
|
27
27
|
},
|
|
28
|
+
tickLabelRotation: {
|
|
29
|
+
type: 'number',
|
|
30
|
+
},
|
|
28
31
|
},
|
|
29
32
|
additionalProperties: false,
|
|
30
33
|
description: 'Configuration for the x-axis label and tick count.',
|
|
@@ -71,6 +74,37 @@ const schema = {
|
|
|
71
74
|
description:
|
|
72
75
|
'Maximum number of interactive focus targets before keyboard navigation is disabled. Default `500`.',
|
|
73
76
|
},
|
|
77
|
+
theme: {
|
|
78
|
+
type: 'object',
|
|
79
|
+
properties: {
|
|
80
|
+
foreground: {
|
|
81
|
+
type: 'string',
|
|
82
|
+
},
|
|
83
|
+
muted: {
|
|
84
|
+
type: 'string',
|
|
85
|
+
},
|
|
86
|
+
grid: {
|
|
87
|
+
type: 'string',
|
|
88
|
+
},
|
|
89
|
+
background: {
|
|
90
|
+
type: 'string',
|
|
91
|
+
},
|
|
92
|
+
palette: {
|
|
93
|
+
type: 'array',
|
|
94
|
+
items: {
|
|
95
|
+
type: 'string',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
additionalProperties: false,
|
|
100
|
+
description:
|
|
101
|
+
'Partial visual theme override. Omitted fields inherit the surrounding application.',
|
|
102
|
+
},
|
|
103
|
+
tooltip: {
|
|
104
|
+
type: 'boolean',
|
|
105
|
+
description:
|
|
106
|
+
'Enable the default visual tooltip. Custom snippet tooltips are available in the TypeScript API.',
|
|
107
|
+
},
|
|
74
108
|
class: {
|
|
75
109
|
type: 'string',
|
|
76
110
|
description: 'Custom class applied to the root element.',
|
|
@@ -142,6 +176,12 @@ const schema = {
|
|
|
142
176
|
name: 'loadingContent',
|
|
143
177
|
reason: 'function-or-snippet',
|
|
144
178
|
},
|
|
179
|
+
{
|
|
180
|
+
name: 'mark',
|
|
181
|
+
reason: 'function-or-snippet',
|
|
182
|
+
description:
|
|
183
|
+
'Per-series renderer override. The chart retains scales, guides, focus, and data-table semantics.',
|
|
184
|
+
},
|
|
145
185
|
],
|
|
146
186
|
},
|
|
147
187
|
} satisfies ComponentSchema;
|
|
@@ -3,12 +3,14 @@ export {};
|
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
5
|
<script lang="ts">
|
|
6
|
-
import {
|
|
6
|
+
import { onMount } from 'svelte';
|
|
7
|
+
import { assertValidNonNegativeInteger, chartPaletteColor, chartResourceId, createCartesianModel, dataTableClass, formatDataTableCaption, formatNumericValue, legendVisible, observeChartFontLoading, } from '../../_internal/chart/chart-utilities.ts';
|
|
7
8
|
import { DEFAULT_CHART_FOCUS_RING_STROKE_PADDING, createPointFocusRingGeometry, } from '../../_internal/chart/chart-focus-ring.ts';
|
|
8
9
|
import { ChartInteraction } from '../../_internal/chart/chart-interaction.svelte.ts';
|
|
9
10
|
import ChartDataTable from '../_internal/chart-data-table.svelte';
|
|
11
|
+
import ChartTooltip from '../_internal/chart-tooltip.svelte';
|
|
10
12
|
import { classNames } from '../../utilities/class-names.ts';
|
|
11
|
-
let { label, description, series, mode = 'single', height = 280, xAxis, yAxis, legendPosition = 'top', hiddenSeriesIds = $bindable([]), loading = false, dataTableCaption, dataTableVisibility = 'screen-reader-only', maximumInteractivePoints = 500, class: customClassName, empty, loadingContent, id, ...rest } = $props();
|
|
13
|
+
let { label, description, series, mode = 'single', height = 280, xAxis, yAxis, legendPosition = 'top', hiddenSeriesIds = $bindable([]), loading = false, dataTableCaption, dataTableVisibility = 'screen-reader-only', maximumInteractivePoints = 500, theme, tooltip = false, mark, class: customClassName, empty, loadingContent, id, ...rest } = $props();
|
|
12
14
|
const generatedId = $props.id();
|
|
13
15
|
const rootId = $derived(id ?? generatedId);
|
|
14
16
|
const descriptionId = $derived(description ? `${rootId}-description` : undefined);
|
|
@@ -16,6 +18,14 @@ const descriptionId = $derived(description ? `${rootId}-description` : undefined
|
|
|
16
18
|
// Pointer axis defaults to 'x', which is correct for line/area charts.
|
|
17
19
|
const interaction = new ChartInteraction();
|
|
18
20
|
let rootElement = $state();
|
|
21
|
+
let measureText = $state(false);
|
|
22
|
+
let measurementVersion = $state(0);
|
|
23
|
+
onMount(() => {
|
|
24
|
+
measureText = true;
|
|
25
|
+
return observeChartFontLoading(() => {
|
|
26
|
+
measurementVersion += 1;
|
|
27
|
+
});
|
|
28
|
+
});
|
|
19
29
|
$effect(() => {
|
|
20
30
|
if (!rootElement)
|
|
21
31
|
return;
|
|
@@ -30,6 +40,10 @@ const model = $derived(createCartesianModel({
|
|
|
30
40
|
xAxis,
|
|
31
41
|
yAxis,
|
|
32
42
|
stackedArea: mode === 'stacked',
|
|
43
|
+
theme,
|
|
44
|
+
measureText,
|
|
45
|
+
measurementElement: rootElement,
|
|
46
|
+
measurementVersion,
|
|
33
47
|
}));
|
|
34
48
|
const keyboardEnabled = $derived(model.targets.length > 0 && model.targets.length <= maximumInteractivePoints);
|
|
35
49
|
const hasDataTable = $derived(dataTableVisibility !== 'hidden');
|
|
@@ -97,6 +111,10 @@ function handleTargetKeydown(event) {
|
|
|
97
111
|
bind:this={rootElement}
|
|
98
112
|
id={rootId}
|
|
99
113
|
class={classNames('cinder-area-chart', customClassName)}
|
|
114
|
+
style:--_cinder-chart-foreground={model.theme.foreground}
|
|
115
|
+
style:--_cinder-chart-muted={model.theme.muted}
|
|
116
|
+
style:--_cinder-chart-grid={model.theme.grid}
|
|
117
|
+
style:--_cinder-chart-background={model.theme.background}
|
|
100
118
|
aria-label={label}
|
|
101
119
|
aria-describedby={descriptionId}
|
|
102
120
|
data-cinder-mode={mode}
|
|
@@ -111,7 +129,7 @@ function handleTargetKeydown(event) {
|
|
|
111
129
|
type="button"
|
|
112
130
|
aria-pressed={!hiddenSeriesIds.includes(item.id)}
|
|
113
131
|
onclick={() => (hiddenSeriesIds = interaction.toggleSeries(hiddenSeriesIds, item.id))}
|
|
114
|
-
><span style:background={item.color ?? chartPaletteColor(index)}
|
|
132
|
+
><span style:background={item.color ?? chartPaletteColor(index, model.theme.palette)}
|
|
115
133
|
></span>{item.label}</button
|
|
116
134
|
>
|
|
117
135
|
{/each}
|
|
@@ -161,33 +179,82 @@ function handleTargetKeydown(event) {
|
|
|
161
179
|
>{formatNumericValue(tick, yAxis, undefined, { index })}</text
|
|
162
180
|
>
|
|
163
181
|
{/each}
|
|
182
|
+
{#if yAxis?.label}
|
|
183
|
+
<text
|
|
184
|
+
class="cinder-area-chart__axis-title"
|
|
185
|
+
x={-model.geometry.plotHeight / 2}
|
|
186
|
+
y={-model.geometry.marginLeft + 12}
|
|
187
|
+
text-anchor="middle"
|
|
188
|
+
transform="rotate(-90)">{yAxis.label}</text
|
|
189
|
+
>
|
|
190
|
+
{/if}
|
|
164
191
|
{#each model.xTicks as tick (tick.label)}
|
|
165
192
|
<text
|
|
166
193
|
class="cinder-area-chart__tick-label"
|
|
167
194
|
x={tick.x}
|
|
168
195
|
y={model.geometry.plotHeight + 20}
|
|
196
|
+
transform={xAxis?.tickLabelRotation
|
|
197
|
+
? `rotate(${xAxis.tickLabelRotation} ${tick.x} ${model.geometry.plotHeight + 20})`
|
|
198
|
+
: undefined}
|
|
169
199
|
text-anchor="middle">{tick.label}</text
|
|
170
200
|
>
|
|
171
201
|
{/each}
|
|
202
|
+
{#if xAxis?.label}
|
|
203
|
+
<text
|
|
204
|
+
class="cinder-area-chart__axis-title"
|
|
205
|
+
x={model.geometry.plotWidth / 2}
|
|
206
|
+
y={model.geometry.plotHeight + model.geometry.marginBottom - 4}
|
|
207
|
+
text-anchor="middle">{xAxis.label}</text
|
|
208
|
+
>
|
|
209
|
+
{/if}
|
|
210
|
+
<defs>
|
|
211
|
+
{#each model.normalizedSeries as item (item.id)}
|
|
212
|
+
<linearGradient
|
|
213
|
+
id={chartResourceId(rootId, 'gradient', item.id)}
|
|
214
|
+
x1="0"
|
|
215
|
+
x2="0"
|
|
216
|
+
y1="0"
|
|
217
|
+
y2="1"
|
|
218
|
+
>
|
|
219
|
+
<stop offset="0" stop-color={item.color} stop-opacity="0.42" />
|
|
220
|
+
<stop offset="1" stop-color={item.color} stop-opacity="0.08" />
|
|
221
|
+
</linearGradient>
|
|
222
|
+
{/each}
|
|
223
|
+
</defs>
|
|
172
224
|
<!-- Series-specific rendering: filled area paths + stroke line paths. -->
|
|
173
|
-
{#
|
|
174
|
-
{#
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
225
|
+
{#if mark}
|
|
226
|
+
{#each model.normalizedSeries as item (item.id)}
|
|
227
|
+
{#if !hiddenSeriesIds.includes(item.id)}
|
|
228
|
+
{@const sourceSeries = series.find((candidate) => candidate.id === item.id)}
|
|
229
|
+
{#if sourceSeries}
|
|
230
|
+
{@render mark({
|
|
231
|
+
series: sourceSeries,
|
|
232
|
+
points: item.points,
|
|
233
|
+
geometry: model.geometry,
|
|
234
|
+
})}
|
|
235
|
+
{/if}
|
|
236
|
+
{/if}
|
|
237
|
+
{/each}
|
|
238
|
+
{:else}
|
|
239
|
+
{#each model.normalizedSeries as item (item.id)}
|
|
240
|
+
{#if !hiddenSeriesIds.includes(item.id) && item.areaPath}
|
|
241
|
+
<path
|
|
242
|
+
class="cinder-area-chart__area"
|
|
243
|
+
d={item.areaPath}
|
|
244
|
+
fill={`url(#${chartResourceId(rootId, 'gradient', item.id)})`}
|
|
245
|
+
aria-hidden="true"
|
|
246
|
+
data-cinder-series={item.id}
|
|
247
|
+
/>
|
|
248
|
+
<path
|
|
249
|
+
class="cinder-area-chart__line"
|
|
250
|
+
d={item.path}
|
|
251
|
+
stroke={item.color}
|
|
252
|
+
aria-hidden="true"
|
|
253
|
+
data-cinder-series={item.id}
|
|
254
|
+
/>
|
|
255
|
+
{/if}
|
|
256
|
+
{/each}
|
|
257
|
+
{/if}
|
|
191
258
|
{#if interaction.activeTarget}
|
|
192
259
|
<!-- Vertical crosshair — area charts always use a vertical indicator. -->
|
|
193
260
|
<line
|
|
@@ -224,7 +291,7 @@ function handleTargetKeydown(event) {
|
|
|
224
291
|
? 'true'
|
|
225
292
|
: undefined}
|
|
226
293
|
aria-label={`${target.seriesLabel}, ${target.xLabel}, ${target.valueLabel}`}
|
|
227
|
-
aria-describedby={interaction.activeTarget?.id === target.id
|
|
294
|
+
aria-describedby={tooltip && interaction.activeTarget?.id === target.id
|
|
228
295
|
? `${rootId}-tooltip`
|
|
229
296
|
: undefined}
|
|
230
297
|
onfocus={() => handleTargetFocus(target)}
|
|
@@ -294,24 +361,25 @@ function handleTargetKeydown(event) {
|
|
|
294
361
|
</g>
|
|
295
362
|
{/if}
|
|
296
363
|
</svg>
|
|
297
|
-
{#if
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
>{interaction.activeTarget.xLabel}: {interaction.activeTarget.valueLabel}</span
|
|
306
|
-
>
|
|
307
|
-
</div>{/if}
|
|
364
|
+
{#if tooltip}
|
|
365
|
+
<ChartTooltip
|
|
366
|
+
id={`${rootId}-tooltip`}
|
|
367
|
+
target={interaction.activeTarget}
|
|
368
|
+
geometry={model.geometry}
|
|
369
|
+
content={tooltip}
|
|
370
|
+
/>
|
|
371
|
+
{/if}
|
|
308
372
|
</div>
|
|
309
373
|
{#if guidanceId}<p id={guidanceId} class="cinder-sr-only">
|
|
310
374
|
Use the data table to inspect this chart with a keyboard.
|
|
311
375
|
</p>{/if}
|
|
312
376
|
{#if hasDataTable}
|
|
313
377
|
<ChartDataTable
|
|
314
|
-
caption={
|
|
378
|
+
caption={formatDataTableCaption(
|
|
379
|
+
dataTableCaption ?? label,
|
|
380
|
+
model.tableRows.length,
|
|
381
|
+
model.targets.length,
|
|
382
|
+
)}
|
|
315
383
|
headers={['Series', 'X', 'Value']}
|
|
316
384
|
rows={model.tableRows.map((row) => ({
|
|
317
385
|
id: row.id,
|
|
@@ -329,7 +397,7 @@ function handleTargetKeydown(event) {
|
|
|
329
397
|
type="button"
|
|
330
398
|
aria-pressed={!hiddenSeriesIds.includes(item.id)}
|
|
331
399
|
onclick={() => (hiddenSeriesIds = interaction.toggleSeries(hiddenSeriesIds, item.id))}
|
|
332
|
-
><span style:background={item.color ?? chartPaletteColor(index)}
|
|
400
|
+
><span style:background={item.color ?? chartPaletteColor(index, model.theme.palette)}
|
|
333
401
|
></span>{item.label}</button
|
|
334
402
|
>
|
|
335
403
|
{/each}
|
|
@@ -6,6 +6,8 @@ import type {
|
|
|
6
6
|
ChartJsonXValue,
|
|
7
7
|
ChartLegendPosition,
|
|
8
8
|
ChartSharedProps,
|
|
9
|
+
ChartThemeSchema,
|
|
10
|
+
ChartXAxisSchemaConfiguration,
|
|
9
11
|
} from '../chart.types.ts';
|
|
10
12
|
|
|
11
13
|
export type AreaChartProps = ChartSharedProps & {
|
|
@@ -37,7 +39,7 @@ export type AreaChartSchemaProps = {
|
|
|
37
39
|
/** Pixel height of the chart viewport. Default `280`. */
|
|
38
40
|
height?: number;
|
|
39
41
|
/** Configuration for the x-axis label and tick count. */
|
|
40
|
-
xAxis?:
|
|
42
|
+
xAxis?: ChartXAxisSchemaConfiguration;
|
|
41
43
|
/** Configuration for the y-axis label and tick count. */
|
|
42
44
|
yAxis?: ChartAxisSchemaConfiguration;
|
|
43
45
|
/** Where to render the series legend relative to the chart. Default `top`. */
|
|
@@ -52,6 +54,10 @@ export type AreaChartSchemaProps = {
|
|
|
52
54
|
dataTableVisibility?: ChartDataTableVisibility;
|
|
53
55
|
/** Maximum number of interactive focus targets before keyboard navigation is disabled. Default `500`. */
|
|
54
56
|
maximumInteractivePoints?: number;
|
|
57
|
+
/** Partial visual theme override. Omitted fields inherit the surrounding application. */
|
|
58
|
+
theme?: ChartThemeSchema;
|
|
59
|
+
/** Enable the default visual tooltip. Custom snippet tooltips are available in the TypeScript API. */
|
|
60
|
+
tooltip?: boolean;
|
|
55
61
|
/** Custom class applied to the root element. */
|
|
56
62
|
class?: string;
|
|
57
63
|
/** Series rendered as independent filled areas or stacked areas. */
|
|
@@ -84,10 +84,10 @@
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/* ----------------------------------------
|
|
87
|
-
*
|
|
87
|
+
* Monospace affordance
|
|
88
88
|
* ---------------------------------------- */
|
|
89
89
|
|
|
90
|
-
.cinder-badge[data-cinder-
|
|
90
|
+
.cinder-badge[data-cinder-monospace] {
|
|
91
91
|
font-family: var(
|
|
92
92
|
--cinder-font-mono,
|
|
93
93
|
ui-monospace,
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"description": "Size of the badge.",
|
|
13
13
|
"default": "md"
|
|
14
14
|
},
|
|
15
|
-
"
|
|
15
|
+
"monospace": {
|
|
16
16
|
"type": "boolean",
|
|
17
17
|
"description": "Render the badge label in a monospace font. Useful for version strings, error codes, or other technical labels.",
|
|
18
18
|
"default": false
|
|
@@ -14,7 +14,7 @@ const schema = {
|
|
|
14
14
|
description: 'Size of the badge.',
|
|
15
15
|
default: 'md',
|
|
16
16
|
},
|
|
17
|
-
|
|
17
|
+
monospace: {
|
|
18
18
|
type: 'boolean',
|
|
19
19
|
description:
|
|
20
20
|
'Render the badge label in a monospace font. Useful for version strings, error codes, or other technical labels.',
|