@swiftplot/react 0.5.1 → 0.6.0-rc.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/README.md +8 -7
- package/dist/bind.js +43 -12
- package/dist/index.js +17 -17
- package/package.json +11 -7
- package/styles.css +10 -0
package/README.md
CHANGED
|
@@ -14,7 +14,8 @@ project stands, what it lacks and what 1.0 needs: [swiftplot.dev/status](https:/
|
|
|
14
14
|
[Discussions](https://github.com/GusevP/swiftplot/discussions).
|
|
15
15
|
|
|
16
16
|
**For AI coding assistants:** [`llms-full.txt`](https://swiftplot.dev/llms-full.txt) is a guide to writing code with
|
|
17
|
-
swiftplot, and [`llms.txt`](https://swiftplot.dev/llms.txt) its index.
|
|
17
|
+
swiftplot, and [`llms.txt`](https://swiftplot.dev/llms.txt) its index. `swiftplot/schema.json` is a JSON Schema of the
|
|
18
|
+
easy charts' props, for a model that answers with a chart as JSON.
|
|
18
19
|
|
|
19
20
|
<img src="https://raw.githubusercontent.com/GusevP/swiftplot/main/assets/pan.gif" alt="Panning and zooming a line of a million points" width="640" />
|
|
20
21
|
|
|
@@ -97,12 +98,12 @@ Gzip size of the minified bundle of each entry in `site/scripts/size/`, built fr
|
|
|
97
98
|
|
|
98
99
|
| entry | imports | KB |
|
|
99
100
|
| ------------------ | ------------------------------------------------------- | ---: |
|
|
100
|
-
| plot-line | `plot` and `line` from `swiftplot` |
|
|
101
|
-
| plot-line-features | the same with `tooltip`, `legend`, `zoom` and `animate` |
|
|
102
|
-
| line-chart | `lineChart` from `swiftplot/charts` |
|
|
103
|
-
| all-charts | every chart of `swiftplot/charts` |
|
|
104
|
-
| react-line-chart | `LineChart` from `@swiftplot/react`, React not counted |
|
|
105
|
-
| vue-line-chart | `LineChart` from `@swiftplot/vue`, Vue not counted |
|
|
101
|
+
| plot-line | `plot` and `line` from `swiftplot` | 15.4 |
|
|
102
|
+
| plot-line-features | the same with `tooltip`, `legend`, `zoom` and `animate` | 20.7 |
|
|
103
|
+
| line-chart | `lineChart` from `swiftplot/charts` | 40.2 |
|
|
104
|
+
| all-charts | every chart of `swiftplot/charts` | 57.6 |
|
|
105
|
+
| react-line-chart | `LineChart` from `@swiftplot/react`, React not counted | 42.0 |
|
|
106
|
+
| vue-line-chart | `LineChart` from `@swiftplot/vue`, Vue not counted | 42.5 |
|
|
106
107
|
|
|
107
108
|
On chart-bench's page, which bundles `plot`, `line`, `area`, `ticks`, `dots`, `tooltip` and `animate`, swiftplot 0.5.0 adds 19.3 KB and uPlot 23.9 KB (`results/bundle.json`: the arm's page less the same page with no chart). uPlot ships more in its size: it is one module that comes whole, with its legend, cursor, selection and series types whether a page uses them or not.
|
|
108
109
|
|
package/dist/bind.js
CHANGED
|
@@ -32,11 +32,24 @@ const keyOf = (e, { data, ...rest }) => [
|
|
|
32
32
|
];
|
|
33
33
|
const callback = (k) => /^on[A-Z]/.test(k);
|
|
34
34
|
const changed = (was, now) => [...new Set([...Object.keys(was), ...Object.keys(now)])].filter(k => !Object.is(was[k], now[k]));
|
|
35
|
+
// oxlint-disable-next-line no-restricted-globals -- a check for a DOM, made once on load with no element to ask
|
|
35
36
|
const useLayout = typeof document === 'undefined' ? useEffect : useLayoutEffect;
|
|
36
37
|
const FALLBACK = 'data-swiftplot-fallback';
|
|
37
38
|
const LAYER = 'data-swiftplot-fallback-layer';
|
|
39
|
+
// The text of styles.css, whose counter-reset tells a probe that the shipped file already applies in its root.
|
|
40
|
+
const RULE = `@layer swiftplot {
|
|
41
|
+
:where([data-swiftplot-fallback='fill']) {
|
|
42
|
+
height: 100%;
|
|
43
|
+
counter-reset: swiftplot-fallback;
|
|
44
|
+
}
|
|
45
|
+
:where([data-swiftplot-fallback='fixed']) {
|
|
46
|
+
height: 300px;
|
|
47
|
+
counter-reset: swiftplot-fallback;
|
|
48
|
+
}
|
|
49
|
+
}\n`;
|
|
38
50
|
const styles = new WeakMap();
|
|
39
|
-
|
|
51
|
+
const detached = new WeakMap();
|
|
52
|
+
const windowOf = (el) => (el.ownerDocument?.defaultView ?? globalThis);
|
|
40
53
|
/**
|
|
41
54
|
* Lowest priority: with no height from the app, fill a parent that has one, else 300 px. A rule in the
|
|
42
55
|
* first cascade layer of the host's document or shadow root rather than an inline height, so a height
|
|
@@ -44,27 +57,42 @@ let detached;
|
|
|
44
57
|
* once it is laid out.
|
|
45
58
|
*/
|
|
46
59
|
function fallback(el) {
|
|
60
|
+
const win = windowOf(el);
|
|
61
|
+
let observer = detached.get(win);
|
|
47
62
|
if (!el.isConnected) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
if (!observer) {
|
|
64
|
+
observer = new win.ResizeObserver(entries => {
|
|
65
|
+
for (const { target } of entries)
|
|
66
|
+
if (target.isConnected)
|
|
67
|
+
fallback(target);
|
|
68
|
+
});
|
|
69
|
+
detached.set(win, observer);
|
|
70
|
+
}
|
|
71
|
+
observer.observe(el);
|
|
53
72
|
return;
|
|
54
73
|
}
|
|
55
|
-
|
|
74
|
+
observer?.unobserve(el);
|
|
56
75
|
const contain = el.style.contain;
|
|
57
76
|
el.removeAttribute(FALLBACK);
|
|
58
77
|
el.style.contain = 'size';
|
|
59
|
-
const cs = getComputedStyle(el);
|
|
78
|
+
const cs = win.getComputedStyle(el);
|
|
60
79
|
for (const h of ['fill', 'fixed']) {
|
|
61
80
|
if (el.clientHeight - parseFloat(cs.paddingTop) - parseFloat(cs.paddingBottom) > 0)
|
|
62
81
|
break;
|
|
63
|
-
sheet(el);
|
|
64
82
|
el.setAttribute(FALLBACK, h);
|
|
83
|
+
if (h === 'fill' && !shipped(el))
|
|
84
|
+
sheet(el);
|
|
65
85
|
}
|
|
66
86
|
el.style.contain = contain;
|
|
67
87
|
}
|
|
88
|
+
// A probe of its own rather than the host, whose counter-reset the app's CSS may set.
|
|
89
|
+
function shipped(el) {
|
|
90
|
+
const probe = el.appendChild(el.ownerDocument.createElement('swiftplot-probe'));
|
|
91
|
+
probe.setAttribute(FALLBACK, 'fill');
|
|
92
|
+
const on = windowOf(el).getComputedStyle(probe).counterReset === 'swiftplot-fallback 0';
|
|
93
|
+
probe.remove();
|
|
94
|
+
return on;
|
|
95
|
+
}
|
|
68
96
|
function sheet(el) {
|
|
69
97
|
const doc = el.ownerDocument;
|
|
70
98
|
const root = el.getRootNode();
|
|
@@ -80,14 +108,17 @@ function sheet(el) {
|
|
|
80
108
|
}
|
|
81
109
|
const style = doc.createElement('style');
|
|
82
110
|
style.setAttribute(LAYER, '');
|
|
83
|
-
|
|
111
|
+
// A script's nonce would not pass style-src, and a page may give scripts and styles different ones.
|
|
112
|
+
style.nonce =
|
|
113
|
+
[...doc.querySelectorAll('style[nonce], link[rel~="stylesheet" i][nonce]')].find(e => e.nonce)?.nonce ?? '';
|
|
114
|
+
style.textContent = RULE;
|
|
84
115
|
parent.prepend(style);
|
|
85
116
|
styles.set(root, style);
|
|
86
117
|
// A sheet put first later (React 19 does so with its first precedence sheet) would declare its layers ahead of ours.
|
|
87
118
|
// A script that also keeps its node first would move it back forever, so a burst of moves ends the watch.
|
|
88
119
|
let moves = 0;
|
|
89
120
|
let since = 0;
|
|
90
|
-
const first = new MutationObserver(() => {
|
|
121
|
+
const first = new (windowOf(el).MutationObserver)(() => {
|
|
91
122
|
if (style.parentNode !== parent)
|
|
92
123
|
return first.disconnect();
|
|
93
124
|
const head = parent.firstChild;
|
|
@@ -210,7 +241,7 @@ export function bind(chart) {
|
|
|
210
241
|
useLayout(() => {
|
|
211
242
|
const el = host.current;
|
|
212
243
|
return () => {
|
|
213
|
-
detached?.unobserve(el);
|
|
244
|
+
detached.get(windowOf(el))?.unobserve(el);
|
|
214
245
|
bound.current.chart?.destroy();
|
|
215
246
|
bound.current = {};
|
|
216
247
|
store.clear('layout');
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { areaChart, barChart, boxPlotChart, candlestickChart, comboChart, funnelChart, heatmapChart, histogramChart, lineChart, mount, pieChart, radarChart, radialBarChart, sankeyChart, scatterChart, sunburstChart, treemapChart, } from 'swiftplot/charts';
|
|
3
3
|
import { bind } from './bind.js';
|
|
4
|
-
export const LineChart = bind(lineChart);
|
|
5
|
-
export const AreaChart = bind(areaChart);
|
|
6
|
-
export const BarChart = bind(barChart);
|
|
7
|
-
export const ScatterChart = bind(scatterChart);
|
|
8
|
-
export const PieChart = bind(pieChart);
|
|
9
|
-
export const FunnelChart = bind(funnelChart);
|
|
10
|
-
export const RadialBarChart = bind(radialBarChart);
|
|
11
|
-
export const RadarChart = bind(radarChart);
|
|
12
|
-
export const HeatmapChart = bind(heatmapChart);
|
|
13
|
-
export const HistogramChart = bind(histogramChart);
|
|
14
|
-
export const BoxPlotChart = bind(boxPlotChart);
|
|
15
|
-
export const CandlestickChart = bind(candlestickChart);
|
|
16
|
-
export const ComboChart = bind(comboChart);
|
|
17
|
-
export const SankeyChart = bind(sankeyChart);
|
|
18
|
-
export const TreemapChart = bind(treemapChart);
|
|
19
|
-
export const SunburstChart = bind(sunburstChart);
|
|
20
|
-
export const Plot = bind(mount);
|
|
4
|
+
export const LineChart = /*#__PURE__*/ bind(lineChart);
|
|
5
|
+
export const AreaChart = /*#__PURE__*/ bind(areaChart);
|
|
6
|
+
export const BarChart = /*#__PURE__*/ bind(barChart);
|
|
7
|
+
export const ScatterChart = /*#__PURE__*/ bind(scatterChart);
|
|
8
|
+
export const PieChart = /*#__PURE__*/ bind(pieChart);
|
|
9
|
+
export const FunnelChart = /*#__PURE__*/ bind(funnelChart);
|
|
10
|
+
export const RadialBarChart = /*#__PURE__*/ bind(radialBarChart);
|
|
11
|
+
export const RadarChart = /*#__PURE__*/ bind(radarChart);
|
|
12
|
+
export const HeatmapChart = /*#__PURE__*/ bind(heatmapChart);
|
|
13
|
+
export const HistogramChart = /*#__PURE__*/ bind(histogramChart);
|
|
14
|
+
export const BoxPlotChart = /*#__PURE__*/ bind(boxPlotChart);
|
|
15
|
+
export const CandlestickChart = /*#__PURE__*/ bind(candlestickChart);
|
|
16
|
+
export const ComboChart = /*#__PURE__*/ bind(comboChart);
|
|
17
|
+
export const SankeyChart = /*#__PURE__*/ bind(sankeyChart);
|
|
18
|
+
export const TreemapChart = /*#__PURE__*/ bind(treemapChart);
|
|
19
|
+
export const SunburstChart = /*#__PURE__*/ bind(sunburstChart);
|
|
20
|
+
export const Plot = /*#__PURE__*/ bind(mount);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swiftplot/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-rc.0",
|
|
4
4
|
"description": "React components for swiftplot charts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chart",
|
|
@@ -22,20 +22,24 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://swiftplot.dev",
|
|
24
24
|
"type": "module",
|
|
25
|
-
"sideEffects":
|
|
25
|
+
"sideEffects": [
|
|
26
|
+
"*.css"
|
|
27
|
+
],
|
|
26
28
|
"exports": {
|
|
27
29
|
".": {
|
|
28
30
|
"types": "./dist/index.d.ts",
|
|
29
31
|
"default": "./dist/index.js"
|
|
30
|
-
}
|
|
32
|
+
},
|
|
33
|
+
"./styles.css": "./styles.css"
|
|
31
34
|
},
|
|
32
35
|
"files": [
|
|
33
|
-
"dist"
|
|
36
|
+
"dist",
|
|
37
|
+
"styles.css"
|
|
34
38
|
],
|
|
35
39
|
"peerDependencies": {
|
|
36
40
|
"react": "^18.3 || ^19",
|
|
37
41
|
"react-dom": "^18.3 || ^19",
|
|
38
|
-
"swiftplot": "^0.
|
|
42
|
+
"swiftplot": "^0.6.0-rc.0"
|
|
39
43
|
},
|
|
40
44
|
"devDependencies": {
|
|
41
45
|
"@types/node": "^24.19.2",
|
|
@@ -47,12 +51,12 @@
|
|
|
47
51
|
"react-dom": "^19.3.1",
|
|
48
52
|
"typescript": "^7.0.2",
|
|
49
53
|
"vitest": "^5.1.1",
|
|
50
|
-
"swiftplot": "0.
|
|
54
|
+
"swiftplot": "0.6.0-rc.0"
|
|
51
55
|
},
|
|
52
56
|
"scripts": {
|
|
53
57
|
"build": "tsc -p tsconfig.build.json",
|
|
54
58
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.node.json",
|
|
55
|
-
"test": "vitest run",
|
|
59
|
+
"test": "vitest run && NODE_ENV=production vitest run -c vitest.production.config.ts --reporter=verbose",
|
|
56
60
|
"test:import": "node test/import.mjs"
|
|
57
61
|
}
|
|
58
62
|
}
|