@aiaiai-pt/design-system 0.53.0 → 0.55.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.
@@ -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>;
@@ -26,6 +26,15 @@
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
+
33
+ A series with `tone: "muted"` draws in the secondary text colour, behind the
34
+ accent series, and leaves the accent ramp to the others. `yCeiling` and
35
+ `ySecondaryCeiling` make an axis reach at least that value (larger data still
36
+ extends it), so small values look small: 3 mm of rain on a 20 mm scale.
37
+
29
38
  @example
30
39
  <EChart
31
40
  caption="Reports by status"
@@ -38,18 +47,40 @@
38
47
  legend
39
48
  locale="pt"
40
49
  />
50
+ @example A band over a stay
51
+ <EChart
52
+ caption="Usual weather"
53
+ labelHeader="Day"
54
+ category={["1 Oct", "2 Oct", "3 Oct", "4 Oct"]}
55
+ series={[{ name: "High °C", type: "line", data: [24, 25, 23, 22] }]}
56
+ band={{ from: "2 Oct", to: "3 Oct", label: "Stay" }}
57
+ />
58
+ @example Quiet rain bars under temperature lines
59
+ <EChart
60
+ caption="Usual weather"
61
+ labelHeader="Day"
62
+ category={["1 Oct", "2 Oct", "3 Oct"]}
63
+ series={[
64
+ { name: "High °C", type: "line", data: [24, 25, 23] },
65
+ { name: "Rain mm", type: "bar", axis: "secondary", tone: "muted", data: [1, 9, 2] },
66
+ ]}
67
+ ySecondary
68
+ ySecondaryCeiling={20}
69
+ legend
70
+ />
41
71
  -->
42
72
  <script module>
43
73
  /**
44
74
  * @typedef {{ label: string, value: number }} ChartItem
45
75
  * @typedef {import('./renderer/aggregate').ChartData} ChartData
46
76
  * @typedef {import('./renderer/aggregate').SeriesData} SeriesData
77
+ * @typedef {import('./renderer/chart-option').ChartBand} ChartBand
47
78
  */
48
79
  </script>
49
80
 
50
81
  <script>
51
82
  import { watchTheme } from "./map-utils.js";
52
- import { buildChartOption } from "./renderer/chart-option";
83
+ import { bandRows, buildChartOption } from "./renderer/chart-option";
53
84
 
54
85
  let {
55
86
  /** @type {string[]} The category (x / pie-angle) ticks. */
@@ -64,6 +95,12 @@
64
95
  ySecondary = false,
65
96
  /** @type {number} Pie/donut hole as a fraction of the radius (0 = full pie). */
66
97
  innerRadius = 0,
98
+ /** @type {ChartBand | undefined} Shade a run of categories, inclusive. */
99
+ band = undefined,
100
+ /** @type {number | undefined} The primary axis reaches at least this value. */
101
+ yCeiling = undefined,
102
+ /** @type {number | undefined} The secondary axis reaches at least this value. */
103
+ ySecondaryCeiling = undefined,
67
104
  /** @type {ChartItem[]} BACK-COMPAT: single-series `{label,value}` rows. */
68
105
  items = [],
69
106
  /** @type {"bar" | "line" | "donut"} BACK-COMPAT: legacy single-series kind. */
@@ -109,6 +146,9 @@
109
146
  });
110
147
 
111
148
  // Legacy donut gets the ring hole even though the caller passes no innerRadius.
149
+ /** The table rows inside `band`, or null. */
150
+ const rows = $derived(bandRows(chartData.category, band));
151
+
112
152
  const effInnerRadius = $derived(
113
153
  series.length === 0 && kind === "donut" ? 0.45 : innerRadius,
114
154
  );
@@ -149,12 +189,16 @@
149
189
  textSecondary: token("--color-text-secondary", "#6b7280"),
150
190
  border: token("--color-border", "#e5e7eb"),
151
191
  surface: token("--color-surface", "#ffffff"),
192
+ band: token("--chart-band-bg", ""),
152
193
  },
153
194
  locale,
154
195
  legend,
155
196
  orientation: effOrientation,
156
197
  ySecondary,
157
198
  innerRadius: effInnerRadius,
199
+ band,
200
+ yCeiling,
201
+ ySecondaryCeiling,
158
202
  });
159
203
  }
160
204
 
@@ -188,6 +232,7 @@
188
232
  components.GridComponent,
189
233
  components.TooltipComponent,
190
234
  components.LegendComponent,
235
+ components.MarkAreaComponent,
191
236
  renderers.CanvasRenderer,
192
237
  // echarts 6 (#773): `grid.containLabel` moved behind this opt-in
193
238
  // feature. Registering it preserves the v5 layout (labels contained
@@ -231,6 +276,9 @@
231
276
  void effOrientation;
232
277
  void ySecondary;
233
278
  void effInnerRadius;
279
+ void band;
280
+ void yCeiling;
281
+ void ySecondaryCeiling;
234
282
  if (_chart) _chart.setOption(buildOption(), true);
235
283
  });
236
284
  </script>
@@ -260,8 +308,9 @@
260
308
  </thead>
261
309
  <tbody>
262
310
  {#each chartData.category as cat, r (cat + r)}
263
- <tr>
264
- <th scope="row">{cat}</th>
311
+ {@const inBand = rows !== null && r >= rows[0] && r <= rows[1]}
312
+ <tr data-band={inBand ? "" : undefined}>
313
+ <th scope="row">{cat}{#if inBand && band?.label}{" "}<span class="echart-band-label">{band.label}</span>{/if}</th>
265
314
  {#each chartData.series as s, si (si)}
266
315
  <td>{fmt(s.data[r] ?? 0)}</td>
267
316
  {/each}
@@ -302,6 +351,14 @@
302
351
  font-weight: 600;
303
352
  }
304
353
 
354
+ .echart-table tr[data-band] {
355
+ background: var(--chart-band-bg);
356
+ }
357
+ .echart-band-label {
358
+ margin-inline-start: var(--space-xs);
359
+ color: var(--color-text-secondary);
360
+ font-size: var(--type-label-size);
361
+ }
305
362
  .echart-table tbody th {
306
363
  font-weight: 400;
307
364
  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,15 @@ 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
+ *
45
+ * A series with `tone: "muted"` draws in the secondary text colour, behind the
46
+ * accent series, and leaves the accent ramp to the others. `yCeiling` and
47
+ * `ySecondaryCeiling` make an axis reach at least that value (larger data still
48
+ * extends it), so small values look small: 3 mm of rain on a 20 mm scale.
49
+ *
40
50
  * @example
41
51
  * <EChart
42
52
  * caption="Reports by status"
@@ -49,6 +59,27 @@ type EChart = {
49
59
  * legend
50
60
  * locale="pt"
51
61
  * />
62
+ * @example A band over a stay
63
+ * <EChart
64
+ * caption="Usual weather"
65
+ * labelHeader="Day"
66
+ * category={["1 Oct", "2 Oct", "3 Oct", "4 Oct"]}
67
+ * series={[{ name: "High °C", type: "line", data: [24, 25, 23, 22] }]}
68
+ * band={{ from: "2 Oct", to: "3 Oct", label: "Stay" }}
69
+ * />
70
+ * @example Quiet rain bars under temperature lines
71
+ * <EChart
72
+ * caption="Usual weather"
73
+ * labelHeader="Day"
74
+ * category={["1 Oct", "2 Oct", "3 Oct"]}
75
+ * series={[
76
+ * { name: "High °C", type: "line", data: [24, 25, 23] },
77
+ * { name: "Rain mm", type: "bar", axis: "secondary", tone: "muted", data: [1, 9, 2] },
78
+ * ]}
79
+ * ySecondary
80
+ * ySecondaryCeiling={20}
81
+ * legend
82
+ * />
52
83
  */
53
84
  declare const EChart: import("svelte").Component<{
54
85
  category?: any[];
@@ -57,6 +88,9 @@ declare const EChart: import("svelte").Component<{
57
88
  orientation?: any;
58
89
  ySecondary?: boolean;
59
90
  innerRadius?: number;
91
+ band?: any;
92
+ yCeiling?: any;
93
+ ySecondaryCeiling?: any;
60
94
  items?: any[];
61
95
  kind?: string;
62
96
  caption?: string;
@@ -73,6 +107,9 @@ type $$ComponentProps = {
73
107
  orientation?: any;
74
108
  ySecondary?: boolean;
75
109
  innerRadius?: number;
110
+ band?: any;
111
+ yCeiling?: any;
112
+ ySecondaryCeiling?: any;
76
113
  items?: any[];
77
114
  kind?: string;
78
115
  caption?: string;
@@ -81,6 +81,9 @@ export interface SeriesData {
81
81
  data: number[];
82
82
  stack?: string;
83
83
  axis?: "primary" | "secondary";
84
+ /** `muted` draws the series in the secondary text colour, behind the accent
85
+ * series (rain bars under temperature lines). Default `accent`. */
86
+ tone?: "accent" | "muted";
84
87
  }
85
88
  /** The shape `EChart` / `ResultsChart` render: aligned category + series. */
86
89
  export interface ChartData {
@@ -147,6 +147,9 @@ export interface SeriesData {
147
147
  data: number[];
148
148
  stack?: string;
149
149
  axis?: "primary" | "secondary";
150
+ /** `muted` draws the series in the secondary text colour, behind the accent
151
+ * series (rain bars under temperature lines). Default `accent`. */
152
+ tone?: "accent" | "muted";
150
153
  }
151
154
 
152
155
  /** The shape `EChart` / `ResultsChart` render: aligned category + series. */
@@ -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,13 @@ 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;
56
+ /** The primary value axis reaches at least this value; larger data extends it.
57
+ * Keeps small values looking small (3 mm of rain on a 20 mm scale). */
58
+ yCeiling?: number;
59
+ /** The same, for the secondary value axis. */
60
+ ySecondaryCeiling?: number;
45
61
  }
46
62
  /**
47
63
  * Per-series / per-slice colour: an alpha ramp off the accent so N series stay
@@ -49,6 +65,10 @@ export interface BuildChartOptionOpts {
49
65
  * it in the live colour space, so it re-themes with the tokens.
50
66
  */
51
67
  export declare function seriesColor(accent: string, i: number): string;
68
+ /** A muted series: the secondary text colour, light enough to sit behind the accent. */
69
+ export declare function mutedColor(textSecondary: string): string;
70
+ /** Index range of a band's rows in the category order, or null. */
71
+ export declare function bandRows(category: ReadonlyArray<string>, band: ChartBand | undefined): [number, number] | null;
52
72
  /**
53
73
  * Build the ECharts `option` for a declarative chart. Pie (single-measure) and
54
74
  * 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,13 @@ 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;
60
+ /** The primary value axis reaches at least this value; larger data extends it.
61
+ * Keeps small values looking small (3 mm of rain on a 20 mm scale). */
62
+ yCeiling?: number;
63
+ /** The same, for the secondary value axis. */
64
+ ySecondaryCeiling?: number;
48
65
  }
49
66
 
50
67
  /** Token-driven tooltip chrome — ECharts defaults to a white panel that
@@ -97,7 +114,13 @@ function buildPieOption(
97
114
  `${p.name}: ${fmt(p.value)} (${p.percent}%)`,
98
115
  },
99
116
  ...(opts.legend
100
- ? { legend: { show: true, top: 0, textStyle: { color: tokens.textPrimary } } }
117
+ ? {
118
+ legend: {
119
+ show: true,
120
+ top: 0,
121
+ textStyle: { color: tokens.textPrimary },
122
+ },
123
+ }
101
124
  : {}),
102
125
  color: palette,
103
126
  series: [
@@ -115,7 +138,12 @@ function buildPieOption(
115
138
  };
116
139
  }
117
140
 
118
- /** Map one shaped series → its ECharts series object. */
141
+ /** A muted series: the secondary text colour, light enough to sit behind the accent. */
142
+ export function mutedColor(textSecondary: string): string {
143
+ return `color-mix(in srgb, ${textSecondary} 35%, transparent)`;
144
+ }
145
+
146
+ /** Map one shaped series → its ECharts series object. `i` counts accent series only. */
119
147
  function toEchartsSeries(
120
148
  s: SeriesData,
121
149
  i: number,
@@ -123,7 +151,10 @@ function toEchartsSeries(
123
151
  ): Record<string, unknown> {
124
152
  const { tokens, orientation, ySecondary } = opts;
125
153
  const horizontal = orientation === "horizontal";
126
- const color = seriesColor(tokens.accent, i);
154
+ const color =
155
+ s.tone === "muted"
156
+ ? mutedColor(tokens.textSecondary)
157
+ : seriesColor(tokens.accent, i);
127
158
  // The value dimension is y for vertical charts, x for horizontal.
128
159
  const axisKey = horizontal ? "xAxisIndex" : "yAxisIndex";
129
160
  const axisIndex = s.axis === "secondary" && ySecondary ? 1 : 0;
@@ -169,6 +200,42 @@ function toEchartsSeries(
169
200
  };
170
201
  }
171
202
 
203
+ /** The ECharts markArea for a band, or null when its ends are not categories. */
204
+ function bandArea(
205
+ category: ReadonlyArray<string>,
206
+ opts: BuildChartOptionOpts,
207
+ ): Record<string, unknown> | null {
208
+ const { band, tokens, orientation } = opts;
209
+ if (!band || !category.includes(band.from) || !category.includes(band.to)) {
210
+ return null;
211
+ }
212
+ const key = orientation === "horizontal" ? "yAxis" : "xAxis";
213
+ return {
214
+ silent: true,
215
+ itemStyle: {
216
+ color:
217
+ tokens.band || `color-mix(in srgb, ${tokens.accent} 16%, transparent)`,
218
+ },
219
+ label: {
220
+ show: Boolean(band.label),
221
+ position: "insideTop",
222
+ color: tokens.textSecondary,
223
+ },
224
+ data: [[{ name: band.label ?? "", [key]: band.from }, { [key]: band.to }]],
225
+ };
226
+ }
227
+
228
+ /** Index range of a band's rows in the category order, or null. */
229
+ export function bandRows(
230
+ category: ReadonlyArray<string>,
231
+ band: ChartBand | undefined,
232
+ ): [number, number] | null {
233
+ if (!band) return null;
234
+ const from = category.indexOf(band.from);
235
+ const to = category.indexOf(band.to);
236
+ return from < 0 || to < 0 ? null : [Math.min(from, to), Math.max(from, to)];
237
+ }
238
+
172
239
  function buildCartesianOption(
173
240
  data: ChartData,
174
241
  opts: BuildChartOptionOpts,
@@ -195,22 +262,34 @@ function buildCartesianOption(
195
262
  axisTick: { show: false },
196
263
  };
197
264
 
198
- const valueAxis = (secondary: boolean) => ({
199
- type: "value" as const,
200
- axisLabel: {
201
- color: tokens.textSecondary,
202
- formatter: (v: number) => fmt(v),
203
- },
204
- axisLine: { lineStyle: { color: tokens.border } },
205
- // Hide the 2nd axis' grid lines to avoid a double grid.
206
- splitLine: { show: !secondary, lineStyle: { color: tokens.border } },
207
- });
265
+ const valueAxis = (secondary: boolean) => {
266
+ const ceiling = secondary ? opts.ySecondaryCeiling : opts.yCeiling;
267
+ return {
268
+ type: "value" as const,
269
+ ...(ceiling === undefined
270
+ ? {}
271
+ : { max: (extent: { max: number }) => Math.max(extent.max, ceiling) }),
272
+ axisLabel: {
273
+ color: tokens.textSecondary,
274
+ formatter: (v: number) => fmt(v),
275
+ },
276
+ axisLine: { lineStyle: { color: tokens.border } },
277
+ // Hide the 2nd axis' grid lines to avoid a double grid.
278
+ splitLine: { show: !secondary, lineStyle: { color: tokens.border } },
279
+ };
280
+ };
208
281
 
209
282
  const valueAxes = ySecondary
210
283
  ? [valueAxis(false), valueAxis(true)]
211
284
  : [valueAxis(false)];
212
285
 
213
- const echSeries = series.map((s, i) => toEchartsSeries(s, i, opts));
286
+ // The accent ramp counts accent series only, so a muted one does not fade the rest.
287
+ let accentIndex = 0;
288
+ const echSeries = series.map((s) =>
289
+ toEchartsSeries(s, s.tone === "muted" ? 0 : accentIndex++, opts),
290
+ );
291
+ const area = bandArea(category, opts);
292
+ if (area && echSeries[0]) echSeries[0].markArea = area;
214
293
 
215
294
  return {
216
295
  animation: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiaiai-pt/design-system",
3
- "version": "0.53.0",
3
+ "version": "0.55.0",
4
4
  "description": "Design system tokens and Svelte components for aiaiai products",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -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);