@swiftplot/react 0.5.1 → 0.5.2
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 +4 -4
- package/dist/bind.js +18 -10
- package/dist/index.js +17 -17
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -98,11 +98,11 @@ Gzip size of the minified bundle of each entry in `site/scripts/size/`, built fr
|
|
|
98
98
|
| entry | imports | KB |
|
|
99
99
|
| ------------------ | ------------------------------------------------------- | ---: |
|
|
100
100
|
| plot-line | `plot` and `line` from `swiftplot` | 14.4 |
|
|
101
|
-
| plot-line-features | the same with `tooltip`, `legend`, `zoom` and `animate` | 19.
|
|
102
|
-
| line-chart | `lineChart` from `swiftplot/charts` | 37.
|
|
101
|
+
| plot-line-features | the same with `tooltip`, `legend`, `zoom` and `animate` | 19.1 |
|
|
102
|
+
| line-chart | `lineChart` from `swiftplot/charts` | 37.6 |
|
|
103
103
|
| all-charts | every chart of `swiftplot/charts` | 54.7 |
|
|
104
|
-
| react-line-chart | `LineChart` from `@swiftplot/react`, React not counted |
|
|
105
|
-
| vue-line-chart | `LineChart` from `@swiftplot/vue`, Vue not counted |
|
|
104
|
+
| react-line-chart | `LineChart` from `@swiftplot/react`, React not counted | 39.3 |
|
|
105
|
+
| vue-line-chart | `LineChart` from `@swiftplot/vue`, Vue not counted | 39.8 |
|
|
106
106
|
|
|
107
107
|
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
108
|
|
package/dist/bind.js
CHANGED
|
@@ -32,11 +32,13 @@ 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';
|
|
38
39
|
const styles = new WeakMap();
|
|
39
|
-
|
|
40
|
+
const detached = new WeakMap();
|
|
41
|
+
const windowOf = (el) => (el.ownerDocument?.defaultView ?? globalThis);
|
|
40
42
|
/**
|
|
41
43
|
* Lowest priority: with no height from the app, fill a parent that has one, else 300 px. A rule in the
|
|
42
44
|
* first cascade layer of the host's document or shadow root rather than an inline height, so a height
|
|
@@ -44,19 +46,25 @@ let detached;
|
|
|
44
46
|
* once it is laid out.
|
|
45
47
|
*/
|
|
46
48
|
function fallback(el) {
|
|
49
|
+
const win = windowOf(el);
|
|
50
|
+
let observer = detached.get(win);
|
|
47
51
|
if (!el.isConnected) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
if (!observer) {
|
|
53
|
+
observer = new win.ResizeObserver(entries => {
|
|
54
|
+
for (const { target } of entries)
|
|
55
|
+
if (target.isConnected)
|
|
56
|
+
fallback(target);
|
|
57
|
+
});
|
|
58
|
+
detached.set(win, observer);
|
|
59
|
+
}
|
|
60
|
+
observer.observe(el);
|
|
53
61
|
return;
|
|
54
62
|
}
|
|
55
|
-
|
|
63
|
+
observer?.unobserve(el);
|
|
56
64
|
const contain = el.style.contain;
|
|
57
65
|
el.removeAttribute(FALLBACK);
|
|
58
66
|
el.style.contain = 'size';
|
|
59
|
-
const cs = getComputedStyle(el);
|
|
67
|
+
const cs = win.getComputedStyle(el);
|
|
60
68
|
for (const h of ['fill', 'fixed']) {
|
|
61
69
|
if (el.clientHeight - parseFloat(cs.paddingTop) - parseFloat(cs.paddingBottom) > 0)
|
|
62
70
|
break;
|
|
@@ -87,7 +95,7 @@ function sheet(el) {
|
|
|
87
95
|
// A script that also keeps its node first would move it back forever, so a burst of moves ends the watch.
|
|
88
96
|
let moves = 0;
|
|
89
97
|
let since = 0;
|
|
90
|
-
const first = new MutationObserver(() => {
|
|
98
|
+
const first = new (windowOf(el).MutationObserver)(() => {
|
|
91
99
|
if (style.parentNode !== parent)
|
|
92
100
|
return first.disconnect();
|
|
93
101
|
const head = parent.firstChild;
|
|
@@ -210,7 +218,7 @@ export function bind(chart) {
|
|
|
210
218
|
useLayout(() => {
|
|
211
219
|
const el = host.current;
|
|
212
220
|
return () => {
|
|
213
|
-
detached?.unobserve(el);
|
|
221
|
+
detached.get(windowOf(el))?.unobserve(el);
|
|
214
222
|
bound.current.chart?.destroy();
|
|
215
223
|
bound.current = {};
|
|
216
224
|
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.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "React components for swiftplot charts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chart",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": "^18.3 || ^19",
|
|
37
37
|
"react-dom": "^18.3 || ^19",
|
|
38
|
-
"swiftplot": "^0.5.
|
|
38
|
+
"swiftplot": "^0.5.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^24.19.2",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"react-dom": "^19.3.1",
|
|
48
48
|
"typescript": "^7.0.2",
|
|
49
49
|
"vitest": "^5.1.1",
|
|
50
|
-
"swiftplot": "0.5.
|
|
50
|
+
"swiftplot": "0.5.2"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "tsc -p tsconfig.build.json",
|
|
54
54
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.node.json",
|
|
55
|
-
"test": "vitest run",
|
|
55
|
+
"test": "vitest run && NODE_ENV=production vitest run -c vitest.production.config.ts --reporter=verbose",
|
|
56
56
|
"test:import": "node test/import.mjs"
|
|
57
57
|
}
|
|
58
58
|
}
|