graphein 0.4.0 → 0.5.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 -21
- package/README.md +60 -60
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/package.json +60 -60
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Sachin Patney
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sachin Patney
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
# graphein
|
|
2
|
-
|
|
3
|
-
> The framework-agnostic, **zero-dependency** engine behind [Graphein](https://github.com/spatney/graphein) —
|
|
4
|
-
> a beautiful, high-performance, **agent-first** data visualization library.
|
|
5
|
-
|
|
6
|
-
One chart is one JSON object. Hand the engine a declarative, JSON-serializable
|
|
7
|
-
`ChartSpec` and it renders Tableau-class visuals with a tiny hybrid Canvas2D + DOM core —
|
|
8
|
-
scales, ticks, color, shapes, the pivot engine, and the renderer are all hand-written
|
|
9
|
-
(no D3/charting dependencies).
|
|
10
|
-
|
|
11
|
-
Install the zero-dependency engine:
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npm install graphein
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import { render, type ChartSpec } from 'graphein';
|
|
19
|
-
|
|
20
|
-
const spec: ChartSpec = {
|
|
21
|
-
type: 'line',
|
|
22
|
-
title: 'Monthly active users',
|
|
23
|
-
data: [
|
|
24
|
-
{ month: '2024-01', users: 4200 },
|
|
25
|
-
{ month: '2024-02', users: 4650 },
|
|
26
|
-
{ month: '2024-03', users: 5010 },
|
|
27
|
-
],
|
|
28
|
-
encoding: {
|
|
29
|
-
x: { field: 'month', type: 'temporal' },
|
|
30
|
-
y: { field: 'users', type: 'quantitative', format: ',d' },
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const chart = render('#app', spec);
|
|
35
|
-
chart.update(nextSpec); // new data/config (animated)
|
|
36
|
-
chart.resize(); // re-measure after a layout change
|
|
37
|
-
chart.destroy(); // tear down
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Chart types
|
|
41
|
-
|
|
42
|
-
`line` · `area` · `bar` · `scatter` · `pie`/donut · `heatmap` · `kpi` · `table` ·
|
|
43
|
-
`matrix` (pivot) · `box` (box-and-whisker) · `sankey` · `choropleth`.
|
|
44
|
-
|
|
45
|
-
## Validation
|
|
46
|
-
|
|
47
|
-
```ts
|
|
48
|
-
import { validateSpec } from 'graphein';
|
|
49
|
-
|
|
50
|
-
const { valid, errors, warnings } = validateSpec(spec);
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Documentation
|
|
54
|
-
|
|
55
|
-
- [Agent Guide](https://github.com/spatney/graphein/blob/main/docs/agent-guide.md)
|
|
56
|
-
- [Spec Reference](https://github.com/spatney/graphein/blob/main/docs/spec-reference.md)
|
|
57
|
-
- [JSON Schema](https://github.com/spatney/graphein/blob/main/docs/chart-spec.schema.json)
|
|
58
|
-
- [Examples](https://github.com/spatney/graphein/tree/main/docs/examples)
|
|
59
|
-
|
|
60
|
-
MIT © Sachin Patney
|
|
1
|
+
# graphein
|
|
2
|
+
|
|
3
|
+
> The framework-agnostic, **zero-dependency** engine behind [Graphein](https://github.com/spatney/graphein) —
|
|
4
|
+
> a beautiful, high-performance, **agent-first** data visualization library.
|
|
5
|
+
|
|
6
|
+
One chart is one JSON object. Hand the engine a declarative, JSON-serializable
|
|
7
|
+
`ChartSpec` and it renders Tableau-class visuals with a tiny hybrid Canvas2D + DOM core —
|
|
8
|
+
scales, ticks, color, shapes, the pivot engine, and the renderer are all hand-written
|
|
9
|
+
(no D3/charting dependencies).
|
|
10
|
+
|
|
11
|
+
Install the zero-dependency engine:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install graphein
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { render, type ChartSpec } from 'graphein';
|
|
19
|
+
|
|
20
|
+
const spec: ChartSpec = {
|
|
21
|
+
type: 'line',
|
|
22
|
+
title: 'Monthly active users',
|
|
23
|
+
data: [
|
|
24
|
+
{ month: '2024-01', users: 4200 },
|
|
25
|
+
{ month: '2024-02', users: 4650 },
|
|
26
|
+
{ month: '2024-03', users: 5010 },
|
|
27
|
+
],
|
|
28
|
+
encoding: {
|
|
29
|
+
x: { field: 'month', type: 'temporal' },
|
|
30
|
+
y: { field: 'users', type: 'quantitative', format: ',d' },
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const chart = render('#app', spec);
|
|
35
|
+
chart.update(nextSpec); // new data/config (animated)
|
|
36
|
+
chart.resize(); // re-measure after a layout change
|
|
37
|
+
chart.destroy(); // tear down
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Chart types
|
|
41
|
+
|
|
42
|
+
`line` · `area` · `bar` · `scatter` · `pie`/donut · `heatmap` · `kpi` · `table` ·
|
|
43
|
+
`matrix` (pivot) · `box` (box-and-whisker) · `sankey` · `choropleth`.
|
|
44
|
+
|
|
45
|
+
## Validation
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { validateSpec } from 'graphein';
|
|
49
|
+
|
|
50
|
+
const { valid, errors, warnings } = validateSpec(spec);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Documentation
|
|
54
|
+
|
|
55
|
+
- [Agent Guide](https://github.com/spatney/graphein/blob/main/docs/agent-guide.md)
|
|
56
|
+
- [Spec Reference](https://github.com/spatney/graphein/blob/main/docs/spec-reference.md)
|
|
57
|
+
- [JSON Schema](https://github.com/spatney/graphein/blob/main/docs/chart-spec.schema.json)
|
|
58
|
+
- [Examples](https://github.com/spatney/graphein/tree/main/docs/examples)
|
|
59
|
+
|
|
60
|
+
MIT © Sachin Patney
|
package/dist/index.js
CHANGED
|
@@ -2635,6 +2635,9 @@ function analyzeCategory(rows, categoryField, measureField) {
|
|
|
2635
2635
|
});
|
|
2636
2636
|
return { count: order.length, total, top, bottom, topShare: total > 0 ? top.value / total : 0 };
|
|
2637
2637
|
}
|
|
2638
|
+
function xLabel(x) {
|
|
2639
|
+
return x instanceof Date ? prettyDate(x) : toKey(x);
|
|
2640
|
+
}
|
|
2638
2641
|
function analyzeSeriesFamily(rows, xField, yField, seriesField) {
|
|
2639
2642
|
const readX = accessor(xField);
|
|
2640
2643
|
const readY = accessor(yField);
|
|
@@ -2653,7 +2656,7 @@ function analyzeSeriesFamily(rows, xField, yField, seriesField) {
|
|
|
2653
2656
|
}
|
|
2654
2657
|
const x = readX(d);
|
|
2655
2658
|
g.values.push(y);
|
|
2656
|
-
g.labels.push(
|
|
2659
|
+
g.labels.push(xLabel(x));
|
|
2657
2660
|
g.raws.push(x);
|
|
2658
2661
|
}
|
|
2659
2662
|
const out = [];
|