@angx/ngx-chart-kit 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +311 -2
- package/fesm2022/angx-ngx-chart-kit.mjs +1039 -0
- package/fesm2022/angx-ngx-chart-kit.mjs.map +1 -0
- package/package.json +57 -3
- package/types/angx-ngx-chart-kit.d.ts +484 -0
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated bundle index. Do not edit.
|
|
3
|
+
*/
|
|
4
|
+
import { Chart } from "chart.js";
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
/**
|
|
7
|
+
* Public data and configuration types for `@angx/ngx-chart-kit`.
|
|
8
|
+
*
|
|
9
|
+
* These are deliberately small. The library's contract is "labels down the
|
|
10
|
+
* side, named series across the top" — the same shape a data table has, which
|
|
11
|
+
* is what makes the accessible table equivalent a mechanical transformation of
|
|
12
|
+
* the chart's own data rather than something a consumer has to maintain twice.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Chart forms the library exposes.
|
|
16
|
+
*
|
|
17
|
+
* `hbar` is a bar chart with the category axis on the left, and `area` is a
|
|
18
|
+
* line chart with the region under the line filled. Both are separate entries
|
|
19
|
+
* here rather than flags because that is how a consumer thinks about them, and
|
|
20
|
+
* because it keeps the chart.js `indexAxis` / `fill` plumbing inside the
|
|
21
|
+
* library.
|
|
22
|
+
*/
|
|
23
|
+
type ChartKitType = 'bar' | 'hbar' | 'line' | 'area' | 'pie' | 'doughnut' | 'radar';
|
|
24
|
+
/** One named run of values, aligned with {@link ChartKitData.labels}. */
|
|
25
|
+
interface ChartKitSeries {
|
|
26
|
+
/**
|
|
27
|
+
* Name of the series. Used in the legend, in tooltips and as the column
|
|
28
|
+
* header of the accessible table, so it must be meaningful to a reader.
|
|
29
|
+
*/
|
|
30
|
+
readonly label: string;
|
|
31
|
+
/**
|
|
32
|
+
* The values, one per entry in {@link ChartKitData.labels}. `null` and
|
|
33
|
+
* `undefined` mean "no value here": the chart leaves a gap and the table
|
|
34
|
+
* says so in words.
|
|
35
|
+
*/
|
|
36
|
+
readonly data: readonly (number | null | undefined)[];
|
|
37
|
+
/**
|
|
38
|
+
* Overrides this series' colour, bypassing the palette. Any CSS colour the
|
|
39
|
+
* browser can parse. Prefer the `--chart-kit-*` custom properties — a colour
|
|
40
|
+
* set here cannot follow a theme change.
|
|
41
|
+
*/
|
|
42
|
+
readonly color?: string;
|
|
43
|
+
}
|
|
44
|
+
/** The data a chart draws, and the data its table equivalent is built from. */
|
|
45
|
+
interface ChartKitData {
|
|
46
|
+
/** Category names: the x axis of a bar or line chart, the slices of a pie. */
|
|
47
|
+
readonly labels: readonly string[];
|
|
48
|
+
/** One or more series. A pie or doughnut draws a ring per series. */
|
|
49
|
+
readonly series: readonly ChartKitSeries[];
|
|
50
|
+
}
|
|
51
|
+
/** What a value formatter is told about the value it is formatting. */
|
|
52
|
+
interface ChartKitValueContext {
|
|
53
|
+
/** Index into {@link ChartKitData.series}. */
|
|
54
|
+
readonly seriesIndex: number;
|
|
55
|
+
/** Index into {@link ChartKitData.labels}. */
|
|
56
|
+
readonly pointIndex: number;
|
|
57
|
+
/** The series' name. */
|
|
58
|
+
readonly seriesLabel: string;
|
|
59
|
+
/** The category's name. */
|
|
60
|
+
readonly label: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Turns a value into display text, for table cells and tooltips alike, so the
|
|
64
|
+
* two can never disagree. Return text for a `null` value too — a screen reader
|
|
65
|
+
* reads an empty cell as "blank", which does not distinguish "no data" from a
|
|
66
|
+
* rendering bug.
|
|
67
|
+
*/
|
|
68
|
+
type ChartKitValueFormat = (value: number | null, context: ChartKitValueContext) => string;
|
|
69
|
+
/** Where the table equivalent of the chart is rendered. */
|
|
70
|
+
type ChartKitTableMode = 'hidden' | 'visible';
|
|
71
|
+
/** A single cell of the accessible table. */
|
|
72
|
+
interface ChartKitTableCell {
|
|
73
|
+
/** The raw value, or `null` where the series has no value. */
|
|
74
|
+
readonly value: number | null;
|
|
75
|
+
/** The formatted text actually rendered in the cell. */
|
|
76
|
+
readonly text: string;
|
|
77
|
+
}
|
|
78
|
+
/** A single row of the accessible table: one category, one cell per series. */
|
|
79
|
+
interface ChartKitTableRow {
|
|
80
|
+
/** The category name, rendered as the row header. */
|
|
81
|
+
readonly label: string;
|
|
82
|
+
/** One cell per series, in series order. */
|
|
83
|
+
readonly cells: readonly ChartKitTableCell[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The accessible table, derived from the same {@link ChartKitData} the chart
|
|
87
|
+
* draws. Exported because it is the part of the library most worth testing in
|
|
88
|
+
* a consumer's own suite.
|
|
89
|
+
*/
|
|
90
|
+
interface ChartKitTableModel {
|
|
91
|
+
/** The table's `<caption>`: the chart's accessible name. */
|
|
92
|
+
readonly caption: string;
|
|
93
|
+
/** Header of the first column, naming what the row headers are. */
|
|
94
|
+
readonly categoryHeader: string;
|
|
95
|
+
/** Column headers, one per series, in series order. */
|
|
96
|
+
readonly seriesHeaders: readonly string[];
|
|
97
|
+
/** One row per category. */
|
|
98
|
+
readonly rows: readonly ChartKitTableRow[];
|
|
99
|
+
}
|
|
100
|
+
/** Colours and fonts a chart draws with, resolved from CSS. */
|
|
101
|
+
interface ChartKitTheme {
|
|
102
|
+
/** Categorical colours, in the order series or slices consume them. */
|
|
103
|
+
readonly palette: readonly string[];
|
|
104
|
+
/** Primary text: legend labels, tooltip titles. */
|
|
105
|
+
readonly text: string;
|
|
106
|
+
/** Secondary text: axis ticks. */
|
|
107
|
+
readonly muted: string;
|
|
108
|
+
/** Grid and axis border lines. */
|
|
109
|
+
readonly grid: string;
|
|
110
|
+
/** The surface the chart sits on, used for the gaps between pie slices. */
|
|
111
|
+
readonly surface: string;
|
|
112
|
+
/** Tooltip background. */
|
|
113
|
+
readonly tooltipBackground: string;
|
|
114
|
+
/** Tooltip text. */
|
|
115
|
+
readonly tooltipText: string;
|
|
116
|
+
/** Font stack for every label the chart draws. */
|
|
117
|
+
readonly font: string;
|
|
118
|
+
}
|
|
119
|
+
/** A point a reader clicked or activated, reported by `pointSelect`. */
|
|
120
|
+
interface ChartKitPoint extends ChartKitValueContext {
|
|
121
|
+
/** The value at that point, or `null` where the series has no value. */
|
|
122
|
+
readonly value: number | null;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* An accessible, lazily-loaded, CSS-themed chart.
|
|
126
|
+
*
|
|
127
|
+
* Four things distinguish it from a thin chart.js wrapper, and they are worth
|
|
128
|
+
* stating because they are the reason to use it:
|
|
129
|
+
*
|
|
130
|
+
* 1. Every chart renders a real `<table>` of the same data, visually hidden by
|
|
131
|
+
* default. A `<canvas>` is a bitmap: assistive technology can see nothing
|
|
132
|
+
* in it, so a chart without a text equivalent is a chart some readers
|
|
133
|
+
* cannot read at all. Because the table is derived from the same input the
|
|
134
|
+
* canvas draws, it cannot go stale.
|
|
135
|
+
* 2. Inputs are signals. Changing one recomputes the configuration and hands
|
|
136
|
+
* it to chart.js's `update()`, keeping the same chart instance.
|
|
137
|
+
* 3. chart.js is imported dynamically on first draw, so it never lands in the
|
|
138
|
+
* initial bundle, and every `document` / `window` / canvas touch is behind
|
|
139
|
+
* `isPlatformBrowser`, so the component server-renders its table and
|
|
140
|
+
* attaches the canvas only in a browser.
|
|
141
|
+
* 4. Colours come from CSS custom properties on the host, read at draw time. A
|
|
142
|
+
* consumer's dark-mode switch recolours the chart with no input rebound.
|
|
143
|
+
*/
|
|
144
|
+
export declare class NgxChartKitComponent {
|
|
145
|
+
private readonly host;
|
|
146
|
+
private readonly canvasRef;
|
|
147
|
+
/**
|
|
148
|
+
* Whether this is running in a browser. Read by the template, which renders
|
|
149
|
+
* the table on both platforms but the canvas only here.
|
|
150
|
+
*/
|
|
151
|
+
protected readonly isBrowser: boolean;
|
|
152
|
+
/** Id of the description paragraph, referenced by the canvas. */
|
|
153
|
+
protected readonly descriptionId: string;
|
|
154
|
+
/** The data to draw, and the data the accessible table is built from. */
|
|
155
|
+
readonly data: import("@angular/core").InputSignal<ChartKitData>;
|
|
156
|
+
/**
|
|
157
|
+
* The chart's accessible name and the table's `<caption>`. Required: a chart
|
|
158
|
+
* nobody can name is a chart some readers cannot use, and making it optional
|
|
159
|
+
* would mean most charts shipped without one.
|
|
160
|
+
*/
|
|
161
|
+
readonly caption: import("@angular/core").InputSignal<string>;
|
|
162
|
+
/** Which form to draw. */
|
|
163
|
+
readonly type: import("@angular/core").InputSignal<ChartKitType>;
|
|
164
|
+
/**
|
|
165
|
+
* A longer explanation — what the chart shows, where the numbers come from.
|
|
166
|
+
* Rendered above the table and referenced by the canvas's
|
|
167
|
+
* `aria-describedby`.
|
|
168
|
+
*/
|
|
169
|
+
readonly description: import("@angular/core").InputSignal<string>;
|
|
170
|
+
/** Header of the table's first column, naming what the row headers are. */
|
|
171
|
+
readonly categoryHeader: import("@angular/core").InputSignal<string>;
|
|
172
|
+
/**
|
|
173
|
+
* Where the data table goes: `'hidden'` (the default) keeps it in the
|
|
174
|
+
* accessibility tree but out of sight, `'visible'` renders it under the
|
|
175
|
+
* chart. There is deliberately no third value that removes it.
|
|
176
|
+
*/
|
|
177
|
+
readonly dataTable: import("@angular/core").InputSignal<ChartKitTableMode>;
|
|
178
|
+
/** Height of the drawing area, in CSS pixels. Width follows the host. */
|
|
179
|
+
readonly height: import("@angular/core").InputSignalWithTransform<number, unknown>;
|
|
180
|
+
/** Stack series on top of one another. Applies to bar and area charts. */
|
|
181
|
+
readonly stacked: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
|
|
182
|
+
/**
|
|
183
|
+
* Show the legend. Ignored for a single-series cartesian chart, where a
|
|
184
|
+
* legend of one entry tells a reader nothing the caption has not.
|
|
185
|
+
*/
|
|
186
|
+
readonly legend: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
|
|
187
|
+
/** Show tooltips on hover. */
|
|
188
|
+
readonly tooltips: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
|
|
189
|
+
/**
|
|
190
|
+
* Animate transitions. Forced off when the reader has asked for reduced
|
|
191
|
+
* motion, whatever this is set to.
|
|
192
|
+
*/
|
|
193
|
+
readonly animate: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
|
|
194
|
+
/** Start the value axis at zero, so bar lengths stay proportional. */
|
|
195
|
+
readonly beginAtZero: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
|
|
196
|
+
/**
|
|
197
|
+
* Overrides the palette from TypeScript. The CSS custom properties are the
|
|
198
|
+
* better route — a palette passed here cannot follow a theme change — but
|
|
199
|
+
* this exists for a palette that comes from data rather than from design.
|
|
200
|
+
*/
|
|
201
|
+
readonly palette: import("@angular/core").InputSignal<readonly string[] | undefined>;
|
|
202
|
+
/** Locale for the default number formatting. Defaults to the runtime's. */
|
|
203
|
+
readonly locale: import("@angular/core").InputSignal<string | undefined>;
|
|
204
|
+
/**
|
|
205
|
+
* Formats a value for both the table and the tooltip, so the two can never
|
|
206
|
+
* disagree. Takes the value and its position; see `ChartKitValueFormat`.
|
|
207
|
+
*/
|
|
208
|
+
readonly valueFormat: import("@angular/core").InputSignal<ChartKitValueFormat | undefined>;
|
|
209
|
+
/** Table text for a missing value. Read aloud, so not an empty string. */
|
|
210
|
+
readonly emptyValueText: import("@angular/core").InputSignal<string>;
|
|
211
|
+
/**
|
|
212
|
+
* A point the reader clicked. Supplementary to the table, not a replacement
|
|
213
|
+
* for it: this is a pointer affordance, and the table is the path that works
|
|
214
|
+
* without one.
|
|
215
|
+
*/
|
|
216
|
+
readonly pointSelect: import("@angular/core").OutputEmitterRef<ChartKitPoint>;
|
|
217
|
+
/**
|
|
218
|
+
* The chart.js instance, once created, and again after a rebuild. The
|
|
219
|
+
* deliberate escape hatch: reach for it to register a plugin or read a
|
|
220
|
+
* scale, rather than expecting this component to re-export chart.js's
|
|
221
|
+
* options object.
|
|
222
|
+
*/
|
|
223
|
+
readonly chartCreate: import("@angular/core").OutputEmitterRef<Chart<keyof import("chart.js").ChartTypeRegistry, (number | [number, number] | import("chart.js").Point | import("chart.js").BubbleDataPoint | null)[], unknown>>;
|
|
224
|
+
/**
|
|
225
|
+
* Something went wrong drawing the chart: the chart.js chunk failed to load,
|
|
226
|
+
* or the canvas refused a 2d context. Emitted rather than thrown so a
|
|
227
|
+
* consumer can show a fallback — and because an input-driven draw happens
|
|
228
|
+
* outside any call a consumer could wrap in a `try`. The table equivalent is
|
|
229
|
+
* already on the page either way, which is the point of rendering it from
|
|
230
|
+
* the data rather than from the chart.
|
|
231
|
+
*/
|
|
232
|
+
readonly renderError: import("@angular/core").OutputEmitterRef<unknown>;
|
|
233
|
+
/** Bumped whenever something that could have changed the CSS has changed. */
|
|
234
|
+
private readonly themeRevision;
|
|
235
|
+
/** Whether the reader has asked for reduced motion. */
|
|
236
|
+
private readonly reducedMotion;
|
|
237
|
+
/** Height, with a non-finite binding falling back to the default. */
|
|
238
|
+
protected readonly safeHeight: import("@angular/core").Signal<number>;
|
|
239
|
+
/**
|
|
240
|
+
* Colours and fonts, re-read from the host's resolved CSS every time
|
|
241
|
+
* {@link themeRevision} changes. On the server there is no computed style to
|
|
242
|
+
* read, so the reader falls back to its documented defaults.
|
|
243
|
+
*/
|
|
244
|
+
private readonly theme;
|
|
245
|
+
/** The formatter the table and the tooltips share. */
|
|
246
|
+
private readonly format;
|
|
247
|
+
/** The chart's accessible name: the caption, plus what kind of chart it is. */
|
|
248
|
+
protected readonly accessibleName: import("@angular/core").Signal<string>;
|
|
249
|
+
/** The table equivalent of the chart. */
|
|
250
|
+
protected readonly table: import("@angular/core").Signal<import("@angx/ngx-chart-kit").ChartKitTableModel>;
|
|
251
|
+
/** Everything the chart.js configuration is built from. */
|
|
252
|
+
private readonly renderInput;
|
|
253
|
+
private chart?;
|
|
254
|
+
/** The chart.js type the live instance was built with. */
|
|
255
|
+
private chartJsType?;
|
|
256
|
+
/** Guards against an out-of-order draw resolving after a newer one. */
|
|
257
|
+
private drawToken;
|
|
258
|
+
private destroyed;
|
|
259
|
+
/** Coalesces a burst of theme notifications into one re-read. */
|
|
260
|
+
private themeRefreshScheduled;
|
|
261
|
+
constructor();
|
|
262
|
+
/**
|
|
263
|
+
* Re-reads the host's CSS and redraws.
|
|
264
|
+
*
|
|
265
|
+
* The component already watches `prefers-color-scheme` and the attributes a
|
|
266
|
+
* theme switch usually changes, which covers the common cases. Call this
|
|
267
|
+
* when a theme is switched some other way — a stylesheet swapped at runtime,
|
|
268
|
+
* a custom property set from script on an ancestor.
|
|
269
|
+
*/
|
|
270
|
+
refreshTheme(): void;
|
|
271
|
+
/** Draws or updates the chart. */
|
|
272
|
+
private draw;
|
|
273
|
+
/**
|
|
274
|
+
* Watches for the things that change a chart's colours: the OS colour
|
|
275
|
+
* scheme, and the document attributes an in-app theme toggle sets. The
|
|
276
|
+
* second matters more in practice — most applications switch themes with a
|
|
277
|
+
* class on `<html>`, not by asking the OS.
|
|
278
|
+
*/
|
|
279
|
+
private watchColorScheme;
|
|
280
|
+
/**
|
|
281
|
+
* Defers the re-read to the next frame. A theme toggle often sets several
|
|
282
|
+
* attributes at once, and the new custom property values are not resolved
|
|
283
|
+
* until the browser has restyled, so reading synchronously from the
|
|
284
|
+
* observer would read the old palette.
|
|
285
|
+
*/
|
|
286
|
+
private scheduleThemeRefresh;
|
|
287
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NgxChartKitComponent, never>;
|
|
288
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<NgxChartKitComponent, "chart-kit", never, {
|
|
289
|
+
"data": {
|
|
290
|
+
"alias": "data";
|
|
291
|
+
"required": true;
|
|
292
|
+
"isSignal": true;
|
|
293
|
+
};
|
|
294
|
+
"caption": {
|
|
295
|
+
"alias": "caption";
|
|
296
|
+
"required": true;
|
|
297
|
+
"isSignal": true;
|
|
298
|
+
};
|
|
299
|
+
"type": {
|
|
300
|
+
"alias": "type";
|
|
301
|
+
"required": false;
|
|
302
|
+
"isSignal": true;
|
|
303
|
+
};
|
|
304
|
+
"description": {
|
|
305
|
+
"alias": "description";
|
|
306
|
+
"required": false;
|
|
307
|
+
"isSignal": true;
|
|
308
|
+
};
|
|
309
|
+
"categoryHeader": {
|
|
310
|
+
"alias": "categoryHeader";
|
|
311
|
+
"required": false;
|
|
312
|
+
"isSignal": true;
|
|
313
|
+
};
|
|
314
|
+
"dataTable": {
|
|
315
|
+
"alias": "dataTable";
|
|
316
|
+
"required": false;
|
|
317
|
+
"isSignal": true;
|
|
318
|
+
};
|
|
319
|
+
"height": {
|
|
320
|
+
"alias": "height";
|
|
321
|
+
"required": false;
|
|
322
|
+
"isSignal": true;
|
|
323
|
+
};
|
|
324
|
+
"stacked": {
|
|
325
|
+
"alias": "stacked";
|
|
326
|
+
"required": false;
|
|
327
|
+
"isSignal": true;
|
|
328
|
+
};
|
|
329
|
+
"legend": {
|
|
330
|
+
"alias": "legend";
|
|
331
|
+
"required": false;
|
|
332
|
+
"isSignal": true;
|
|
333
|
+
};
|
|
334
|
+
"tooltips": {
|
|
335
|
+
"alias": "tooltips";
|
|
336
|
+
"required": false;
|
|
337
|
+
"isSignal": true;
|
|
338
|
+
};
|
|
339
|
+
"animate": {
|
|
340
|
+
"alias": "animate";
|
|
341
|
+
"required": false;
|
|
342
|
+
"isSignal": true;
|
|
343
|
+
};
|
|
344
|
+
"beginAtZero": {
|
|
345
|
+
"alias": "beginAtZero";
|
|
346
|
+
"required": false;
|
|
347
|
+
"isSignal": true;
|
|
348
|
+
};
|
|
349
|
+
"palette": {
|
|
350
|
+
"alias": "palette";
|
|
351
|
+
"required": false;
|
|
352
|
+
"isSignal": true;
|
|
353
|
+
};
|
|
354
|
+
"locale": {
|
|
355
|
+
"alias": "locale";
|
|
356
|
+
"required": false;
|
|
357
|
+
"isSignal": true;
|
|
358
|
+
};
|
|
359
|
+
"valueFormat": {
|
|
360
|
+
"alias": "valueFormat";
|
|
361
|
+
"required": false;
|
|
362
|
+
"isSignal": true;
|
|
363
|
+
};
|
|
364
|
+
"emptyValueText": {
|
|
365
|
+
"alias": "emptyValueText";
|
|
366
|
+
"required": false;
|
|
367
|
+
"isSignal": true;
|
|
368
|
+
};
|
|
369
|
+
}, {
|
|
370
|
+
"pointSelect": "pointSelect";
|
|
371
|
+
"chartCreate": "chartCreate";
|
|
372
|
+
"renderError": "renderError";
|
|
373
|
+
}, never, never, true, never>;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* The default categorical palette.
|
|
377
|
+
*
|
|
378
|
+
* Chosen from the Okabe–Ito colour-blind-safe set, with two deliberate
|
|
379
|
+
* departures:
|
|
380
|
+
*
|
|
381
|
+
* - Okabe–Ito's black is dropped. It is invisible against a dark surface, and
|
|
382
|
+
* this library is meant to be themed from CSS rather than assume a white
|
|
383
|
+
* page.
|
|
384
|
+
* - Okabe–Ito's `#F0E442` yellow is dropped. Its relative luminance is around
|
|
385
|
+
* 0.79, so a 2px line or a small legend swatch in that colour falls below
|
|
386
|
+
* 3:1 against white.
|
|
387
|
+
*
|
|
388
|
+
* That leaves six Okabe–Ito hues, extended with a violet from IBM's
|
|
389
|
+
* colour-blind-safe palette and a neutral grey in the last slot, which reads
|
|
390
|
+
* naturally as "other" when a chart needs more than seven series. Every entry
|
|
391
|
+
* sits in the mid-luminance band (roughly 0.15–0.5), which is what lets the
|
|
392
|
+
* same palette hold its contrast on a near-white and a near-black surface
|
|
393
|
+
* without being swapped out.
|
|
394
|
+
*
|
|
395
|
+
* The order separates the pairs most easily confused under protanopia and
|
|
396
|
+
* deuteranopia: blue and orange first, with sky blue held back to slot five so
|
|
397
|
+
* it is never adjacent to the darker blue.
|
|
398
|
+
*/
|
|
399
|
+
export declare const CHART_KIT_PALETTE: readonly string[];
|
|
400
|
+
/** CSS custom properties the library reads from its host element. */
|
|
401
|
+
export declare const CHART_KIT_CSS_PROPERTIES: {
|
|
402
|
+
/** Whole palette as a comma-separated list, replacing the default. */
|
|
403
|
+
readonly palette: "--chart-kit-palette";
|
|
404
|
+
/** Prefix for a single palette slot, 1-based: `--chart-kit-series-3`. */
|
|
405
|
+
readonly seriesPrefix: "--chart-kit-series-";
|
|
406
|
+
/** Legend labels and tooltip titles. */
|
|
407
|
+
readonly text: "--chart-kit-text";
|
|
408
|
+
/** Axis ticks. */
|
|
409
|
+
readonly muted: "--chart-kit-muted";
|
|
410
|
+
/** Grid and axis lines. */
|
|
411
|
+
readonly grid: "--chart-kit-grid";
|
|
412
|
+
/** Surface the chart sits on; fills the gaps between pie slices. */
|
|
413
|
+
readonly surface: "--chart-kit-surface";
|
|
414
|
+
/** Tooltip background. */
|
|
415
|
+
readonly tooltipBackground: "--chart-kit-tooltip-bg";
|
|
416
|
+
/** Tooltip text. */
|
|
417
|
+
readonly tooltipText: "--chart-kit-tooltip-text";
|
|
418
|
+
/** Font stack for every label the chart draws. */
|
|
419
|
+
readonly font: "--chart-kit-font";
|
|
420
|
+
};
|
|
421
|
+
/**
|
|
422
|
+
* Coerces whatever a template binding holds into a value a chart can draw.
|
|
423
|
+
*
|
|
424
|
+
* `undefined` is what a binding holds while its data loads, and `NaN` is what
|
|
425
|
+
* arithmetic on it produces. Both become `null`, which chart.js renders as a
|
|
426
|
+
* gap and the table renders as words.
|
|
427
|
+
*/
|
|
428
|
+
export declare function toChartValue(value: number | null | undefined): number | null;
|
|
429
|
+
/**
|
|
430
|
+
* The number of rows the chart and its table both have.
|
|
431
|
+
*
|
|
432
|
+
* `labels` normally governs, but a series longer than `labels` would otherwise
|
|
433
|
+
* have values that are drawn and never described — chart.js would plot them
|
|
434
|
+
* against an unlabelled category. Taking the longest of the two keeps the
|
|
435
|
+
* canvas and the table showing the same number of points, always.
|
|
436
|
+
*/
|
|
437
|
+
export declare function chartKitRowCount(data: ChartKitData): number;
|
|
438
|
+
/**
|
|
439
|
+
* The category labels, padded to {@link chartKitRowCount} so every drawn point
|
|
440
|
+
* has a name. This same array is handed to chart.js, so the axis ticks and the
|
|
441
|
+
* table's row headers cannot drift apart.
|
|
442
|
+
*/
|
|
443
|
+
export declare function chartKitLabels(data: ChartKitData): string[];
|
|
444
|
+
/** A formatter that renders numbers in the reader's locale. */
|
|
445
|
+
export declare function createDefaultValueFormat(locale?: string, emptyText?: string): ChartKitValueFormat;
|
|
446
|
+
/** Everything {@link buildChartKitTable} needs. */
|
|
447
|
+
interface ChartKitTableInput {
|
|
448
|
+
readonly data: ChartKitData;
|
|
449
|
+
readonly caption: string;
|
|
450
|
+
readonly categoryHeader: string;
|
|
451
|
+
readonly format: ChartKitValueFormat;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Builds the table equivalent of a chart from the chart's own data.
|
|
455
|
+
*
|
|
456
|
+
* This is the function the library exists for. A `<canvas>` exposes nothing to
|
|
457
|
+
* assistive technology — it is a bitmap — so every chart here also renders a
|
|
458
|
+
* real `<table>` with a caption, a header row and a header column, built here
|
|
459
|
+
* from the same {@link ChartKitData} the canvas draws. Because it is derived
|
|
460
|
+
* rather than authored, it cannot fall out of date when the data changes.
|
|
461
|
+
*/
|
|
462
|
+
export declare function buildChartKitTable(input: ChartKitTableInput): ChartKitTableModel;
|
|
463
|
+
/**
|
|
464
|
+
* The slice of `CSSStyleDeclaration` the theme reader uses. Narrowing it to
|
|
465
|
+
* this keeps the reader a pure function of resolved CSS, which is what makes
|
|
466
|
+
* it testable without a browser.
|
|
467
|
+
*/
|
|
468
|
+
interface ChartKitStyleSource {
|
|
469
|
+
getPropertyValue(property: string): string;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Builds a {@link ChartKitTheme} from resolved CSS on the chart's host.
|
|
473
|
+
*
|
|
474
|
+
* Only the palette, text colour and font have to come from anywhere: every
|
|
475
|
+
* other value is derived from the text colour's luminance, so a consumer who
|
|
476
|
+
* sets nothing at all still gets grid lines and tooltips that suit whichever
|
|
477
|
+
* surface the chart has landed on. The derivation is the whole point of
|
|
478
|
+
* reading at draw time — a dark-mode switch changes the inherited `color`, and
|
|
479
|
+
* the chart follows without any input being rebound.
|
|
480
|
+
*/
|
|
481
|
+
export declare function readChartKitTheme(style: ChartKitStyleSource, paletteOverride?: readonly string[]): ChartKitTheme;
|
|
482
|
+
/** Colour for the series or slice at `index`, cycling through the palette. */
|
|
483
|
+
export declare function paletteColor(theme: ChartKitTheme, index: number): string;
|
|
484
|
+
export type { ChartKitData, ChartKitPoint, ChartKitSeries, ChartKitStyleSource, ChartKitTableCell, ChartKitTableInput, ChartKitTableMode, ChartKitTableModel, ChartKitTableRow, ChartKitTheme, ChartKitType, ChartKitValueContext, ChartKitValueFormat };
|