goro-charts 1.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.
- package/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/README.md +530 -0
- package/dist/charts/area-chart.d.ts +13 -0
- package/dist/charts/chart-base.d.ts +248 -0
- package/dist/charts/line-chart.d.ts +13 -0
- package/dist/charts/scatter-chart.d.ts +13 -0
- package/dist/data/monotonic-extent.d.ts +39 -0
- package/dist/data/ring-buffer.d.ts +44 -0
- package/dist/data/series-store.d.ts +65 -0
- package/dist/defaults.d.ts +13 -0
- package/dist/goro-charts.js +990 -0
- package/dist/goro-charts.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/math/format.d.ts +16 -0
- package/dist/math/scale.d.ts +33 -0
- package/dist/math/ticks.d.ts +16 -0
- package/dist/presets.d.ts +17 -0
- package/dist/render/area.d.ts +15 -0
- package/dist/render/axes.d.ts +14 -0
- package/dist/render/crosshair.d.ts +36 -0
- package/dist/render/legend.d.ts +10 -0
- package/dist/render/line.d.ts +20 -0
- package/dist/render/scatter.d.ts +11 -0
- package/dist/render/shape.d.ts +5 -0
- package/dist/render/stacked-band.d.ts +40 -0
- package/dist/render/surface.d.ts +32 -0
- package/dist/types.d.ts +142 -0
- package/package.json +78 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Shared types and the data/render contract.
|
|
3
|
+
*
|
|
4
|
+
* `ChartOpts` is the public configuration surface shared by all chart types.
|
|
5
|
+
* `SeriesConfig` drives per-series styling. `PlotRect` and `Domain` are small
|
|
6
|
+
* value objects passed to the pure renderers. `SeriesView` is the read-only
|
|
7
|
+
* contract the renderers depend on instead of the concrete data store — it
|
|
8
|
+
* decouples `render/` from `data/` so either can change independently.
|
|
9
|
+
*/
|
|
10
|
+
/** Per-series visual configuration. */
|
|
11
|
+
export interface SeriesConfig {
|
|
12
|
+
/** Display name for legends and the crosshair tooltip. */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Line / dot colour for this series. */
|
|
15
|
+
color: string;
|
|
16
|
+
/** Line stroke width (AreaChart: top stroke width). */
|
|
17
|
+
lineWidth?: number;
|
|
18
|
+
/** Line dash pattern, e.g. `[8, 4]` for dashed lines. */
|
|
19
|
+
dash?: number[];
|
|
20
|
+
/** Area fill colour (only meaningful on an {@link AreaChart}). */
|
|
21
|
+
fillColor?: string;
|
|
22
|
+
/** Area fill opacity 0–1 (only meaningful on an {@link AreaChart}). */
|
|
23
|
+
fillOpacity?: number;
|
|
24
|
+
/** Which Y axis this series maps to. Default `'left'`. */
|
|
25
|
+
yAxis?: 'left' | 'right';
|
|
26
|
+
/**
|
|
27
|
+
* Stack group identifier. Series with the same `stack` value render
|
|
28
|
+
* cumulatively — each series' Y values are added to the previous series'
|
|
29
|
+
* accumulated Y within the same group. Meaningful only on AreaChart.
|
|
30
|
+
*/
|
|
31
|
+
stack?: string;
|
|
32
|
+
/** Fixed Y lower bound for this series only (overrides the grid domain). */
|
|
33
|
+
yMin?: number;
|
|
34
|
+
/** Fixed Y upper bound for this series only (overrides the grid domain). */
|
|
35
|
+
yMax?: number;
|
|
36
|
+
}
|
|
37
|
+
/** Public configuration for a {@link LineChart} or {@link AreaChart}. */
|
|
38
|
+
export interface ChartOpts {
|
|
39
|
+
/**
|
|
40
|
+
* One entry per series. Each entry owns colour, width, and optional
|
|
41
|
+
* name / fill properties. When omitted a single default series is used.
|
|
42
|
+
*/
|
|
43
|
+
series?: SeriesConfig[];
|
|
44
|
+
/** Padding [top, right, bottom, left] in CSS pixels. */
|
|
45
|
+
padding?: [number, number, number, number];
|
|
46
|
+
/** Per-series fallback line colour (overridden by SeriesConfig.color). */
|
|
47
|
+
lineColor?: string;
|
|
48
|
+
/** Per-series fallback line width (overridden by SeriesConfig.lineWidth). */
|
|
49
|
+
lineWidth?: number;
|
|
50
|
+
/** Per-series fallback area fill colour (overridden by SeriesConfig.fillColor). */
|
|
51
|
+
fillColor?: string;
|
|
52
|
+
/** Per-series fallback area fill opacity (overridden by SeriesConfig.fillOpacity). */
|
|
53
|
+
fillOpacity?: number;
|
|
54
|
+
/** Per-series fallback crosshair marker colour. */
|
|
55
|
+
pointColor?: string;
|
|
56
|
+
gridColor?: string;
|
|
57
|
+
axisColor?: string;
|
|
58
|
+
textColor?: string;
|
|
59
|
+
fontSize?: number;
|
|
60
|
+
fontFamily?: string;
|
|
61
|
+
crosshairColor?: string;
|
|
62
|
+
crosshairWidth?: number;
|
|
63
|
+
pointRadius?: number;
|
|
64
|
+
bgColor?: string;
|
|
65
|
+
/** Approximate number of X-axis ticks. */
|
|
66
|
+
xTicks?: number;
|
|
67
|
+
/** Approximate number of Y-axis ticks. */
|
|
68
|
+
yTicks?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Enable streaming "ring" mode with a sliding window of this many points.
|
|
71
|
+
* Activates append()/appendBatch(); setData() still works (snapshot mode).
|
|
72
|
+
*/
|
|
73
|
+
maxPoints?: number;
|
|
74
|
+
/**
|
|
75
|
+
* When true, append()/appendBatch() coalesce into a single
|
|
76
|
+
* requestAnimationFrame draw instead of drawing synchronously — many
|
|
77
|
+
* appends per frame collapse to one paint. Still demand-driven (no idle loop).
|
|
78
|
+
*/
|
|
79
|
+
autoDraw?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Fixed Y-axis lower bound. When set the grid domain is pinned to this
|
|
82
|
+
* value instead of auto-expanding from data. Pair with {@link yMax}.
|
|
83
|
+
*/
|
|
84
|
+
yMin?: number;
|
|
85
|
+
/**
|
|
86
|
+
* Fixed Y-axis upper bound. When set the grid domain is pinned to this
|
|
87
|
+
* value instead of auto-expanding from data. Pair with {@link yMin}.
|
|
88
|
+
*/
|
|
89
|
+
yMax?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Max dots drawn by a {@link ScatterChart} before stride-thinning kicks
|
|
92
|
+
* in (default 2000).
|
|
93
|
+
*/
|
|
94
|
+
maxDots?: number;
|
|
95
|
+
}
|
|
96
|
+
/** Fully-resolved options (every field present). */
|
|
97
|
+
export type ResolvedOpts = Required<ChartOpts>;
|
|
98
|
+
/** Plot area rectangle in CSS pixels, padding already applied. */
|
|
99
|
+
export interface PlotRect {
|
|
100
|
+
/** Left edge (x of the plot origin). */
|
|
101
|
+
x: number;
|
|
102
|
+
/** Top edge (y of the plot origin). */
|
|
103
|
+
y: number;
|
|
104
|
+
/** Plot width. */
|
|
105
|
+
w: number;
|
|
106
|
+
/** Plot height. */
|
|
107
|
+
h: number;
|
|
108
|
+
}
|
|
109
|
+
/** Data-space extents for both axes. */
|
|
110
|
+
export interface Domain {
|
|
111
|
+
xMin: number;
|
|
112
|
+
xMax: number;
|
|
113
|
+
yMin: number;
|
|
114
|
+
yMax: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Read-only view of the current series window that renderers consume.
|
|
118
|
+
*
|
|
119
|
+
* Data is stored columnar in physical backing arrays addressed through a
|
|
120
|
+
* logical window `[0, count)`. In snapshot mode the logical and physical
|
|
121
|
+
* indices coincide; in ring mode the window wraps, so `physOf` translates a
|
|
122
|
+
* logical index to its physical slot. x is sorted in logical order.
|
|
123
|
+
*/
|
|
124
|
+
export interface SeriesView extends Domain {
|
|
125
|
+
/** Physical backing array for x (length `cap`). */
|
|
126
|
+
readonly xArr: Float64Array<ArrayBufferLike>;
|
|
127
|
+
/** Physical backing array for y (length `cap`). */
|
|
128
|
+
readonly yArr: Float64Array<ArrayBufferLike>;
|
|
129
|
+
/** Physical index of logical position 0 (the oldest sample). */
|
|
130
|
+
readonly head: number;
|
|
131
|
+
/** Number of samples currently in the window. */
|
|
132
|
+
readonly count: number;
|
|
133
|
+
/** Physical capacity of the backing arrays. */
|
|
134
|
+
readonly cap: number;
|
|
135
|
+
/** Translate a logical index [0, count) to its physical slot. */
|
|
136
|
+
physOf(logical: number): number;
|
|
137
|
+
/**
|
|
138
|
+
* Largest logical index whose x ≤ target (the left bracket), clamped to
|
|
139
|
+
* [0, count-1]. Valid even when physical storage is wrapped.
|
|
140
|
+
*/
|
|
141
|
+
bracketLogical(target: number): number;
|
|
142
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "goro-charts",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Minimal high-performance line and area chart engine. Canvas 2D, zero dependencies, framework-agnostic.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Isaac Stefanello",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/stefanelloisaac/goro-charts.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/stefanelloisaac/goro-charts#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/stefanelloisaac/goro-charts/issues"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=24"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"chart",
|
|
21
|
+
"canvas",
|
|
22
|
+
"timeseries",
|
|
23
|
+
"line-chart",
|
|
24
|
+
"area-chart",
|
|
25
|
+
"performance",
|
|
26
|
+
"multi-series",
|
|
27
|
+
"streaming",
|
|
28
|
+
"visualization",
|
|
29
|
+
"typescript"
|
|
30
|
+
],
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/goro-charts.js",
|
|
36
|
+
"default": "./dist/goro-charts.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"module": "./dist/goro-charts.js",
|
|
40
|
+
"main": "./dist/goro-charts.js",
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"files": [
|
|
43
|
+
"dist",
|
|
44
|
+
"README.md",
|
|
45
|
+
"LICENSE",
|
|
46
|
+
"CHANGELOG.md"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"dev": "vite",
|
|
50
|
+
"build": "vite build && tsc -p tsconfig.build.json && node scripts/fix-dts-imports.mjs",
|
|
51
|
+
"build:demo": "vite build --config vite.demo.config.ts",
|
|
52
|
+
"typecheck": "tsc -b",
|
|
53
|
+
"lint": "eslint .",
|
|
54
|
+
"preview": "vite preview",
|
|
55
|
+
"preview:demo": "vite preview --config vite.demo.config.ts",
|
|
56
|
+
"prepublishOnly": "npm run build",
|
|
57
|
+
"fix:all": "eslint --fix . && prettier --write .",
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"test:watch": "vitest",
|
|
60
|
+
"test:ui": "vitest --ui",
|
|
61
|
+
"test:coverage": "vitest run --coverage",
|
|
62
|
+
"bench": "node scripts/bench.mjs"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@eslint/js": "^10.0.1",
|
|
66
|
+
"@types/node": "^26.1.0",
|
|
67
|
+
"@vitest/coverage-v8": "^4.1.9",
|
|
68
|
+
"@vitest/ui": "^4.1.9",
|
|
69
|
+
"eslint": "^10.6.0",
|
|
70
|
+
"globals": "^17.7.0",
|
|
71
|
+
"happy-dom": "^20.10.6",
|
|
72
|
+
"prettier": "^3.9.4",
|
|
73
|
+
"typescript": "~6.0.2",
|
|
74
|
+
"typescript-eslint": "^8.62.1",
|
|
75
|
+
"vite": "^8.1.3",
|
|
76
|
+
"vitest": "^4.1.9"
|
|
77
|
+
}
|
|
78
|
+
}
|