@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/math.js DELETED
@@ -1,178 +0,0 @@
1
- // math.js — Pure math: scales, ticks, color ops, smoothing, decimation
2
- // No DOM, no canvas, no side effects.
3
-
4
- export const TAU = Math.PI * 2;
5
-
6
- export const clamp = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
7
- export const lerp = (a, b, t) => a + (b - a) * t;
8
-
9
- export function extent(arr, fn = (x) => x) {
10
- let mn = Infinity, mx = -Infinity;
11
- for (let i = 0; i < arr.length; i++) {
12
- const v = fn(arr[i], i);
13
- if (v < mn) mn = v;
14
- if (v > mx) mx = v;
15
- }
16
- return [mn === Infinity ? 0 : mn, mx === -Infinity ? 1 : mx];
17
- }
18
-
19
- // "Nice" tick generator for linear axes. Returns ticks at human-readable
20
- // values (1, 2, 5 × 10^k) covering the input domain.
21
- export function niceTicks(min, max, count = 5) {
22
- if (min === max) { min -= 0.5; max += 0.5; }
23
- const span = max - min;
24
- const step0 = span / Math.max(1, count);
25
- const mag = Math.pow(10, Math.floor(Math.log10(step0)));
26
- const norm = step0 / mag;
27
- let step;
28
- if (norm < 1.5) step = mag;
29
- else if (norm < 3) step = 2 * mag;
30
- else if (norm < 7) step = 5 * mag;
31
- else step = 10 * mag;
32
- const lo = Math.ceil(min / step) * step;
33
- const hi = Math.floor(max / step) * step;
34
- const ticks = [];
35
- for (let v = lo; v <= hi + step / 2; v += step) {
36
- ticks.push(Math.round(v / step) * step);
37
- }
38
- return ticks;
39
- }
40
-
41
- export function niceDomain(min, max, count = 5) {
42
- if (min === max) { min -= 0.5; max += 0.5; }
43
- const span = max - min;
44
- const step0 = span / Math.max(1, count);
45
- const mag = Math.pow(10, Math.floor(Math.log10(step0)));
46
- const norm = step0 / mag;
47
- let step;
48
- if (norm < 1.5) step = mag;
49
- else if (norm < 3) step = 2 * mag;
50
- else if (norm < 7) step = 5 * mag;
51
- else step = 10 * mag;
52
- return [Math.floor(min / step) * step, Math.ceil(max / step) * step];
53
- }
54
-
55
- // Time axis: pick a nice unit (second, minute, hour, day, week, month) and
56
- // generate ticks aligned to it. Returns timestamps in ms.
57
- const T = { sec: 1e3, min: 6e4, hour: 36e5, day: 864e5, week: 6.048e8, month: 2.628e9 };
58
- export function timeNiceTicks(minMs, maxMs, count = 6) {
59
- if (minMs === maxMs) { minMs -= 1000; maxMs += 1000; }
60
- const span = maxMs - minMs;
61
- const target = span / count;
62
- const units = [
63
- [T.sec, 1], [T.sec, 5], [T.sec, 15], [T.sec, 30],
64
- [T.min, 1], [T.min, 5], [T.min, 15], [T.min, 30],
65
- [T.hour, 1], [T.hour, 3], [T.hour, 6], [T.hour, 12],
66
- [T.day, 1], [T.day, 2], [T.week, 1],
67
- [T.month, 1], [T.month, 3], [T.month, 6], [T.month, 12],
68
- ];
69
- let step = T.sec;
70
- for (const [u, n] of units) if (u * n <= target * 1.5) step = u * n;
71
- const lo = Math.ceil(minMs / step) * step;
72
- const ticks = [];
73
- for (let v = lo; v <= maxMs; v += step) ticks.push(v);
74
- return ticks;
75
- }
76
-
77
- export function timeFormat(step) {
78
- if (step < T.min) return (t) => new Date(t).toISOString().slice(11, 19);
79
- if (step < T.hour) return (t) => new Date(t).toISOString().slice(11, 16);
80
- if (step < T.day) return (t) => new Date(t).toISOString().slice(11, 16);
81
- if (step < T.month) return (t) => new Date(t).toISOString().slice(5, 10);
82
- return (t) => new Date(t).toISOString().slice(0, 7);
83
- }
84
-
85
- // Min-max decimation: when N points exceed pixel count, compress to ~2 per
86
- // pixel column preserving local min and max. Used for line charts with
87
- // huge datasets.
88
- export function minMaxDecimate(data, targetCount, fn = (d) => d.value) {
89
- if (data.length <= targetCount) return data;
90
- const bucket = data.length / targetCount;
91
- const out = [];
92
- for (let i = 0; i < targetCount; i++) {
93
- const lo = Math.floor(i * bucket);
94
- const hi = Math.min(data.length, Math.floor((i + 1) * bucket));
95
- let mnI = lo, mxI = lo;
96
- let mn = fn(data[lo], lo), mx = mn;
97
- for (let j = lo + 1; j < hi; j++) {
98
- const v = fn(data[j], j);
99
- if (v < mn) { mn = v; mnI = j; }
100
- if (v > mx) { mx = v; mxI = j; }
101
- }
102
- if (mnI < mxI) { out.push(data[mnI]); out.push(data[mxI]); }
103
- else { out.push(data[mxI]); out.push(data[mnI]); }
104
- }
105
- return out;
106
- }
107
-
108
- export function shouldDecimate(n, pxWidth) {
109
- return n > pxWidth * 2;
110
- }
111
-
112
- // Smooth path control points (centripetal Catmull-Rom-ish). Returns array
113
- // of {c1x,c1y,c2x,c2y} to use with bezierCurveTo.
114
- export function bezierControlPoints(pts, tension = 1 / 6) {
115
- const n = pts.length;
116
- if (n < 2) return [];
117
- const cps = [];
118
- for (let i = 0; i < n - 1; i++) {
119
- const p0 = pts[i - 1] || pts[i];
120
- const p1 = pts[i];
121
- const p2 = pts[i + 1];
122
- const p3 = pts[i + 2] || p2;
123
- cps.push({
124
- c1x: p1.x + (p2.x - p0.x) * tension,
125
- c1y: p1.y + (p2.y - p0.y) * tension,
126
- c2x: p2.x - (p3.x - p1.x) * tension,
127
- c2y: p2.y - (p3.y - p1.y) * tension,
128
- });
129
- }
130
- return cps;
131
- }
132
-
133
- // Spring physics step. Used for animated transitions.
134
- export function springStep(v, tgt, vel, cfg = {}) {
135
- const stiffness = cfg.stiffness || 170;
136
- const damping = cfg.damping || 26;
137
- const dt = 1 / 60;
138
- const F = -stiffness * (v - tgt);
139
- const D = -damping * vel;
140
- const a = F + D;
141
- vel = vel + a * dt;
142
- v = v + vel * dt;
143
- const done = Math.abs(vel) < 0.05 && Math.abs(v - tgt) < 0.05;
144
- if (done) { v = tgt; vel = 0; }
145
- return { value: v, velocity: vel, done };
146
- }
147
-
148
- // Color helpers: hex/rgb/rgba parsing, alpha mixing, lightening.
149
- export function colorParse(c) {
150
- if (!c) return [0, 0, 0, 1];
151
- if (c[0] === '#') {
152
- const h = c.slice(1);
153
- if (h.length === 3) return [parseInt(h[0]+h[0],16), parseInt(h[1]+h[1],16), parseInt(h[2]+h[2],16), 1];
154
- if (h.length === 6) return [parseInt(h.slice(0,2),16), parseInt(h.slice(2,4),16), parseInt(h.slice(4,6),16), 1];
155
- if (h.length === 8) return [parseInt(h.slice(0,2),16), parseInt(h.slice(2,4),16), parseInt(h.slice(4,6),16), parseInt(h.slice(6,8),16)/255];
156
- }
157
- const m = c.match(/rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)(?:[,\s/]+([\d.]+))?\s*\)/);
158
- if (m) return [+m[1], +m[2], +m[3], m[4] !== undefined ? +m[4] : 1];
159
- return [0, 0, 0, 1];
160
- }
161
-
162
- export function colorAlpha(c, a) {
163
- const [r, g, b] = colorParse(c);
164
- return `rgba(${r|0},${g|0},${b|0},${a})`;
165
- }
166
-
167
- export function colorMix(a, b, t) {
168
- const [r1, g1, b1, a1] = colorParse(a);
169
- const [r2, g2, b2, a2] = colorParse(b);
170
- return `rgba(${(r1+(r2-r1)*t)|0},${(g1+(g2-g1)*t)|0},${(b1+(b2-b1)*t)|0},${a1+(a2-a1)*t})`;
171
- }
172
-
173
- // Default qualitative palette (8 colors, distinct hues, balanced lightness).
174
- // Lead color: #64c8ff (rgba(100,200,255,0.85) brand accent).
175
- export const PALETTE = [
176
- '#64c8ff', '#10b981', '#f59e0b', '#ef4444',
177
- '#8b5cf6', '#ec4899', '#84cc16', '#6366f1',
178
- ];