@aiaiai-pt/design-system 0.52.0 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/DataTable.svelte +3 -1
- package/components/DataTable.svelte.d.ts +2 -0
- package/components/EChart.svelte +34 -3
- package/components/EChart.svelte.d.ts +15 -0
- package/components/renderer/chart-option.d.ts +13 -0
- package/components/renderer/chart-option.ts +51 -0
- package/package.json +44 -1
- package/tokens/components.css +4 -0
|
@@ -121,6 +121,8 @@
|
|
|
121
121
|
cell = undefined,
|
|
122
122
|
/** @type {import('svelte').Snippet | undefined} */
|
|
123
123
|
children = undefined,
|
|
124
|
+
/** @type {string | undefined} Accessible name for the <table> itself; spread attributes land on the wrapper. */
|
|
125
|
+
caption = undefined,
|
|
124
126
|
/** @type {string} */
|
|
125
127
|
class: className = '',
|
|
126
128
|
...rest
|
|
@@ -222,7 +224,7 @@
|
|
|
222
224
|
{/if}
|
|
223
225
|
|
|
224
226
|
<div class="table-scroll">
|
|
225
|
-
<table class="table">
|
|
227
|
+
<table class="table" aria-label={caption}>
|
|
226
228
|
<thead class="table-head">
|
|
227
229
|
<tr>
|
|
228
230
|
{#if selectable}
|
|
@@ -81,6 +81,7 @@ declare const DataTable: import("svelte").Component<{
|
|
|
81
81
|
on_row_click?: any;
|
|
82
82
|
cell?: any;
|
|
83
83
|
children?: any;
|
|
84
|
+
caption?: any;
|
|
84
85
|
class?: string;
|
|
85
86
|
} & Record<string, any>, {}, "selected_rows">;
|
|
86
87
|
type $$ComponentProps = {
|
|
@@ -102,5 +103,6 @@ type $$ComponentProps = {
|
|
|
102
103
|
on_row_click?: any;
|
|
103
104
|
cell?: any;
|
|
104
105
|
children?: any;
|
|
106
|
+
caption?: any;
|
|
105
107
|
class?: string;
|
|
106
108
|
} & Record<string, any>;
|
package/components/EChart.svelte
CHANGED
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
palette is an alpha ramp off `--color-accent` — no hardcoded colour list.
|
|
27
27
|
Soft-empty: no series/category → renders nothing.
|
|
28
28
|
|
|
29
|
+
`band` shades a run of categories, inclusive (a stay inside a run of days).
|
|
30
|
+
The canvas draws it in `--chart-band-bg`; the table marks the same rows with
|
|
31
|
+
`data-band` and the band's label, so it is never encoded only in pixels.
|
|
32
|
+
|
|
29
33
|
@example
|
|
30
34
|
<EChart
|
|
31
35
|
caption="Reports by status"
|
|
@@ -38,18 +42,27 @@
|
|
|
38
42
|
legend
|
|
39
43
|
locale="pt"
|
|
40
44
|
/>
|
|
45
|
+
@example A band over a stay
|
|
46
|
+
<EChart
|
|
47
|
+
caption="Usual weather"
|
|
48
|
+
labelHeader="Day"
|
|
49
|
+
category={["1 Oct", "2 Oct", "3 Oct", "4 Oct"]}
|
|
50
|
+
series={[{ name: "High °C", type: "line", data: [24, 25, 23, 22] }]}
|
|
51
|
+
band={{ from: "2 Oct", to: "3 Oct", label: "Stay" }}
|
|
52
|
+
/>
|
|
41
53
|
-->
|
|
42
54
|
<script module>
|
|
43
55
|
/**
|
|
44
56
|
* @typedef {{ label: string, value: number }} ChartItem
|
|
45
57
|
* @typedef {import('./renderer/aggregate').ChartData} ChartData
|
|
46
58
|
* @typedef {import('./renderer/aggregate').SeriesData} SeriesData
|
|
59
|
+
* @typedef {import('./renderer/chart-option').ChartBand} ChartBand
|
|
47
60
|
*/
|
|
48
61
|
</script>
|
|
49
62
|
|
|
50
63
|
<script>
|
|
51
64
|
import { watchTheme } from "./map-utils.js";
|
|
52
|
-
import { buildChartOption } from "./renderer/chart-option";
|
|
65
|
+
import { bandRows, buildChartOption } from "./renderer/chart-option";
|
|
53
66
|
|
|
54
67
|
let {
|
|
55
68
|
/** @type {string[]} The category (x / pie-angle) ticks. */
|
|
@@ -64,6 +77,8 @@
|
|
|
64
77
|
ySecondary = false,
|
|
65
78
|
/** @type {number} Pie/donut hole as a fraction of the radius (0 = full pie). */
|
|
66
79
|
innerRadius = 0,
|
|
80
|
+
/** @type {ChartBand | undefined} Shade a run of categories, inclusive. */
|
|
81
|
+
band = undefined,
|
|
67
82
|
/** @type {ChartItem[]} BACK-COMPAT: single-series `{label,value}` rows. */
|
|
68
83
|
items = [],
|
|
69
84
|
/** @type {"bar" | "line" | "donut"} BACK-COMPAT: legacy single-series kind. */
|
|
@@ -109,6 +124,9 @@
|
|
|
109
124
|
});
|
|
110
125
|
|
|
111
126
|
// Legacy donut gets the ring hole even though the caller passes no innerRadius.
|
|
127
|
+
/** The table rows inside `band`, or null. */
|
|
128
|
+
const rows = $derived(bandRows(chartData.category, band));
|
|
129
|
+
|
|
112
130
|
const effInnerRadius = $derived(
|
|
113
131
|
series.length === 0 && kind === "donut" ? 0.45 : innerRadius,
|
|
114
132
|
);
|
|
@@ -149,12 +167,14 @@
|
|
|
149
167
|
textSecondary: token("--color-text-secondary", "#6b7280"),
|
|
150
168
|
border: token("--color-border", "#e5e7eb"),
|
|
151
169
|
surface: token("--color-surface", "#ffffff"),
|
|
170
|
+
band: token("--chart-band-bg", ""),
|
|
152
171
|
},
|
|
153
172
|
locale,
|
|
154
173
|
legend,
|
|
155
174
|
orientation: effOrientation,
|
|
156
175
|
ySecondary,
|
|
157
176
|
innerRadius: effInnerRadius,
|
|
177
|
+
band,
|
|
158
178
|
});
|
|
159
179
|
}
|
|
160
180
|
|
|
@@ -188,6 +208,7 @@
|
|
|
188
208
|
components.GridComponent,
|
|
189
209
|
components.TooltipComponent,
|
|
190
210
|
components.LegendComponent,
|
|
211
|
+
components.MarkAreaComponent,
|
|
191
212
|
renderers.CanvasRenderer,
|
|
192
213
|
// echarts 6 (#773): `grid.containLabel` moved behind this opt-in
|
|
193
214
|
// feature. Registering it preserves the v5 layout (labels contained
|
|
@@ -231,6 +252,7 @@
|
|
|
231
252
|
void effOrientation;
|
|
232
253
|
void ySecondary;
|
|
233
254
|
void effInnerRadius;
|
|
255
|
+
void band;
|
|
234
256
|
if (_chart) _chart.setOption(buildOption(), true);
|
|
235
257
|
});
|
|
236
258
|
</script>
|
|
@@ -260,8 +282,9 @@
|
|
|
260
282
|
</thead>
|
|
261
283
|
<tbody>
|
|
262
284
|
{#each chartData.category as cat, r (cat + r)}
|
|
263
|
-
|
|
264
|
-
|
|
285
|
+
{@const inBand = rows !== null && r >= rows[0] && r <= rows[1]}
|
|
286
|
+
<tr data-band={inBand ? "" : undefined}>
|
|
287
|
+
<th scope="row">{cat}{#if inBand && band?.label}{" "}<span class="echart-band-label">{band.label}</span>{/if}</th>
|
|
265
288
|
{#each chartData.series as s, si (si)}
|
|
266
289
|
<td>{fmt(s.data[r] ?? 0)}</td>
|
|
267
290
|
{/each}
|
|
@@ -302,6 +325,14 @@
|
|
|
302
325
|
font-weight: 600;
|
|
303
326
|
}
|
|
304
327
|
|
|
328
|
+
.echart-table tr[data-band] {
|
|
329
|
+
background: var(--chart-band-bg);
|
|
330
|
+
}
|
|
331
|
+
.echart-band-label {
|
|
332
|
+
margin-inline-start: var(--space-xs);
|
|
333
|
+
color: var(--color-text-secondary);
|
|
334
|
+
font-size: var(--type-label-size);
|
|
335
|
+
}
|
|
305
336
|
.echart-table tbody th {
|
|
306
337
|
font-weight: 400;
|
|
307
338
|
color: var(--color-text-primary);
|
|
@@ -5,6 +5,7 @@ export type ChartItem = {
|
|
|
5
5
|
};
|
|
6
6
|
export type ChartData = import("./renderer/aggregate").ChartData;
|
|
7
7
|
export type SeriesData = import("./renderer/aggregate").SeriesData;
|
|
8
|
+
export type ChartBand = import("./renderer/chart-option").ChartBand;
|
|
8
9
|
type EChart = {
|
|
9
10
|
$on?(type: string, callback: (e: any) => void): () => void;
|
|
10
11
|
$set?(props: Partial<$$ComponentProps>): void;
|
|
@@ -37,6 +38,10 @@ type EChart = {
|
|
|
37
38
|
* palette is an alpha ramp off `--color-accent` — no hardcoded colour list.
|
|
38
39
|
* Soft-empty: no series/category → renders nothing.
|
|
39
40
|
*
|
|
41
|
+
* `band` shades a run of categories, inclusive (a stay inside a run of days).
|
|
42
|
+
* The canvas draws it in `--chart-band-bg`; the table marks the same rows with
|
|
43
|
+
* `data-band` and the band's label, so it is never encoded only in pixels.
|
|
44
|
+
*
|
|
40
45
|
* @example
|
|
41
46
|
* <EChart
|
|
42
47
|
* caption="Reports by status"
|
|
@@ -49,6 +54,14 @@ type EChart = {
|
|
|
49
54
|
* legend
|
|
50
55
|
* locale="pt"
|
|
51
56
|
* />
|
|
57
|
+
* @example A band over a stay
|
|
58
|
+
* <EChart
|
|
59
|
+
* caption="Usual weather"
|
|
60
|
+
* labelHeader="Day"
|
|
61
|
+
* category={["1 Oct", "2 Oct", "3 Oct", "4 Oct"]}
|
|
62
|
+
* series={[{ name: "High °C", type: "line", data: [24, 25, 23, 22] }]}
|
|
63
|
+
* band={{ from: "2 Oct", to: "3 Oct", label: "Stay" }}
|
|
64
|
+
* />
|
|
52
65
|
*/
|
|
53
66
|
declare const EChart: import("svelte").Component<{
|
|
54
67
|
category?: any[];
|
|
@@ -57,6 +70,7 @@ declare const EChart: import("svelte").Component<{
|
|
|
57
70
|
orientation?: any;
|
|
58
71
|
ySecondary?: boolean;
|
|
59
72
|
innerRadius?: number;
|
|
73
|
+
band?: any;
|
|
60
74
|
items?: any[];
|
|
61
75
|
kind?: string;
|
|
62
76
|
caption?: string;
|
|
@@ -73,6 +87,7 @@ type $$ComponentProps = {
|
|
|
73
87
|
orientation?: any;
|
|
74
88
|
ySecondary?: boolean;
|
|
75
89
|
innerRadius?: number;
|
|
90
|
+
band?: any;
|
|
76
91
|
items?: any[];
|
|
77
92
|
kind?: string;
|
|
78
93
|
caption?: string;
|
|
@@ -29,6 +29,15 @@ export interface ChartTokens {
|
|
|
29
29
|
/** Panel surface behind floating chrome (tooltip); themes the default-white
|
|
30
30
|
ECharts tooltip for dark/high-contrast schemes (#89). */
|
|
31
31
|
surface: string;
|
|
32
|
+
/** Wash behind a `band` (`--chart-band-bg`); falls back to an accent wash. */
|
|
33
|
+
band?: string;
|
|
34
|
+
}
|
|
35
|
+
/** A run of categories to shade, inclusive at both ends (a stay inside a run
|
|
36
|
+
* of days). Ends that are not categories draw no band. */
|
|
37
|
+
export interface ChartBand {
|
|
38
|
+
from: string;
|
|
39
|
+
to: string;
|
|
40
|
+
label?: string;
|
|
32
41
|
}
|
|
33
42
|
export interface BuildChartOptionOpts {
|
|
34
43
|
tokens: ChartTokens;
|
|
@@ -42,6 +51,8 @@ export interface BuildChartOptionOpts {
|
|
|
42
51
|
ySecondary?: boolean;
|
|
43
52
|
/** Pie/donut hole as a fraction of the outer radius (0 = full pie). */
|
|
44
53
|
innerRadius?: number;
|
|
54
|
+
/** Shade a run of categories (cartesian charts only). */
|
|
55
|
+
band?: ChartBand;
|
|
45
56
|
}
|
|
46
57
|
/**
|
|
47
58
|
* Per-series / per-slice colour: an alpha ramp off the accent so N series stay
|
|
@@ -49,6 +60,8 @@ export interface BuildChartOptionOpts {
|
|
|
49
60
|
* it in the live colour space, so it re-themes with the tokens.
|
|
50
61
|
*/
|
|
51
62
|
export declare function seriesColor(accent: string, i: number): string;
|
|
63
|
+
/** Index range of a band's rows in the category order, or null. */
|
|
64
|
+
export declare function bandRows(category: ReadonlyArray<string>, band: ChartBand | undefined): [number, number] | null;
|
|
52
65
|
/**
|
|
53
66
|
* Build the ECharts `option` for a declarative chart. Pie (single-measure) and
|
|
54
67
|
* cartesian (bar/line/area/scatter, optionally stacked / dual-axis) are the two
|
|
@@ -31,6 +31,16 @@ export interface ChartTokens {
|
|
|
31
31
|
/** Panel surface behind floating chrome (tooltip); themes the default-white
|
|
32
32
|
ECharts tooltip for dark/high-contrast schemes (#89). */
|
|
33
33
|
surface: string;
|
|
34
|
+
/** Wash behind a `band` (`--chart-band-bg`); falls back to an accent wash. */
|
|
35
|
+
band?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A run of categories to shade, inclusive at both ends (a stay inside a run
|
|
39
|
+
* of days). Ends that are not categories draw no band. */
|
|
40
|
+
export interface ChartBand {
|
|
41
|
+
from: string;
|
|
42
|
+
to: string;
|
|
43
|
+
label?: string;
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
export interface BuildChartOptionOpts {
|
|
@@ -45,6 +55,8 @@ export interface BuildChartOptionOpts {
|
|
|
45
55
|
ySecondary?: boolean;
|
|
46
56
|
/** Pie/donut hole as a fraction of the outer radius (0 = full pie). */
|
|
47
57
|
innerRadius?: number;
|
|
58
|
+
/** Shade a run of categories (cartesian charts only). */
|
|
59
|
+
band?: ChartBand;
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
/** Token-driven tooltip chrome — ECharts defaults to a white panel that
|
|
@@ -169,6 +181,43 @@ function toEchartsSeries(
|
|
|
169
181
|
};
|
|
170
182
|
}
|
|
171
183
|
|
|
184
|
+
/** The ECharts markArea for a band, or null when its ends are not categories. */
|
|
185
|
+
function bandArea(
|
|
186
|
+
category: ReadonlyArray<string>,
|
|
187
|
+
opts: BuildChartOptionOpts,
|
|
188
|
+
): Record<string, unknown> | null {
|
|
189
|
+
const { band, tokens, orientation } = opts;
|
|
190
|
+
if (!band || !category.includes(band.from) || !category.includes(band.to)) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
const key = orientation === "horizontal" ? "yAxis" : "xAxis";
|
|
194
|
+
return {
|
|
195
|
+
silent: true,
|
|
196
|
+
itemStyle: {
|
|
197
|
+
color:
|
|
198
|
+
tokens.band ||
|
|
199
|
+
`color-mix(in srgb, ${tokens.accent} 16%, transparent)`,
|
|
200
|
+
},
|
|
201
|
+
label: {
|
|
202
|
+
show: Boolean(band.label),
|
|
203
|
+
position: "insideTop",
|
|
204
|
+
color: tokens.textSecondary,
|
|
205
|
+
},
|
|
206
|
+
data: [[{ name: band.label ?? "", [key]: band.from }, { [key]: band.to }]],
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Index range of a band's rows in the category order, or null. */
|
|
211
|
+
export function bandRows(
|
|
212
|
+
category: ReadonlyArray<string>,
|
|
213
|
+
band: ChartBand | undefined,
|
|
214
|
+
): [number, number] | null {
|
|
215
|
+
if (!band) return null;
|
|
216
|
+
const from = category.indexOf(band.from);
|
|
217
|
+
const to = category.indexOf(band.to);
|
|
218
|
+
return from < 0 || to < 0 ? null : [Math.min(from, to), Math.max(from, to)];
|
|
219
|
+
}
|
|
220
|
+
|
|
172
221
|
function buildCartesianOption(
|
|
173
222
|
data: ChartData,
|
|
174
223
|
opts: BuildChartOptionOpts,
|
|
@@ -211,6 +260,8 @@ function buildCartesianOption(
|
|
|
211
260
|
: [valueAxis(false)];
|
|
212
261
|
|
|
213
262
|
const echSeries = series.map((s, i) => toEchartsSeries(s, i, opts));
|
|
263
|
+
const area = bandArea(category, opts);
|
|
264
|
+
if (area && echSeries[0]) echSeries[0].markArea = area;
|
|
214
265
|
|
|
215
266
|
return {
|
|
216
267
|
animation: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiaiai-pt/design-system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.0",
|
|
4
4
|
"description": "Design system tokens and Svelte components for aiaiai products",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -91,7 +91,50 @@
|
|
|
91
91
|
"ol": "^10.0.0",
|
|
92
92
|
"svelte": "^5.0.0"
|
|
93
93
|
},
|
|
94
|
+
"peerDependenciesMeta": {
|
|
95
|
+
"@codemirror/commands": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"@codemirror/lang-json": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"@codemirror/lang-python": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"@codemirror/lang-sql": {
|
|
105
|
+
"optional": true
|
|
106
|
+
},
|
|
107
|
+
"@codemirror/language": {
|
|
108
|
+
"optional": true
|
|
109
|
+
},
|
|
110
|
+
"@codemirror/state": {
|
|
111
|
+
"optional": true
|
|
112
|
+
},
|
|
113
|
+
"@codemirror/view": {
|
|
114
|
+
"optional": true
|
|
115
|
+
},
|
|
116
|
+
"@lezer/highlight": {
|
|
117
|
+
"optional": true
|
|
118
|
+
},
|
|
119
|
+
"date-fns": {
|
|
120
|
+
"optional": true
|
|
121
|
+
},
|
|
122
|
+
"echarts": {
|
|
123
|
+
"optional": true
|
|
124
|
+
},
|
|
125
|
+
"ol": {
|
|
126
|
+
"optional": true
|
|
127
|
+
}
|
|
128
|
+
},
|
|
94
129
|
"devDependencies": {
|
|
130
|
+
"@codemirror/commands": "^6.10.3",
|
|
131
|
+
"@codemirror/lang-json": "^6.0.2",
|
|
132
|
+
"@codemirror/lang-python": "^6.2.1",
|
|
133
|
+
"@codemirror/lang-sql": "^6.10.0",
|
|
134
|
+
"@codemirror/language": "^6.12.2",
|
|
135
|
+
"@codemirror/state": "^6.6.0",
|
|
136
|
+
"@codemirror/view": "^6.40.0",
|
|
137
|
+
"@lezer/highlight": "^1.0.0",
|
|
95
138
|
"@sveltejs/package": "^2.5.7",
|
|
96
139
|
"date-fns": "^4.1.0",
|
|
97
140
|
"echarts": "^6.1.0",
|
package/tokens/components.css
CHANGED
|
@@ -879,6 +879,10 @@
|
|
|
879
879
|
routes carry the colour. Redefined for the dark scheme below. */
|
|
880
880
|
--map-tiles-muted-filter: grayscale(1) contrast(0.7) brightness(1.08);
|
|
881
881
|
|
|
882
|
+
/* ── Chart ───────────────────────────────────── */
|
|
883
|
+
/* The wash behind an EChart `band` (a stay inside a run of days), on the canvas and on its table rows. */
|
|
884
|
+
--chart-band-bg: var(--color-accent-subtle);
|
|
885
|
+
|
|
882
886
|
/* Cluster */
|
|
883
887
|
--map-cluster-radius: var(--space-md);
|
|
884
888
|
--map-cluster-fill: var(--color-accent);
|