@aeriz/chart 1.0.1 → 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 (73) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +64 -431
  3. package/dist/aeriz.cjs +2781 -2338
  4. package/dist/aeriz.esm.js +1859 -1459
  5. package/dist/aeriz.esm.min.js +278 -1
  6. package/dist/aeriz.js +2781 -2338
  7. package/dist/aeriz.min.cjs +282 -1
  8. package/dist/aeriz.min.js +282 -1
  9. package/dist/esm/base.js +84 -0
  10. package/dist/esm/cartesian.js +13 -0
  11. package/dist/esm/charts/area.js +9 -0
  12. package/dist/esm/charts/bar.js +4 -0
  13. package/dist/esm/charts/boxplot.js +4 -0
  14. package/dist/esm/charts/bubble.js +3 -0
  15. package/dist/esm/charts/composite.js +11 -0
  16. package/dist/esm/charts/funnel.js +3 -0
  17. package/dist/esm/charts/gauge.js +5 -0
  18. package/dist/esm/charts/grouped-bar.js +5 -0
  19. package/dist/esm/charts/hbar.js +6 -0
  20. package/dist/esm/charts/heatmap.js +7 -0
  21. package/dist/esm/charts/line.js +9 -0
  22. package/dist/esm/charts/multi-line.js +8 -0
  23. package/dist/esm/charts/pie.js +6 -0
  24. package/dist/esm/charts/polar.js +3 -0
  25. package/dist/esm/charts/radar.js +10 -0
  26. package/dist/esm/charts/realtime.js +14 -0
  27. package/dist/esm/charts/scatter.js +6 -0
  28. package/dist/esm/charts/sparkline.js +5 -0
  29. package/dist/esm/charts/stacked-bar.js +7 -0
  30. package/dist/esm/charts/treemap.js +10 -0
  31. package/dist/esm/charts/waterfall.js +5 -0
  32. package/dist/esm/engine.js +33 -0
  33. package/dist/esm/index.js +2 -0
  34. package/dist/esm/jquery.js +5 -0
  35. package/dist/esm/math.js +32 -0
  36. package/dist/esm/react.js +4 -0
  37. package/dist/esm/shallow.js +5 -0
  38. package/dist/esm/svelte.js +4 -0
  39. package/dist/esm/vue.js +4 -0
  40. package/dist/index.d.ts +323 -0
  41. package/dist/jquery.d.ts +21 -0
  42. package/dist/react.d.ts +59 -0
  43. package/dist/svelte.d.ts +56 -0
  44. package/dist/types/area.d.ts +1 -0
  45. package/dist/types/bar.d.ts +1 -0
  46. package/dist/types/boxplot.d.ts +1 -0
  47. package/dist/types/bubble.d.ts +1 -0
  48. package/dist/types/composite.d.ts +1 -0
  49. package/dist/types/funnel.d.ts +1 -0
  50. package/dist/types/gauge.d.ts +1 -0
  51. package/dist/types/grouped-bar.d.ts +1 -0
  52. package/dist/types/hbar.d.ts +1 -0
  53. package/dist/types/heatmap.d.ts +1 -0
  54. package/dist/types/line.d.ts +1 -0
  55. package/dist/types/multi-line.d.ts +1 -0
  56. package/dist/types/pie.d.ts +1 -0
  57. package/dist/types/polar.d.ts +1 -0
  58. package/dist/types/radar.d.ts +1 -0
  59. package/dist/types/realtime.d.ts +1 -0
  60. package/dist/types/scatter.d.ts +1 -0
  61. package/dist/types/sparkline.d.ts +1 -0
  62. package/dist/types/stacked-bar.d.ts +1 -0
  63. package/dist/types/treemap.d.ts +1 -0
  64. package/dist/types/waterfall.d.ts +1 -0
  65. package/dist/vue.d.ts +63 -0
  66. package/package.json +60 -29
  67. package/src/base.js +0 -562
  68. package/src/charts.js +0 -1365
  69. package/src/composite.js +0 -187
  70. package/src/engine.js +0 -287
  71. package/src/index.d.ts +0 -517
  72. package/src/index.js +0 -18
  73. package/src/math.js +0 -178
package/src/index.d.ts DELETED
@@ -1,517 +0,0 @@
1
- /**
2
- * aeriz — focused, fast canvas charts.
3
- *
4
- * 21 chart types, single rendering core, zero dependencies.
5
- *
6
- * @packageDocumentation
7
- */
8
-
9
- // ──────────────────────────────────────────────────────────────────
10
- // Common types
11
- // ──────────────────────────────────────────────────────────────────
12
-
13
- /** A CSS selector or a DOM element to mount the chart into. */
14
- export type ChartContainer = string | HTMLElement;
15
-
16
- /** Color value — anything CSS accepts. */
17
- export type Color = string;
18
-
19
- /** Tick formatter used on numeric axes. Receives the raw tick value. */
20
- export type TickFormatter = (value: number) => string;
21
-
22
- /** Categorical tick formatter — receives the raw category label. */
23
- export type CategoryTickFormatter = (label: string, index: number) => string;
24
-
25
- /** Axis scale type. `time` interprets numeric values as ms since epoch. */
26
- export type ScaleType = 'linear' | 'log' | 'time';
27
-
28
- /** Click handler signature shared by all chart types. */
29
- export type ClickHandler<H = unknown> = (
30
- hit: H | null,
31
- point: { x: number; y: number },
32
- chart: Chart<any>,
33
- ) => void;
34
-
35
- /** A single named series of numeric values, used by category-axis charts. */
36
- export interface Series {
37
- name: string;
38
- values: number[];
39
- color?: Color;
40
- hidden?: boolean;
41
- }
42
-
43
- /** A single radar-axis series — same shape as a regular Series. */
44
- export type RadarSeries = Series;
45
-
46
- // ──────────────────────────────────────────────────────────────────
47
- // Per-chart datum shapes
48
- // ──────────────────────────────────────────────────────────────────
49
-
50
- export interface BarDatum {
51
- label: string;
52
- value: number;
53
- color?: Color;
54
- }
55
-
56
- export interface ScatterDatum {
57
- x: number;
58
- y: number;
59
- group?: number | string;
60
- color?: Color;
61
- }
62
-
63
- export interface BubbleDatum extends ScatterDatum {
64
- z: number;
65
- }
66
-
67
- export interface PieDatum {
68
- label: string;
69
- value: number;
70
- color?: Color;
71
- }
72
-
73
- export interface PolarDatum {
74
- label: string;
75
- value: number;
76
- color?: Color;
77
- }
78
-
79
- export interface HeatmapDatum {
80
- x: number;
81
- y: number;
82
- value: number;
83
- }
84
-
85
- export interface BoxplotDatum {
86
- label: string;
87
- min: number;
88
- q1: number;
89
- median: number;
90
- q3: number;
91
- max: number;
92
- outliers?: number[];
93
- }
94
-
95
- export interface FunnelDatum {
96
- label: string;
97
- value: number;
98
- color?: Color;
99
- }
100
-
101
- export interface TreemapDatum {
102
- label: string;
103
- value: number;
104
- color?: Color;
105
- }
106
-
107
- export interface WaterfallDatum {
108
- label: string;
109
- value: number;
110
- /** Anchor bar — drawn at absolute height instead of as a delta. */
111
- isTotal?: boolean;
112
- color?: Color;
113
- }
114
-
115
- /** A layer in a `CompositeChart`. */
116
- export type CompositeLayer =
117
- | {
118
- type: 'bar' | 'line' | 'area';
119
- name: string;
120
- values: number[];
121
- color?: Color;
122
- /** Which y-axis the layer maps to. Default `'left'`. */
123
- axis?: 'left' | 'right';
124
- }
125
- | {
126
- type: 'scatter';
127
- name: string;
128
- values: Array<{ x: number; y: number }>;
129
- color?: Color;
130
- axis?: 'left' | 'right';
131
- };
132
-
133
- // ──────────────────────────────────────────────────────────────────
134
- // Per-chart option types
135
- // ──────────────────────────────────────────────────────────────────
136
-
137
- /** Options shared by every chart. */
138
- export interface BaseChartOptions {
139
- /** Override the auto-resolved palette. */
140
- palette?: Color[];
141
- /** Show value labels on data points / bars (chart-dependent). */
142
- dataLabels?: boolean;
143
- /** Click handler — `hit` is the chart-specific datum or `null`. */
144
- onClick?: ClickHandler<any>;
145
- }
146
-
147
- export interface BarChartOptions extends BaseChartOptions {
148
- data: BarDatum[];
149
- yTickFormat?: TickFormatter;
150
- xTickFormat?: CategoryTickFormatter;
151
- }
152
-
153
- export interface HBarChartOptions extends BaseChartOptions {
154
- data: BarDatum[];
155
- xTickFormat?: TickFormatter;
156
- yTickFormat?: CategoryTickFormatter;
157
- }
158
-
159
- export interface LineChartOptions extends BaseChartOptions {
160
- data: BarDatum[];
161
- /** Path interpolation. Default `'smooth'`. */
162
- interpolation?: 'smooth' | 'linear' | 'step';
163
- /** Render the area under the line. */
164
- fill?: boolean;
165
- /** Highlight the last data point with a dot. */
166
- lastDot?: boolean;
167
- xScale?: ScaleType;
168
- yScale?: ScaleType;
169
- yTickFormat?: TickFormatter;
170
- xTickFormat?: CategoryTickFormatter;
171
- }
172
-
173
- export interface AreaChartOptions extends BaseChartOptions {
174
- categories: string[];
175
- series: Series[];
176
- /** Stack all series. Default `false`. */
177
- stacked?: boolean;
178
- yTickFormat?: TickFormatter;
179
- xTickFormat?: CategoryTickFormatter;
180
- }
181
-
182
- export interface StackedBarChartOptions extends BaseChartOptions {
183
- categories: string[];
184
- series: Series[];
185
- yTickFormat?: TickFormatter;
186
- }
187
-
188
- export interface GroupedBarChartOptions extends BaseChartOptions {
189
- categories: string[];
190
- series: Series[];
191
- yTickFormat?: TickFormatter;
192
- }
193
-
194
- export interface MultiLineChartOptions extends BaseChartOptions {
195
- categories: string[];
196
- series: Series[];
197
- interpolation?: 'smooth' | 'linear' | 'step';
198
- yTickFormat?: TickFormatter;
199
- }
200
-
201
- export interface ScatterChartOptions extends BaseChartOptions {
202
- data: ScatterDatum[];
203
- xScale?: ScaleType;
204
- yScale?: ScaleType;
205
- xTickFormat?: TickFormatter;
206
- yTickFormat?: TickFormatter;
207
- }
208
-
209
- export interface BubbleChartOptions extends BaseChartOptions {
210
- data: BubbleDatum[];
211
- xScale?: ScaleType;
212
- yScale?: ScaleType;
213
- xTickFormat?: TickFormatter;
214
- yTickFormat?: TickFormatter;
215
- }
216
-
217
- export interface PieChartOptions extends BaseChartOptions {
218
- data: PieDatum[];
219
- /**
220
- * Donut hole. Use a number (px) for fixed size, `'auto'` for proportional,
221
- * or omit for a solid pie.
222
- */
223
- innerRadius?: number | 'auto';
224
- /** Label drawn in the center of a donut. */
225
- totalLabel?: string;
226
- centerLabel?: string;
227
- }
228
-
229
- export interface RadarChartOptions extends BaseChartOptions {
230
- axes: string[];
231
- series: RadarSeries[];
232
- }
233
-
234
- export interface PolarChartOptions extends BaseChartOptions {
235
- data: PolarDatum[];
236
- }
237
-
238
- export interface GaugeChartOptions extends BaseChartOptions {
239
- value: number;
240
- /** Maximum scale value. Default `100`. */
241
- max?: number;
242
- /** Label drawn under the gauge. */
243
- label?: string;
244
- /** Suffix appended to the displayed value, e.g. `'%'`. */
245
- unit?: string;
246
- }
247
-
248
- export interface HeatmapChartOptions extends BaseChartOptions {
249
- xLabels: string[];
250
- yLabels: string[];
251
- data: HeatmapDatum[];
252
- /** Color of the lowest cell value. */
253
- colorLow?: Color;
254
- /** Color of the highest cell value. */
255
- colorHigh?: Color;
256
- }
257
-
258
- export interface BoxplotChartOptions extends BaseChartOptions {
259
- data: BoxplotDatum[];
260
- yTickFormat?: TickFormatter;
261
- }
262
-
263
- export interface FunnelChartOptions extends BaseChartOptions {
264
- data: FunnelDatum[];
265
- }
266
-
267
- export interface TreemapChartOptions extends BaseChartOptions {
268
- data: TreemapDatum[];
269
- }
270
-
271
- export interface SparklineOptions extends BaseChartOptions {
272
- /** Plain numeric series — sparklines have no axes. */
273
- data: number[];
274
- color?: Color;
275
- fill?: boolean;
276
- lastDot?: boolean;
277
- }
278
-
279
- export interface RealtimeChartOptions extends BaseChartOptions {
280
- /** Series definitions; values are pushed in over time via `push()`. */
281
- series: Array<{ name: string; color?: Color }>;
282
- /** Number of samples to keep on screen. Default `200`. */
283
- windowSize?: number;
284
- yTickFormat?: TickFormatter;
285
- }
286
-
287
- export interface WaterfallChartOptions extends BaseChartOptions {
288
- data: WaterfallDatum[];
289
- yTickFormat?: TickFormatter;
290
- /** Color for positive deltas. */
291
- colorUp?: Color;
292
- /** Color for negative deltas. */
293
- colorDown?: Color;
294
- /** Color for total / anchor bars. */
295
- colorTotal?: Color;
296
- }
297
-
298
- export interface CompositeChartOptions extends BaseChartOptions {
299
- categories: string[];
300
- layers: CompositeLayer[];
301
- xScale?: ScaleType;
302
- yLeftTickFormat?: TickFormatter;
303
- yRightTickFormat?: TickFormatter;
304
- }
305
-
306
- // ──────────────────────────────────────────────────────────────────
307
- // Base Chart class
308
- // ──────────────────────────────────────────────────────────────────
309
-
310
- /**
311
- * Common base class for every chart.
312
- *
313
- * `O` is the concrete options shape for the subclass. Most users will
314
- * interact only through the typed subclasses (e.g. `BarChart`); this base
315
- * is exposed for advanced extension scenarios.
316
- */
317
- export class Chart<O extends BaseChartOptions = BaseChartOptions> {
318
- constructor(container: ChartContainer, options: O);
319
-
320
- readonly container: HTMLElement;
321
- options: O;
322
-
323
- /** Re-resolve theme + palette from CSS variables and redraw. */
324
- invalidate(): void;
325
-
326
- /** Replace `options.data` and animate to the new state. Returns `this`. */
327
- setData(data: O extends { data: infer D } ? D : unknown): this;
328
-
329
- /** Show a loading overlay. Returns `this`. */
330
- setLoading(message?: string): this;
331
- /** Show an empty-state overlay. Returns `this`. */
332
- setEmpty(message?: string): this;
333
- /** Show an error overlay. Returns `this`. */
334
- setError(message?: string): this;
335
- /** Clear any active overlay state and resume rendering. Returns `this`. */
336
- clearState(): this;
337
-
338
- /** Tear down listeners, observers, and remove the canvas. */
339
- destroy(): void;
340
- }
341
-
342
- // ──────────────────────────────────────────────────────────────────
343
- // Concrete chart classes
344
- // ──────────────────────────────────────────────────────────────────
345
-
346
- export class BarChart extends Chart<BarChartOptions> {
347
- constructor(container: ChartContainer, options: BarChartOptions);
348
- }
349
- export class HBarChart extends Chart<HBarChartOptions> {
350
- constructor(container: ChartContainer, options: HBarChartOptions);
351
- }
352
- export class LineChart extends Chart<LineChartOptions> {
353
- constructor(container: ChartContainer, options: LineChartOptions);
354
- }
355
- export class AreaChart extends Chart<AreaChartOptions> {
356
- constructor(container: ChartContainer, options: AreaChartOptions);
357
- }
358
- export class StackedBarChart extends Chart<StackedBarChartOptions> {
359
- constructor(container: ChartContainer, options: StackedBarChartOptions);
360
- }
361
- export class GroupedBarChart extends Chart<GroupedBarChartOptions> {
362
- constructor(container: ChartContainer, options: GroupedBarChartOptions);
363
- }
364
- export class MultiLineChart extends Chart<MultiLineChartOptions> {
365
- constructor(container: ChartContainer, options: MultiLineChartOptions);
366
- }
367
- export class ScatterChart extends Chart<ScatterChartOptions> {
368
- constructor(container: ChartContainer, options: ScatterChartOptions);
369
- }
370
- export class BubbleChart extends Chart<BubbleChartOptions> {
371
- constructor(container: ChartContainer, options: BubbleChartOptions);
372
- }
373
- export class PieChart extends Chart<PieChartOptions> {
374
- constructor(container: ChartContainer, options: PieChartOptions);
375
- }
376
- export class RadarChart extends Chart<RadarChartOptions> {
377
- constructor(container: ChartContainer, options: RadarChartOptions);
378
- }
379
- export class PolarChart extends Chart<PolarChartOptions> {
380
- constructor(container: ChartContainer, options: PolarChartOptions);
381
- }
382
-
383
- export class GaugeChart extends Chart<GaugeChartOptions> {
384
- constructor(container: ChartContainer, options: GaugeChartOptions);
385
- /** Animate the needle to a new value. */
386
- setValue(value: number): this;
387
- }
388
-
389
- export class HeatmapChart extends Chart<HeatmapChartOptions> {
390
- constructor(container: ChartContainer, options: HeatmapChartOptions);
391
- }
392
- export class BoxplotChart extends Chart<BoxplotChartOptions> {
393
- constructor(container: ChartContainer, options: BoxplotChartOptions);
394
- }
395
- export class FunnelChart extends Chart<FunnelChartOptions> {
396
- constructor(container: ChartContainer, options: FunnelChartOptions);
397
- }
398
- export class TreemapChart extends Chart<TreemapChartOptions> {
399
- constructor(container: ChartContainer, options: TreemapChartOptions);
400
- }
401
- export class Sparkline extends Chart<SparklineOptions> {
402
- constructor(container: ChartContainer, options: SparklineOptions);
403
- }
404
-
405
- export class RealtimeChart extends Chart<RealtimeChartOptions> {
406
- constructor(container: ChartContainer, options: RealtimeChartOptions);
407
- /**
408
- * Append one sample. Pass a single number for one-series charts, or an
409
- * array aligned with `options.series` for multi-series charts.
410
- */
411
- push(values: number | number[]): void;
412
- /** Drop all buffered samples. */
413
- clear(): void;
414
- }
415
-
416
- export class WaterfallChart extends Chart<WaterfallChartOptions> {
417
- constructor(container: ChartContainer, options: WaterfallChartOptions);
418
- }
419
-
420
- export class CompositeChart extends Chart<CompositeChartOptions> {
421
- constructor(container: ChartContainer, options: CompositeChartOptions);
422
- }
423
-
424
- // ──────────────────────────────────────────────────────────────────
425
- // Engine + scheduler (advanced / extension API)
426
- // ──────────────────────────────────────────────────────────────────
427
-
428
- /**
429
- * Low-level canvas drawing primitives shared by every chart. Most users
430
- * will not touch this directly — extend `Chart` and use `this.engine`.
431
- */
432
- export class Engine {
433
- constructor(canvas: HTMLCanvasElement);
434
- readonly canvas: HTMLCanvasElement;
435
- readonly ctx: CanvasRenderingContext2D;
436
- /** Logical width in CSS pixels (set by `resize()`). */
437
- readonly w: number;
438
- /** Logical height in CSS pixels (set by `resize()`). */
439
- readonly h: number;
440
- /** Device pixel ratio used for the backing buffer. */
441
- readonly dpr: number;
442
- resize(w: number, h: number, dpr?: number): void;
443
- clear(): void;
444
- }
445
-
446
- /**
447
- * Global render scheduler. Charts register themselves and are ticked on
448
- * `requestAnimationFrame` only when dirty.
449
- */
450
- export const scheduler: {
451
- schedule(chart: Chart<any>): void;
452
- fps(): number;
453
- count(): number;
454
- };
455
-
456
- /** Current render frame rate, averaged over the last ~500 ms. */
457
- export function getFPS(): number;
458
-
459
- /** Number of charts currently mounted. */
460
- export function getActiveCount(): number;
461
-
462
- // ──────────────────────────────────────────────────────────────────
463
- // Math helpers
464
- // ──────────────────────────────────────────────────────────────────
465
-
466
- /**
467
- * Default qualitative palette — 8 colors, brand accent first.
468
- *
469
- * Re-exported at the top level because every chart accepts a `palette`
470
- * option and most users only ever need this one math symbol directly.
471
- */
472
- export const PALETTE: Color[];
473
-
474
- /**
475
- * Pure helpers (scales, ticks, smoothing, color ops). Use as
476
- * `import { math } from 'aeriz'` and then `math.clamp(...)` etc.
477
- */
478
- export const math: {
479
- readonly TAU: number;
480
- clamp(v: number, lo: number, hi: number): number;
481
- lerp(a: number, b: number, t: number): number;
482
- extent<T>(arr: T[], fn?: (x: T, i: number) => number): [number, number];
483
- niceTicks(min: number, max: number, count?: number): number[];
484
- niceDomain(min: number, max: number, count?: number): [number, number];
485
- timeNiceTicks(minMs: number, maxMs: number, count?: number): number[];
486
- timeFormat(stepMs: number): (timestampMs: number) => string;
487
- minMaxDecimate<T>(
488
- data: T[],
489
- targetCount: number,
490
- fn?: (d: T, i: number) => number,
491
- ): T[];
492
- shouldDecimate(n: number, pxWidth: number): boolean;
493
- bezierControlPoints(
494
- pts: Array<{ x: number; y: number }>,
495
- tension?: number,
496
- ): Array<{ c1x: number; c1y: number; c2x: number; c2y: number }>;
497
- springStep(
498
- v: number,
499
- target: number,
500
- velocity: number,
501
- cfg?: { stiffness?: number; damping?: number },
502
- ): { value: number; velocity: number; done: boolean };
503
- colorParse(c: Color): [number, number, number, number];
504
- colorAlpha(c: Color, a: number): string;
505
- colorMix(a: Color, b: Color, t: number): string;
506
- readonly PALETTE: Color[];
507
- };
508
-
509
- // ──────────────────────────────────────────────────────────────────
510
- // Browser global (for the IIFE / CDN bundle)
511
- // ──────────────────────────────────────────────────────────────────
512
-
513
- declare global {
514
- interface Window {
515
- Aeriz?: typeof import('./index.js');
516
- }
517
- }
package/src/index.js DELETED
@@ -1,18 +0,0 @@
1
- // index.js — public API.
2
-
3
- export { Chart, getFPS, getActiveCount, scheduler } from './base.js';
4
- export { Engine } from './engine.js';
5
- export * as math from './math.js';
6
- export { PALETTE } from './math.js';
7
-
8
- export {
9
- BarChart, HBarChart, LineChart, AreaChart,
10
- StackedBarChart, GroupedBarChart, MultiLineChart,
11
- ScatterChart, BubbleChart,
12
- PieChart, RadarChart, PolarChart,
13
- GaugeChart, HeatmapChart, BoxplotChart,
14
- FunnelChart, TreemapChart, Sparkline,
15
- RealtimeChart, WaterfallChart,
16
- } from './charts.js';
17
-
18
- export { CompositeChart } from './composite.js';