@aeriz/chart 1.1.0 → 2.0.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.
Files changed (45) hide show
  1. package/README.md +60 -34
  2. package/dist/aeriz.cjs +609 -354
  3. package/dist/aeriz.esm.js +578 -331
  4. package/dist/aeriz.esm.min.js +119 -105
  5. package/dist/aeriz.js +609 -354
  6. package/dist/aeriz.min.cjs +123 -107
  7. package/dist/aeriz.min.js +123 -107
  8. package/dist/esm/base.js +33 -22
  9. package/dist/esm/cartesian.js +7 -5
  10. package/dist/esm/charts/area.js +6 -6
  11. package/dist/esm/charts/bar.js +3 -3
  12. package/dist/esm/charts/boxplot.js +3 -3
  13. package/dist/esm/charts/bubble.js +3 -3
  14. package/dist/esm/charts/composite.js +8 -8
  15. package/dist/esm/charts/funnel.js +3 -3
  16. package/dist/esm/charts/gauge.js +5 -5
  17. package/dist/esm/charts/grouped-bar.js +4 -4
  18. package/dist/esm/charts/hbar.js +5 -5
  19. package/dist/esm/charts/heatmap.js +6 -6
  20. package/dist/esm/charts/line.js +6 -6
  21. package/dist/esm/charts/multi-line.js +5 -5
  22. package/dist/esm/charts/pie.js +6 -6
  23. package/dist/esm/charts/polar.js +3 -3
  24. package/dist/esm/charts/radar.js +6 -6
  25. package/dist/esm/charts/realtime.js +11 -9
  26. package/dist/esm/charts/scatter.js +4 -4
  27. package/dist/esm/charts/sparkline.js +4 -4
  28. package/dist/esm/charts/stacked-bar.js +5 -5
  29. package/dist/esm/charts/treemap.js +4 -4
  30. package/dist/esm/charts/waterfall.js +4 -4
  31. package/dist/esm/engine.js +1 -1
  32. package/dist/esm/index.js +2 -2
  33. package/dist/esm/jquery.js +5 -4
  34. package/dist/esm/math.js +1 -1
  35. package/dist/esm/react.js +4 -4
  36. package/dist/esm/shallow.js +4 -2
  37. package/dist/esm/svelte.js +4 -4
  38. package/dist/esm/vue.js +4 -2
  39. package/dist/index.d.ts +228 -552
  40. package/dist/jquery.d.ts +19 -8
  41. package/dist/react.d.ts +55 -18
  42. package/dist/svelte.d.ts +53 -14
  43. package/dist/types/sparkline.d.ts +1 -1
  44. package/dist/vue.d.ts +60 -10
  45. package/package.json +2 -2
package/dist/index.d.ts CHANGED
@@ -1,647 +1,323 @@
1
1
  /**
2
- * @aeriz/chart — visualization, light as air.
2
+ * @aeriz/chart 2.0 — visualization, light as air.
3
3
  *
4
- * 21 canvas chart types, one module each (import only what you use),
5
- * zero dependencies. Framework adapters: `@aeriz/chart/react`, `/vue`,
6
- * `/svelte`, `/jquery`.
4
+ * 21 canvas chart types with one way to do each thing:
5
+ * `new XChart(target, options)` → `update(patch)` · `setState(state)` · `render()` · `destroy()`.
6
+ * Every chart takes its data as `data`. Framework adapters: `@aeriz/chart/react`,
7
+ * `/vue`, `/svelte`, `/jquery`.
7
8
  *
8
9
  * @packageDocumentation
9
10
  */
10
11
 
11
- // ──────────────────────────────────────────────────────────────────
12
- // Common types
13
- // ──────────────────────────────────────────────────────────────────
12
+ // ─── Shared types ────────────────────────────────────────────────
14
13
 
15
14
  /** A CSS selector or a DOM element to mount the chart into. */
16
- export type ChartContainer = string | HTMLElement;
15
+ export type Target = string | HTMLElement;
17
16
 
18
- /** Color value — anything CSS accepts. */
17
+ /** Any CSS color. */
19
18
  export type Color = string;
20
19
 
21
- /** Tick formatter used on numeric axes. Receives the raw tick value. */
22
- export type TickFormatter = (value: number) => string;
23
-
24
- /** Categorical tick formatter — receives the raw category label. */
25
- export type CategoryTickFormatter = (label: string, index: number) => string;
26
-
27
- /** Axis scale type. `time` interprets numeric values as ms since epoch. */
28
- export type ScaleType = 'linear' | 'log' | 'time';
29
-
30
- /** Click handler signature shared by all chart types. */
31
- export type ClickHandler<H = unknown> = (
32
- hit: H | null,
33
- point: { x: number; y: number },
34
- chart: Chart<any>,
35
- ) => void;
36
-
37
- /**
38
- * Label/value data in any of these shapes:
39
- * `[{ label, value }]` · `[3, 7, 4]` · `{ Jan: 3, Feb: 7 }` · `[['Jan', 3], ['Feb', 7]]`
40
- */
41
- export type Rows<T> = T[] | number[] | Record<string, number> | Array<[string, number]>;
42
-
43
20
  /**
44
- * Number format for tooltips and value axes: a function, or
45
- * `Intl.NumberFormat` options such as `{ style: 'currency', currency: 'KRW' }`.
21
+ * Number format for tooltips and the value axis: `Intl.NumberFormat` options
22
+ * such as `{ style: 'currency', currency: 'KRW' }`, or a function.
23
+ * Without it, numbers follow the browser locale.
46
24
  */
47
- export type NumberFormat = ((value: number) => string) | Intl.NumberFormatOptions;
48
-
49
- /** What `onClick` receives — the hovered element, or `null`. */
50
- export interface Hit {
51
- /** Index of the data row / category. */
52
- index?: number;
53
- /** Series index (multi-series charts). */
54
- series?: number;
25
+ export type NumberFormat = Intl.NumberFormatOptions | ((value: number) => string);
26
+
27
+ /** Formats category / time labels on the x axis and in tooltips. Time labels are ms timestamps. */
28
+ export type LabelFormat = (label: any) => string;
29
+
30
+ /** What `onClick` receives: the clicked item. */
31
+ export interface Hit<Row = unknown> {
32
+ /** Index of the row / category (heatmap: column). */
33
+ index: number;
34
+ /** Its label (category, row label, or point label). */
35
+ label: any;
36
+ /** Its value, when the item has one. */
55
37
  value?: number;
56
- /** The original data row, when there is one. */
57
- data?: unknown;
58
- tooltip?: string | { title?: string; rows: Array<{ name?: string; value?: string; color?: Color }> };
38
+ /** Series index in multi-series charts (heatmap: row). */
39
+ series?: number;
40
+ /** The original data item: your row, point or series object. */
41
+ row?: Row;
59
42
  }
60
43
 
61
- /** A single named series of numeric values, used by category-axis charts. */
62
- export interface Series {
63
- name: string;
64
- values: number[];
65
- color?: Color;
66
- hidden?: boolean;
44
+ /** `chart.setState()` overlays. `null` removes the overlay. */
45
+ export type State = 'loading' | 'empty' | 'error' | null;
46
+
47
+ /** Options every chart takes. */
48
+ export interface CommonOptions<D, Row = unknown> {
49
+ /** The data. Its shape depends on the chart — see each chart's `data`. */
50
+ data?: D;
51
+ /** Accessible name for screen readers (gauge also shows it as a caption). */
52
+ title?: string;
53
+ /** Series / item colors, in order. Defaults to `--aeriz-color-1…12`, then the built-in palette. */
54
+ colors?: Color[];
55
+ /** Number format for tooltips and the value axis. */
56
+ format?: NumberFormat;
57
+ /** Show the legend (multi-series charts and pie). Default `true`. */
58
+ legend?: boolean;
59
+ /** Animate drawing and updates. Default `true` (off with prefers-reduced-motion). */
60
+ animate?: boolean;
61
+ /** Text shown when there is no data. Default `'No data'`. */
62
+ emptyText?: string;
63
+ /** Called when an item is clicked (or Enter is pressed on it). */
64
+ onClick?: (hit: Hit<Row>, chart: Chart) => void;
65
+ /** Called when a legend item is toggled. */
66
+ onLegend?: (index: number, visible: boolean, chart: Chart) => void;
67
67
  }
68
68
 
69
- /** A single radar-axis series — same shape as a regular Series. */
70
- export type RadarSeries = Series;
69
+ /** Value axis range (charts with axes). */
70
+ export interface AxisOptions {
71
+ /** Formats x-axis labels and tooltip titles. */
72
+ labelFormat?: LabelFormat;
73
+ /** Lowest value on the value axis (default: from the data, starting at 0). */
74
+ min?: number;
75
+ /** Highest value on the value axis (default: from the data). */
76
+ max?: number;
77
+ }
71
78
 
72
- // ──────────────────────────────────────────────────────────────────
73
- // Per-chart datum shapes
74
- // ──────────────────────────────────────────────────────────────────
79
+ // ─── Data shapes ─────────────────────────────────────────────────
75
80
 
76
- export interface BarDatum {
77
- label: string;
81
+ /** A `{ label, value }` row. Extra fields are allowed (use `label` / `value` accessors to read others). */
82
+ export interface Row {
83
+ label: string | number;
78
84
  value: number;
85
+ /** Per-item color. */
79
86
  color?: Color;
80
87
  }
81
88
 
82
- export interface ScatterDatum {
83
- x: number;
84
- y: number;
85
- group?: number | string;
86
- color?: Color;
87
- }
89
+ /**
90
+ * Single-series data, three ways that mean the same:
91
+ * `[64, 42, 78]` · `{ Jan: 64, Feb: 42 }` · `[{ label: 'Jan', value: 64 }]`
92
+ * (or your own objects with `label` / `value` accessors).
93
+ */
94
+ export type Rows<R = Row> = number[] | Float64Array | Float32Array | Record<string, number> | R[];
88
95
 
89
- export interface BubbleDatum extends ScatterDatum {
90
- z: number;
96
+ /** Single-series options: read other fields with accessors. */
97
+ export interface RowOptions<R> {
98
+ /** Reads a row's label, e.g. `(row) => row.month`. */
99
+ label?: (row: R, index: number) => string | number;
100
+ /** Reads a row's value, e.g. `(row) => row.sales`. */
101
+ value?: (row: R, index: number) => number;
91
102
  }
92
103
 
93
- export interface PieDatum {
94
- label: string;
95
- value: number;
104
+ export interface Series {
105
+ name: string;
106
+ values: ArrayLike<number | null>;
96
107
  color?: Color;
97
108
  }
98
109
 
99
- export interface PolarDatum {
100
- label: string;
101
- value: number;
102
- color?: Color;
110
+ /** Multi-series data. Every series has one value per category. */
111
+ export interface SeriesData<S extends Series = Series> {
112
+ categories: ArrayLike<string | number>;
113
+ series: S[];
103
114
  }
104
115
 
105
- export interface HeatmapDatum {
116
+ export interface Point {
106
117
  x: number;
107
118
  y: number;
108
- value: number;
119
+ /** Scatter: radius in px. Bubble: a value, drawn as the bubble's area. */
120
+ size?: number;
121
+ /** Colors points by series index. */
122
+ group?: number;
123
+ label?: string;
124
+ color?: Color;
109
125
  }
110
126
 
111
- export interface BoxplotDatum {
112
- label: string;
113
- min: number;
114
- q1: number;
115
- median: number;
116
- q3: number;
117
- max: number;
118
- outliers?: number[];
119
- }
127
+ // ─── Base class ──────────────────────────────────────────────────
120
128
 
121
- export interface FunnelDatum {
122
- label: string;
123
- value: number;
124
- color?: Color;
129
+ export interface ChartMeta {
130
+ id: string;
131
+ name: string;
132
+ aria: string;
133
+ data: 'rows' | 'series' | 'stream' | 'points' | 'matrix' | 'boxes' | 'steps' | 'number';
134
+ options: string[];
125
135
  }
126
136
 
127
- export interface TreemapDatum {
128
- label: string;
129
- value: number;
130
- color?: Color;
137
+ export declare class Chart<O = CommonOptions<unknown>> {
138
+ constructor(target: Target, options?: O);
139
+ static readonly meta: ChartMeta | null;
140
+ readonly container: HTMLElement;
141
+ readonly canvas: HTMLCanvasElement;
142
+ readonly options: O;
143
+ /** Change any options, data included. Changed values animate in. */
144
+ update(patch: Partial<O>): this;
145
+ /** Show a loading / empty / error overlay (with optional text), or remove it with `null`. */
146
+ setState(state: State, text?: string): this;
147
+ /** Re-read CSS variables and draw the final frame now — also off-screen (print, export). */
148
+ render(): this;
149
+ /** Remove the chart and undo every change to the container. */
150
+ destroy(): void;
131
151
  }
132
152
 
133
- export interface WaterfallDatum {
134
- label: string;
135
- value: number;
136
- /** Anchor bar — drawn at absolute height instead of as a delta. */
137
- isTotal?: boolean;
138
- color?: Color;
139
- }
153
+ /** The default color palette. */
154
+ export declare const PALETTE: readonly Color[];
140
155
 
141
- /** A layer in a `CompositeChart`. */
142
- export type CompositeLayer =
143
- | {
144
- type: 'bar' | 'line' | 'area';
145
- name: string;
146
- values: number[];
147
- color?: Color;
148
- /** Which y-axis the layer maps to. Default `'left'`. */
149
- axis?: 'left' | 'right';
150
- }
151
- | {
152
- type: 'scatter';
153
- name: string;
154
- values: Array<{ x: number; y: number }>;
155
- color?: Color;
156
- axis?: 'left' | 'right';
157
- };
158
-
159
- // ──────────────────────────────────────────────────────────────────
160
- // Per-chart option types
161
- // ──────────────────────────────────────────────────────────────────
162
-
163
- /** Options shared by every chart. */
164
- export interface BaseChartOptions {
165
- /** Override the auto-resolved palette. */
166
- palette?: Color[];
167
- /** Show value labels on bars (BarChart). A function formats each label. */
168
- dataLabels?: boolean | ((datum: any, index: number) => string);
169
- /** Click handler — `hit` is the element under the pointer, or `null`. Enter key also fires it. */
170
- onClick?: ClickHandler<Hit>;
171
- /** Number format for tooltips and value axes (axes switch to compact 12K / 3.4M above 10,000). */
172
- format?: NumberFormat;
173
- /** `false` hides the legend on multi-series charts. */
174
- legend?: boolean;
175
- /** Called when a legend item is toggled. */
176
- onLegend?: (index: number, visible: boolean, chart: Chart<any>) => void;
177
- /** `false` draws without the entry/update animation. Reduced-motion users never get one. */
178
- animate?: boolean;
179
- /** Accessible name for the chart canvas (defaults to `title`, then the chart type). */
180
- ariaLabel?: string;
181
- title?: string;
182
- /** Text of the automatic empty state. Default `'No data'`. */
183
- emptyText?: string;
184
- }
156
+ // ─── Charts ──────────────────────────────────────────────────────
185
157
 
186
- export interface BarChartOptions extends BaseChartOptions {
187
- data: Rows<BarDatum>;
188
- /** Read the label from a custom row shape. */
189
- label?: (d: any, i: number) => string | number;
190
- /** Read the value from a custom row shape. */
191
- value?: (d: any, i: number) => number;
192
- /** One color for every bar / the line (instead of the palette). */
193
- color?: Color;
194
- yTickFormat?: TickFormatter;
195
- xTickFormat?: CategoryTickFormatter;
196
- }
158
+ type Curve = 'smooth' | 'linear' | 'step';
197
159
 
198
- export interface HBarChartOptions extends BaseChartOptions {
199
- data: Rows<BarDatum>;
200
- /** Read the label from a custom row shape. */
201
- label?: (d: any, i: number) => string | number;
202
- /** Read the value from a custom row shape. */
203
- value?: (d: any, i: number) => number;
204
- /** One color for every bar / the line (instead of the palette). */
205
- color?: Color;
206
- xTickFormat?: TickFormatter;
207
- yTickFormat?: CategoryTickFormatter;
160
+ export interface BarOptions<R = Row> extends CommonOptions<Rows<R>, R>, AxisOptions, RowOptions<R> {
161
+ /** Value labels on the bars: `true`, or a function for the text. */
162
+ dataLabels?: boolean | ((value: number, row: R, index: number) => string);
208
163
  }
164
+ export declare class BarChart<R = Row> extends Chart<BarOptions<R>> {}
209
165
 
210
- export interface LineChartOptions extends BaseChartOptions {
211
- data: Rows<BarDatum>;
212
- /** Read the label from a custom row shape. */
213
- label?: (d: any, i: number) => string | number;
214
- /** Read the value from a custom row shape. */
215
- value?: (d: any, i: number) => number;
216
- /** One color for every bar / the line (instead of the palette). */
217
- color?: Color;
218
- /** Path interpolation. Default `'smooth'`. */
219
- interpolation?: 'smooth' | 'linear' | 'step' | 'step-after' | 'step-middle';
220
- /** Area under the line. Default `true`. */
166
+ export interface HBarOptions<R = Row> extends CommonOptions<Rows<R>, R>, AxisOptions, RowOptions<R> {}
167
+ export declare class HBarChart<R = Row> extends Chart<HBarOptions<R>> {}
168
+
169
+ export interface LineOptions<R = Row> extends CommonOptions<Rows<R>, R>, AxisOptions, RowOptions<R> {
170
+ /** Default `'smooth'`. */
171
+ curve?: Curve;
172
+ /** Gradient fill under the line. Default `true`. */
221
173
  fill?: boolean;
222
- /** Dots on each point (≤ 50 points). Default `true`. */
174
+ /** Point markers (up to 50 points). Default `true`. */
223
175
  points?: boolean;
224
- /** Highlight the last data point with a dot. */
225
- lastDot?: boolean;
226
- xScale?: ScaleType;
227
- yScale?: ScaleType;
228
- yTickFormat?: TickFormatter;
229
- xTickFormat?: CategoryTickFormatter;
176
+ /** `'time'`: labels are ms timestamps on a local-time axis. Default `'category'`. */
177
+ xScale?: 'category' | 'time';
178
+ /** Default `'linear'`. */
179
+ yScale?: 'linear' | 'log';
230
180
  }
181
+ export declare class LineChart<R = Row> extends Chart<LineOptions<R>> {}
231
182
 
232
- export interface AreaChartOptions extends BaseChartOptions {
233
- categories: string[];
234
- series: Series[];
235
- /** Stack all series. Default `false`. */
183
+ export interface AreaOptions extends CommonOptions<SeriesData, Series>, AxisOptions {
184
+ /** Stack the series. */
236
185
  stacked?: boolean;
237
- yTickFormat?: TickFormatter;
238
- xTickFormat?: CategoryTickFormatter;
239
186
  }
187
+ export declare class AreaChart extends Chart<AreaOptions> {}
240
188
 
241
- export interface StackedBarChartOptions extends BaseChartOptions {
242
- categories: string[];
243
- series: Series[];
244
- yTickFormat?: TickFormatter;
245
- }
189
+ export interface StackedBarOptions extends CommonOptions<SeriesData, Series>, AxisOptions {}
190
+ export declare class StackedBarChart extends Chart<StackedBarOptions> {}
246
191
 
247
- export interface GroupedBarChartOptions extends BaseChartOptions {
248
- categories: string[];
249
- series: Series[];
250
- yTickFormat?: TickFormatter;
251
- }
192
+ export interface GroupedBarOptions extends CommonOptions<SeriesData, Series>, AxisOptions {}
193
+ export declare class GroupedBarChart extends Chart<GroupedBarOptions> {}
252
194
 
253
- export interface MultiLineChartOptions extends BaseChartOptions {
254
- categories: Array<string | number>;
255
- series: Series[];
256
- interpolation?: 'smooth' | 'linear' | 'step' | 'step-after' | 'step-middle';
257
- /** `'time'`: categories are timestamps (ms). */
258
- xScale?: ScaleType;
259
- yTickFormat?: TickFormatter;
195
+ export interface MultiLineOptions extends CommonOptions<SeriesData, Series>, AxisOptions {
196
+ curve?: Curve;
197
+ xScale?: 'category' | 'time';
260
198
  }
199
+ export declare class MultiLineChart extends Chart<MultiLineOptions> {}
261
200
 
262
- export interface ScatterChartOptions extends BaseChartOptions {
263
- data: ScatterDatum[];
264
- xScale?: ScaleType;
265
- yScale?: ScaleType;
266
- xTickFormat?: TickFormatter;
267
- yTickFormat?: TickFormatter;
268
- }
201
+ export interface ScatterOptions extends CommonOptions<Point[], Point>, AxisOptions {}
202
+ export declare class ScatterChart extends Chart<ScatterOptions> {}
269
203
 
270
- export interface BubbleChartOptions extends BaseChartOptions {
271
- data: BubbleDatum[];
272
- /** Largest bubble radius in px. Default `32`. */
273
- maxRadius?: number;
274
- /** Smallest bubble radius in px. Default `4`. */
275
- minRadius?: number;
276
- xScale?: ScaleType;
277
- yScale?: ScaleType;
278
- xTickFormat?: TickFormatter;
279
- yTickFormat?: TickFormatter;
204
+ export interface BubbleOptions extends CommonOptions<Point[], Point>, AxisOptions {
205
+ /** Bubble radius range in px for the smallest and largest `size`. Default `[4, 32]`. */
206
+ radius?: [number, number];
280
207
  }
208
+ export declare class BubbleChart extends Chart<BubbleOptions> {}
281
209
 
282
- export interface PieChartOptions extends BaseChartOptions {
283
- data: Rows<PieDatum>;
284
- label?: (d: any, i: number) => string | number;
285
- value?: (d: any, i: number) => number;
286
- /**
287
- * Donut hole: a ratio of the radius (`0.6`), pixels (`80`), `'auto'`
288
- * (0.55), or omit for a solid pie.
289
- */
290
- innerRadius?: number | 'auto';
291
- /** Text in the donut center when nothing is hovered (default: the total). */
292
- totalLabel?: string;
293
- /** `false` hides the donut center text. */
294
- centerLabel?: boolean;
210
+ export interface PieOptions<R = Row> extends CommonOptions<Rows<R>, R>, RowOptions<R> {
211
+ /** Donut hole as a share of the radius, 0–0.9. Default `0` (pie). */
212
+ innerRadius?: number;
213
+ /** Donut center text. Default: the formatted total. `false` hides it. */
214
+ center?: string | false;
295
215
  }
216
+ export declare class PieChart<R = Row> extends Chart<PieOptions<R>> {}
296
217
 
297
- export interface RadarChartOptions extends BaseChartOptions {
298
- axes: string[];
299
- series: RadarSeries[];
218
+ export interface RadarOptions extends CommonOptions<SeriesData, Series> {
219
+ labelFormat?: LabelFormat;
220
+ /** Value at the outer ring (default: from the data). */
221
+ max?: number;
300
222
  }
223
+ export declare class RadarChart extends Chart<RadarOptions> {}
301
224
 
302
- export interface PolarChartOptions extends BaseChartOptions {
303
- data: Rows<PolarDatum>;
304
- label?: (d: any, i: number) => string | number;
305
- value?: (d: any, i: number) => number;
306
- /** `'sqrt'` (default) keeps wedge *area* proportional to value; `'linear'` maps radius. */
225
+ export interface PolarOptions<R = Row> extends CommonOptions<Rows<R>, R>, RowOptions<R> {
226
+ /** `'sqrt'` keeps areas true to the values. Default `'sqrt'`. */
307
227
  scale?: 'sqrt' | 'linear';
308
228
  }
229
+ export declare class PolarChart<R = Row> extends Chart<PolarOptions<R>> {}
309
230
 
310
- export interface GaugeChartOptions extends BaseChartOptions {
311
- value: number;
312
- /** Minimum scale value. Default `0`. */
231
+ export interface GaugeOptions extends CommonOptions<number> {
232
+ /** Default `0`. */
313
233
  min?: number;
314
- /** Maximum scale value. Default `100`. */
234
+ /** Default `100`. */
315
235
  max?: number;
316
- /** Arc color. Default: first palette color. */
317
- color?: Color;
318
- /** Label drawn under the gauge. */
319
- label?: string;
320
- /** Suffix appended to the displayed value, e.g. `'%'`. */
236
+ /** Text after the number, e.g. `'%'`. */
321
237
  unit?: string;
322
238
  }
239
+ export declare class GaugeChart extends Chart<GaugeOptions> {}
323
240
 
324
- export interface HeatmapChartOptions extends BaseChartOptions {
325
- xLabels: string[];
326
- yLabels: string[];
327
- data: HeatmapDatum[];
328
- /** Color of the lowest cell value. */
329
- colorLow?: Color;
330
- /** Color of the highest cell value. */
331
- colorHigh?: Color;
241
+ export interface HeatmapData {
242
+ x: ArrayLike<string | number>;
243
+ y: ArrayLike<string | number>;
244
+ /** `values[y][x]`; `null` leaves a cell empty. */
245
+ values: Array<ArrayLike<number | null>>;
246
+ }
247
+ export interface HeatmapOptions extends Omit<CommonOptions<HeatmapData, { x: unknown; y: unknown; value: number }>, 'colors'> {
248
+ labelFormat?: LabelFormat;
249
+ /** Colors for the lowest and highest values. */
250
+ colors?: { low?: Color; high?: Color };
332
251
  }
252
+ export declare class HeatmapChart extends Chart<HeatmapOptions> {}
333
253
 
334
- export interface BoxplotChartOptions extends BaseChartOptions {
335
- data: BoxplotDatum[];
336
- yTickFormat?: TickFormatter;
254
+ export interface Box {
255
+ label: string | number;
256
+ min: number;
257
+ q1: number;
258
+ median: number;
259
+ q3: number;
260
+ max: number;
261
+ outliers?: number[];
262
+ color?: Color;
337
263
  }
264
+ export interface BoxplotOptions extends CommonOptions<Box[], Box>, AxisOptions {}
265
+ export declare class BoxplotChart extends Chart<BoxplotOptions> {}
338
266
 
339
- export interface FunnelChartOptions extends BaseChartOptions {
340
- data: Rows<FunnelDatum>;
341
- label?: (d: any, i: number) => string | number;
342
- value?: (d: any, i: number) => number;
343
- /** Text color inside segments. Default `#fff`. */
267
+ export interface FunnelOptions<R = Row> extends CommonOptions<Rows<R>, R>, RowOptions<R> {
268
+ /** Color of labels drawn inside the segments. Default `'#fff'`. */
344
269
  labelColor?: Color;
345
270
  }
271
+ export declare class FunnelChart<R = Row> extends Chart<FunnelOptions<R>> {}
346
272
 
347
- export interface TreemapChartOptions extends BaseChartOptions {
348
- data: Rows<TreemapDatum>;
349
- label?: (d: any, i: number) => string | number;
350
- value?: (d: any, i: number) => number;
351
- /** Text color inside tiles. Default `#fff`. */
273
+ export interface TreemapOptions<R = Row> extends CommonOptions<Rows<R>, R>, RowOptions<R> {
274
+ /** Color of labels drawn inside the tiles. Default `'#fff'`. */
352
275
  labelColor?: Color;
353
276
  }
277
+ export declare class TreemapChart<R = Row> extends Chart<TreemapOptions<R>> {}
354
278
 
355
- export interface SparklineOptions extends BaseChartOptions {
356
- /** Numbers (or `{ value }` rows) — sparklines have no axes. */
357
- data: number[] | Array<{ value: number }>;
358
- value?: (d: any, i: number) => number;
359
- color?: Color;
279
+ export interface SparklineOptions<R = Row> extends CommonOptions<Rows<R>, R>, RowOptions<R> {
280
+ min?: number;
281
+ max?: number;
282
+ /** Default `true`. */
360
283
  fill?: boolean;
284
+ /** Dot on the last value. Default `true`. */
361
285
  lastDot?: boolean;
362
286
  }
287
+ export declare class SparklineChart<R = Row> extends Chart<SparklineOptions<R>> {}
363
288
 
364
- export interface RealtimeChartOptions extends BaseChartOptions {
365
- /** Series definitions; values are pushed in over time via `push()`. */
366
- series: Array<{ name: string; color?: Color }>;
367
- /** Number of samples to keep on screen. Default `200`. */
368
- windowSize?: number;
369
- yTickFormat?: TickFormatter;
370
- /** Fix the y range instead of fitting the visible window. */
371
- yMin?: number;
372
- yMax?: number;
373
- /** Text shown before the first sample. Default `'streaming…'`. */
374
- waitingText?: string;
375
- }
376
-
377
- export interface WaterfallChartOptions extends BaseChartOptions {
378
- data: WaterfallDatum[] | Record<string, number>;
379
- yTickFormat?: TickFormatter;
380
- /** Color for positive deltas. */
381
- colorUp?: Color;
382
- /** Color for negative deltas. */
383
- colorDown?: Color;
384
- /** Color for total / anchor bars. */
385
- colorTotal?: Color;
386
- }
387
-
388
- export interface CompositeChartOptions extends BaseChartOptions {
389
- categories: string[];
390
- layers: CompositeLayer[];
391
- xScale?: ScaleType;
392
- /** Left axis format (`yTickFormat` works too). */
393
- yLeftTickFormat?: TickFormatter;
394
- yRightTickFormat?: TickFormatter;
395
- yTickFormat?: TickFormatter;
396
- xTickFormat?: (value: number) => string;
397
- }
398
-
399
- // ──────────────────────────────────────────────────────────────────
400
- // Base Chart class
401
- // ──────────────────────────────────────────────────────────────────
402
-
403
- /**
404
- * Common base class for every chart.
405
- *
406
- * `O` is the concrete options shape for the subclass. Most users will
407
- * interact only through the typed subclasses (e.g. `BarChart`); this base
408
- * is exposed for advanced extension scenarios.
409
- */
410
- export class Chart<O extends BaseChartOptions = BaseChartOptions> {
411
- constructor(container: ChartContainer, options: O);
412
-
413
- readonly container: HTMLElement;
414
- options: O;
415
-
416
- /** Re-resolve theme + palette from CSS variables and redraw. */
417
- invalidate(): void;
418
-
419
- /**
420
- * Merge new options — any of them, including `data`, `series`,
421
- * `categories` — and animate to the new state. Returns `this`.
422
- */
423
- update(options: Partial<O>): this;
424
-
425
- /** Replace `options.data` and animate to the new state. Returns `this`. */
426
- setData(data: O extends { data: infer D } ? D : unknown): this;
427
-
428
- /** Show a loading overlay. Returns `this`. */
429
- setLoading(message?: string): this;
430
- /** Show an empty-state overlay. Returns `this`. */
431
- setEmpty(message?: string): this;
432
- /** Show an error overlay. Returns `this`. */
433
- setError(message?: string): this;
434
- /** Clear any active overlay state and resume rendering. Returns `this`. */
435
- clearState(): this;
436
-
437
- /** Tear down listeners, observers, and remove the canvas. */
438
- destroy(): void;
439
- }
440
-
441
- // ──────────────────────────────────────────────────────────────────
442
- // Concrete chart classes
443
- // ──────────────────────────────────────────────────────────────────
444
-
445
- export class BarChart extends Chart<BarChartOptions> {
446
- constructor(container: ChartContainer, options: BarChartOptions);
447
- }
448
- export class HBarChart extends Chart<HBarChartOptions> {
449
- constructor(container: ChartContainer, options: HBarChartOptions);
450
- }
451
- export class LineChart extends Chart<LineChartOptions> {
452
- constructor(container: ChartContainer, options: LineChartOptions);
453
- }
454
- export class AreaChart extends Chart<AreaChartOptions> {
455
- constructor(container: ChartContainer, options: AreaChartOptions);
456
- }
457
- export class StackedBarChart extends Chart<StackedBarChartOptions> {
458
- constructor(container: ChartContainer, options: StackedBarChartOptions);
459
- }
460
- export class GroupedBarChart extends Chart<GroupedBarChartOptions> {
461
- constructor(container: ChartContainer, options: GroupedBarChartOptions);
462
- }
463
- export class MultiLineChart extends Chart<MultiLineChartOptions> {
464
- constructor(container: ChartContainer, options: MultiLineChartOptions);
465
- }
466
- export class ScatterChart extends Chart<ScatterChartOptions> {
467
- constructor(container: ChartContainer, options: ScatterChartOptions);
468
- }
469
- export class BubbleChart extends Chart<BubbleChartOptions> {
470
- constructor(container: ChartContainer, options: BubbleChartOptions);
471
- }
472
- export class PieChart extends Chart<PieChartOptions> {
473
- constructor(container: ChartContainer, options: PieChartOptions);
474
- }
475
- export class RadarChart extends Chart<RadarChartOptions> {
476
- constructor(container: ChartContainer, options: RadarChartOptions);
477
- }
478
- export class PolarChart extends Chart<PolarChartOptions> {
479
- constructor(container: ChartContainer, options: PolarChartOptions);
480
- }
481
-
482
- export class GaugeChart extends Chart<GaugeChartOptions> {
483
- constructor(container: ChartContainer, options: GaugeChartOptions);
484
- /** Animate the needle to a new value. */
485
- setValue(value: number): this;
486
- }
487
-
488
- export class HeatmapChart extends Chart<HeatmapChartOptions> {
489
- constructor(container: ChartContainer, options: HeatmapChartOptions);
490
- }
491
- export class BoxplotChart extends Chart<BoxplotChartOptions> {
492
- constructor(container: ChartContainer, options: BoxplotChartOptions);
493
- }
494
- export class FunnelChart extends Chart<FunnelChartOptions> {
495
- constructor(container: ChartContainer, options: FunnelChartOptions);
496
- }
497
- export class TreemapChart extends Chart<TreemapChartOptions> {
498
- constructor(container: ChartContainer, options: TreemapChartOptions);
499
- }
500
- export class Sparkline extends Chart<SparklineOptions> {
501
- constructor(container: ChartContainer, options: SparklineOptions);
289
+ export interface RealtimeOptions extends CommonOptions<{ series: Array<{ name: string; color?: Color }> }> {
290
+ min?: number;
291
+ max?: number;
292
+ /** How many samples stay visible. Default `200`. */
293
+ window?: number;
502
294
  }
503
-
504
- export class RealtimeChart extends Chart<RealtimeChartOptions> {
505
- constructor(container: ChartContainer, options: RealtimeChartOptions);
506
- /**
507
- * Append one sample. Pass a single number for one-series charts, or an
508
- * array aligned with `options.series` for multi-series charts.
509
- */
510
- push(values: number | number[]): this;
511
- /** Drop all buffered samples. */
295
+ export declare class RealtimeChart extends Chart<RealtimeOptions> {
296
+ /** Add one sample: one value per series (a number for a single series). */
297
+ push(values: number | Array<number | null>): this;
298
+ /** Remove every sample. */
512
299
  clear(): this;
513
300
  }
514
301
 
515
- export class WaterfallChart extends Chart<WaterfallChartOptions> {
516
- constructor(container: ChartContainer, options: WaterfallChartOptions);
517
- }
518
-
519
- export class CompositeChart extends Chart<CompositeChartOptions> {
520
- constructor(container: ChartContainer, options: CompositeChartOptions);
302
+ export interface Step {
303
+ label: string | number;
304
+ value: number;
305
+ /** Draw this bar from zero to its value (a subtotal or the end result). */
306
+ total?: boolean;
521
307
  }
522
-
523
- // ──────────────────────────────────────────────────────────────────
524
- // Engine + scheduler (advanced / extension API)
525
- // ──────────────────────────────────────────────────────────────────
526
-
527
- /**
528
- * Low-level canvas drawing primitives shared by every chart. Most users
529
- * will not touch this directly — extend `Chart` and use `this.engine`.
530
- */
531
- export class Engine {
532
- constructor(canvas: HTMLCanvasElement);
533
- readonly canvas: HTMLCanvasElement;
534
- readonly ctx: CanvasRenderingContext2D;
535
- /** Logical width in CSS pixels (set by `resize()`). */
536
- readonly w: number;
537
- /** Logical height in CSS pixels (set by `resize()`). */
538
- readonly h: number;
539
- /** Device pixel ratio used for the backing buffer. */
540
- readonly dpr: number;
541
- resize(w: number, h: number): void;
542
- clear(color?: Color): void;
308
+ export interface WaterfallOptions extends Omit<CommonOptions<Step[], Step>, 'colors'>, AxisOptions {
309
+ colors?: { up?: Color; down?: Color; total?: Color };
543
310
  }
311
+ export declare class WaterfallChart extends Chart<WaterfallOptions> {}
544
312
 
545
- /** Normalize label/value data shortcuts to `{ label, value }` rows. */
546
- export function toRows<T = BarDatum>(data: Rows<T> | null | undefined): T[];
547
-
548
- /** Geometry returned by `drawCartesian()`. */
549
- export interface CartesianFrame {
550
- px: number; py: number; pw: number; ph: number;
551
- yToPx(v: number): number;
552
- yRToPx: ((v: number) => number) | null;
553
- xToPx(v: number): number;
554
- yTicks: number[];
555
- xTicks: number[];
556
- yMin: number;
557
- yMax: number;
313
+ export interface CompositeSeries extends Series {
314
+ type: 'bar' | 'line' | 'area' | 'scatter';
315
+ /** Put this series on the right axis. */
316
+ axis?: 'left' | 'right';
317
+ /** Number format for this series (tooltip and its axis). */
318
+ format?: NumberFormat;
558
319
  }
559
-
560
- /** Draw grid + axes for a custom chart (extension API). */
561
- export function drawCartesian(chart: Chart<any>, spec: {
562
- yMin?: number; yMax: number; yScale?: 'linear' | 'log'; yTickFormat?: TickFormatter;
563
- xLabels?: Array<string | number>; xTime?: { min: number; max: number }; xLinear?: { min: number; max: number };
564
- xTickFormat?: (value: number, index: number) => string;
565
- right?: { yMin: number; yMax: number; yTickFormat?: TickFormatter };
566
- pad?: { l?: number; r?: number; t?: number; b?: number };
567
- }): CartesianFrame;
568
-
569
- /**
570
- * Global render scheduler. Charts register themselves and are ticked on
571
- * `requestAnimationFrame` only when dirty.
572
- */
573
- export const scheduler: {
574
- schedule(chart: Chart<any>): void;
575
- fps(): number;
576
- count(): number;
577
- };
578
-
579
- /** Current render frame rate, averaged over the last ~500 ms. */
580
- export function getFPS(): number;
581
-
582
- /** Number of charts currently mounted. */
583
- export function getActiveCount(): number;
584
-
585
- // ──────────────────────────────────────────────────────────────────
586
- // Math helpers
587
- // ──────────────────────────────────────────────────────────────────
588
-
589
- /**
590
- * Default qualitative palette — 8 colors, brand accent first.
591
- *
592
- * Re-exported at the top level because every chart accepts a `palette`
593
- * option and most users only ever need this one math symbol directly.
594
- */
595
- export const PALETTE: Color[];
596
-
597
- /**
598
- * Pure helpers (scales, ticks, smoothing, color ops). Use as
599
- * `import { math } from 'aeriz'` and then `math.clamp(...)` etc.
600
- */
601
- export const math: {
602
- readonly TAU: number;
603
- clamp(v: number, lo: number, hi: number): number;
604
- lerp(a: number, b: number, t: number): number;
605
- extent<T>(arr: T[], fn?: (x: T, i: number) => number): [number, number];
606
- niceTicks(min: number, max: number, count?: number): number[];
607
- niceDomain(min: number, max: number, count?: number): [number, number];
608
- timeNiceTicks(minMs: number, maxMs: number, count?: number): number[];
609
- timeFormat(stepMs: number): (timestampMs: number) => string;
610
- minMaxDecimate<T>(
611
- data: T[],
612
- targetCount: number,
613
- fn?: (d: T, i: number) => number,
614
- ): T[];
615
- /** Indices of the points min-max decimation keeps. */
616
- minMaxDecimateIdx(n: number, targetCount: number, valueAt: (i: number) => number): number[];
617
- shouldDecimate(n: number, pxWidth: number): boolean;
618
- /** Format a number like the charts do (see `NumberFormat`). `axis` enables compact notation. */
619
- formatNumber(value: number, format?: NumberFormat | null, axis?: boolean): string;
620
- bezierControlPoints(
621
- pts: Array<{ x: number; y: number }>,
622
- tension?: number,
623
- ): Array<{ c1x: number; c1y: number; c2x: number; c2y: number }>;
624
- springStep(
625
- v: number,
626
- target: number,
627
- velocity: number,
628
- cfg?: { stiffness?: number; damping?: number },
629
- ): { value: number; velocity: number; done: boolean };
630
- colorParse(c: Color): [number, number, number, number];
631
- colorAlpha(c: Color, a: number): string;
632
- colorMix(a: Color, b: Color, t: number): string;
633
- readonly PALETTE: Color[];
634
- };
635
-
636
- // ──────────────────────────────────────────────────────────────────
637
- // Browser global (for the IIFE / CDN bundle)
638
- // ──────────────────────────────────────────────────────────────────
639
-
640
- declare global {
641
- interface Window {
642
- Aeriz?: typeof import('./index.js') & {
643
- /** Install the jQuery plugin on a jQuery that loaded after this script. */
644
- jquery(jq: unknown): unknown;
645
- };
646
- }
320
+ export interface CompositeOptions extends CommonOptions<SeriesData<CompositeSeries>, CompositeSeries>, AxisOptions {
321
+ xScale?: 'category' | 'time';
647
322
  }
323
+ export declare class CompositeChart extends Chart<CompositeOptions> {}