@swiftplot/vue 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.d.ts +1 -1
- package/dist/bind.js +46 -13
- package/dist/index.js +41 -34
- package/package.json +10 -6
- 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.d.ts
CHANGED
|
@@ -19,5 +19,5 @@ type Shown = {
|
|
|
19
19
|
layout: Layout;
|
|
20
20
|
hover: Hover | null;
|
|
21
21
|
};
|
|
22
|
-
export declare function bind<P extends Sized, T extends Declared<P> = Declared<P>>(chart: Mount<P>, declared: T & Record<Exclude<keyof T, keyof Declared<P>>, never>): Component;
|
|
22
|
+
export declare function bind<P extends Sized, T extends Declared<P> = Declared<P>>(chart: Mount<P>, declared: () => T & Record<Exclude<keyof T, keyof Declared<P>>, never>): Component;
|
|
23
23
|
export {};
|
package/dist/bind.js
CHANGED
|
@@ -51,8 +51,20 @@ const changed = (was, now) => [...new Set([...Object.keys(was), ...Object.keys(n
|
|
|
51
51
|
const hostStyle = (style) => Object.fromEntries(Object.entries(normalizeStyle([style])).filter(([, v]) => v !== undefined && v !== null && v !== ''));
|
|
52
52
|
const FALLBACK = 'data-swiftplot-fallback';
|
|
53
53
|
const LAYER = 'data-swiftplot-fallback-layer';
|
|
54
|
+
// The text of styles.css, whose counter-reset tells a probe that the shipped file already applies in its root.
|
|
55
|
+
const RULE = `@layer swiftplot {
|
|
56
|
+
:where([data-swiftplot-fallback='fill']) {
|
|
57
|
+
height: 100%;
|
|
58
|
+
counter-reset: swiftplot-fallback;
|
|
59
|
+
}
|
|
60
|
+
:where([data-swiftplot-fallback='fixed']) {
|
|
61
|
+
height: 300px;
|
|
62
|
+
counter-reset: swiftplot-fallback;
|
|
63
|
+
}
|
|
64
|
+
}\n`;
|
|
54
65
|
const styles = new WeakMap();
|
|
55
|
-
|
|
66
|
+
const detached = new WeakMap();
|
|
67
|
+
const windowOf = (el) => (el.ownerDocument?.defaultView ?? globalThis);
|
|
56
68
|
/**
|
|
57
69
|
* Lowest priority: with no height from the app, fill a parent that has one, else 300 px. A rule in the
|
|
58
70
|
* first cascade layer of the host's document or shadow root rather than an inline height, so a height
|
|
@@ -60,27 +72,42 @@ let detached;
|
|
|
60
72
|
* once it is laid out.
|
|
61
73
|
*/
|
|
62
74
|
function fallback(el) {
|
|
75
|
+
const win = windowOf(el);
|
|
76
|
+
let observer = detached.get(win);
|
|
63
77
|
if (!el.isConnected) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
if (!observer) {
|
|
79
|
+
observer = new win.ResizeObserver(entries => {
|
|
80
|
+
for (const { target } of entries)
|
|
81
|
+
if (target.isConnected)
|
|
82
|
+
fallback(target);
|
|
83
|
+
});
|
|
84
|
+
detached.set(win, observer);
|
|
85
|
+
}
|
|
86
|
+
observer.observe(el);
|
|
69
87
|
return;
|
|
70
88
|
}
|
|
71
|
-
|
|
89
|
+
observer?.unobserve(el);
|
|
72
90
|
const contain = el.style.contain;
|
|
73
91
|
el.removeAttribute(FALLBACK);
|
|
74
92
|
el.style.contain = 'size';
|
|
75
|
-
const cs = getComputedStyle(el);
|
|
93
|
+
const cs = win.getComputedStyle(el);
|
|
76
94
|
for (const h of ['fill', 'fixed']) {
|
|
77
95
|
if (el.clientHeight - parseFloat(cs.paddingTop) - parseFloat(cs.paddingBottom) > 0)
|
|
78
96
|
break;
|
|
79
|
-
sheet(el);
|
|
80
97
|
el.setAttribute(FALLBACK, h);
|
|
98
|
+
if (h === 'fill' && !shipped(el))
|
|
99
|
+
sheet(el);
|
|
81
100
|
}
|
|
82
101
|
el.style.contain = contain;
|
|
83
102
|
}
|
|
103
|
+
// A probe of its own rather than the host, whose counter-reset the app's CSS may set.
|
|
104
|
+
function shipped(el) {
|
|
105
|
+
const probe = el.appendChild(el.ownerDocument.createElement('swiftplot-probe'));
|
|
106
|
+
probe.setAttribute(FALLBACK, 'fill');
|
|
107
|
+
const on = windowOf(el).getComputedStyle(probe).counterReset === 'swiftplot-fallback 0';
|
|
108
|
+
probe.remove();
|
|
109
|
+
return on;
|
|
110
|
+
}
|
|
84
111
|
function sheet(el) {
|
|
85
112
|
const doc = el.ownerDocument;
|
|
86
113
|
const root = el.getRootNode();
|
|
@@ -96,14 +123,17 @@ function sheet(el) {
|
|
|
96
123
|
}
|
|
97
124
|
const style = doc.createElement('style');
|
|
98
125
|
style.setAttribute(LAYER, '');
|
|
99
|
-
|
|
126
|
+
// A script's nonce would not pass style-src, and a page may give scripts and styles different ones.
|
|
127
|
+
style.nonce =
|
|
128
|
+
[...doc.querySelectorAll('style[nonce], link[rel~="stylesheet" i][nonce]')].find(e => e.nonce)?.nonce ?? '';
|
|
129
|
+
style.textContent = RULE;
|
|
100
130
|
parent.prepend(style);
|
|
101
131
|
styles.set(root, style);
|
|
102
132
|
// A sheet put first later (React 19 does so with its first precedence sheet) would declare its layers ahead of ours.
|
|
103
133
|
// A script that also keeps its node first would move it back forever, so a burst of moves ends the watch.
|
|
104
134
|
let moves = 0;
|
|
105
135
|
let since = 0;
|
|
106
|
-
const first = new MutationObserver(() => {
|
|
136
|
+
const first = new (windowOf(el).MutationObserver)(() => {
|
|
107
137
|
if (style.parentNode !== parent)
|
|
108
138
|
return first.disconnect();
|
|
109
139
|
const head = parent.firstChild;
|
|
@@ -140,7 +170,7 @@ export function bind(chart, declared) {
|
|
|
140
170
|
return defineComponent({
|
|
141
171
|
inheritAttrs: false,
|
|
142
172
|
props: {
|
|
143
|
-
...declared,
|
|
173
|
+
...declared(),
|
|
144
174
|
onError: null,
|
|
145
175
|
...Object.fromEntries(Object.values(LISTENERS).map(e => [toHandlerKey(e), null])),
|
|
146
176
|
},
|
|
@@ -271,7 +301,10 @@ export function bind(chart, declared) {
|
|
|
271
301
|
sync();
|
|
272
302
|
});
|
|
273
303
|
onBeforeUnmount(() => {
|
|
274
|
-
|
|
304
|
+
// A Suspense boundary unmounted while pending never set the ref.
|
|
305
|
+
if (!host.value)
|
|
306
|
+
return;
|
|
307
|
+
detached.get(windowOf(host.value))?.unobserve(host.value);
|
|
275
308
|
bound?.destroy();
|
|
276
309
|
bound = undefined;
|
|
277
310
|
});
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ const base = {
|
|
|
15
15
|
height: null,
|
|
16
16
|
margin: null,
|
|
17
17
|
description: null,
|
|
18
|
+
empty: null,
|
|
18
19
|
hidden: null,
|
|
19
20
|
selected: null,
|
|
20
21
|
pointer: null,
|
|
@@ -22,63 +23,67 @@ const base = {
|
|
|
22
23
|
const axes = { xAxis: null, yAxis: null, zoom: flag, view: null };
|
|
23
24
|
const overlays = { rules: null, zones: null, brush: flag };
|
|
24
25
|
const xy = { ...base, ...axes, ...overlays, x: null, y: null, y2: null, series: null, y2Axis: null };
|
|
25
|
-
export const LineChart = bind(lineChart, {
|
|
26
|
+
export const LineChart = /*#__PURE__*/ bind(lineChart, () => ({
|
|
26
27
|
...xy,
|
|
27
28
|
curve: null,
|
|
28
29
|
fill: flag,
|
|
29
30
|
errorBars: null,
|
|
30
31
|
join: bool,
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
cumulative: bool,
|
|
33
|
+
}));
|
|
34
|
+
export const AreaChart = /*#__PURE__*/ bind(areaChart, () => ({
|
|
33
35
|
...xy,
|
|
34
36
|
curve: null,
|
|
35
37
|
join: bool,
|
|
36
38
|
stack: bool,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
cumulative: bool,
|
|
40
|
+
}));
|
|
41
|
+
export const BarChart = /*#__PURE__*/ bind(barChart, () => ({
|
|
39
42
|
...xy,
|
|
40
43
|
stack: bool,
|
|
44
|
+
cumulative: bool,
|
|
41
45
|
errorBars: null,
|
|
42
|
-
});
|
|
43
|
-
export const ScatterChart = bind(scatterChart, {
|
|
46
|
+
}));
|
|
47
|
+
export const ScatterChart = /*#__PURE__*/ bind(scatterChart, () => ({
|
|
44
48
|
...xy,
|
|
45
49
|
r: null,
|
|
46
50
|
alpha: null,
|
|
47
51
|
ring: null,
|
|
48
52
|
shape: null,
|
|
49
53
|
errorBars: null,
|
|
50
|
-
});
|
|
51
|
-
export const PieChart = bind(pieChart, {
|
|
54
|
+
}));
|
|
55
|
+
export const PieChart = /*#__PURE__*/ bind(pieChart, () => ({
|
|
52
56
|
...base,
|
|
53
57
|
label: null,
|
|
54
58
|
value: null,
|
|
55
59
|
inner: null,
|
|
56
60
|
text: bool,
|
|
57
61
|
sweep: null,
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
center: null,
|
|
63
|
+
}));
|
|
64
|
+
export const FunnelChart = /*#__PURE__*/ bind(funnelChart, () => ({
|
|
60
65
|
...base,
|
|
61
66
|
label: null,
|
|
62
67
|
value: null,
|
|
63
68
|
text: bool,
|
|
64
69
|
fill: null,
|
|
65
|
-
});
|
|
66
|
-
export const RadialBarChart = bind(radialBarChart, {
|
|
70
|
+
}));
|
|
71
|
+
export const RadialBarChart = /*#__PURE__*/ bind(radialBarChart, () => ({
|
|
67
72
|
...base,
|
|
68
73
|
label: null,
|
|
69
74
|
value: null,
|
|
70
75
|
max: null,
|
|
71
76
|
sweep: null,
|
|
72
77
|
inner: null,
|
|
73
|
-
});
|
|
74
|
-
export const RadarChart = bind(radarChart, {
|
|
78
|
+
}));
|
|
79
|
+
export const RadarChart = /*#__PURE__*/ bind(radarChart, () => ({
|
|
75
80
|
...base,
|
|
76
81
|
x: null,
|
|
77
82
|
y: null,
|
|
78
83
|
max: null,
|
|
79
84
|
fill: null,
|
|
80
|
-
});
|
|
81
|
-
export const HeatmapChart = bind(heatmapChart, {
|
|
85
|
+
}));
|
|
86
|
+
export const HeatmapChart = /*#__PURE__*/ bind(heatmapChart, () => ({
|
|
82
87
|
...base,
|
|
83
88
|
x: null,
|
|
84
89
|
y: null,
|
|
@@ -86,22 +91,23 @@ export const HeatmapChart = bind(heatmapChart, {
|
|
|
86
91
|
color: null,
|
|
87
92
|
xAxis: null,
|
|
88
93
|
yAxis: null,
|
|
89
|
-
});
|
|
90
|
-
export const HistogramChart = bind(histogramChart, {
|
|
94
|
+
}));
|
|
95
|
+
export const HistogramChart = /*#__PURE__*/ bind(histogramChart, () => ({
|
|
91
96
|
...base,
|
|
92
97
|
...axes,
|
|
93
98
|
x: null,
|
|
94
99
|
bins: null,
|
|
95
|
-
}
|
|
96
|
-
|
|
100
|
+
cumulative: { type: [Boolean, String], default: undefined },
|
|
101
|
+
}));
|
|
102
|
+
export const BoxPlotChart = /*#__PURE__*/ bind(boxPlotChart, () => ({
|
|
97
103
|
...base,
|
|
98
104
|
x: null,
|
|
99
105
|
y: null,
|
|
100
106
|
fill: null,
|
|
101
107
|
xAxis: null,
|
|
102
108
|
yAxis: null,
|
|
103
|
-
});
|
|
104
|
-
export const CandlestickChart = bind(candlestickChart, {
|
|
109
|
+
}));
|
|
110
|
+
export const CandlestickChart = /*#__PURE__*/ bind(candlestickChart, () => ({
|
|
105
111
|
...base,
|
|
106
112
|
...axes,
|
|
107
113
|
x: null,
|
|
@@ -111,8 +117,8 @@ export const CandlestickChart = bind(candlestickChart, {
|
|
|
111
117
|
close: null,
|
|
112
118
|
up: null,
|
|
113
119
|
down: null,
|
|
114
|
-
});
|
|
115
|
-
export const ComboChart = bind(comboChart, {
|
|
120
|
+
}));
|
|
121
|
+
export const ComboChart = /*#__PURE__*/ bind(comboChart, () => ({
|
|
116
122
|
...base,
|
|
117
123
|
...axes,
|
|
118
124
|
...overlays,
|
|
@@ -123,26 +129,27 @@ export const ComboChart = bind(comboChart, {
|
|
|
123
129
|
y2Lines: null,
|
|
124
130
|
y2Bars: null,
|
|
125
131
|
stack: bool,
|
|
126
|
-
|
|
127
|
-
|
|
132
|
+
cumulative: bool,
|
|
133
|
+
}));
|
|
134
|
+
export const SankeyChart = /*#__PURE__*/ bind(sankeyChart, () => ({
|
|
128
135
|
...base,
|
|
129
136
|
source: null,
|
|
130
137
|
target: null,
|
|
131
138
|
value: null,
|
|
132
139
|
blend: bool,
|
|
133
140
|
text: bool,
|
|
134
|
-
});
|
|
135
|
-
export const TreemapChart = bind(treemapChart, {
|
|
141
|
+
}));
|
|
142
|
+
export const TreemapChart = /*#__PURE__*/ bind(treemapChart, () => ({
|
|
136
143
|
...base,
|
|
137
144
|
text: bool,
|
|
138
145
|
shade: null,
|
|
139
|
-
});
|
|
140
|
-
export const SunburstChart = bind(sunburstChart, {
|
|
146
|
+
}));
|
|
147
|
+
export const SunburstChart = /*#__PURE__*/ bind(sunburstChart, () => ({
|
|
141
148
|
...base,
|
|
142
149
|
text: bool,
|
|
143
150
|
shade: null,
|
|
144
|
-
});
|
|
145
|
-
export const Plot = bind(mount, {
|
|
151
|
+
}));
|
|
152
|
+
export const Plot = /*#__PURE__*/ bind(mount, () => ({
|
|
146
153
|
width: null,
|
|
147
154
|
height: null,
|
|
148
155
|
margin: null,
|
|
@@ -159,4 +166,4 @@ export const Plot = bind(mount, {
|
|
|
159
166
|
hidden: null,
|
|
160
167
|
selected: null,
|
|
161
168
|
pointer: null,
|
|
162
|
-
});
|
|
169
|
+
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swiftplot/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-rc.0",
|
|
4
4
|
"description": "Vue components for swiftplot charts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chart",
|
|
@@ -22,19 +22,23 @@
|
|
|
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
|
"vue": "^3.4",
|
|
37
|
-
"swiftplot": "^0.
|
|
41
|
+
"swiftplot": "^0.6.0-rc.0"
|
|
38
42
|
},
|
|
39
43
|
"devDependencies": {
|
|
40
44
|
"@types/node": "^24.19.2",
|
|
@@ -44,7 +48,7 @@
|
|
|
44
48
|
"vitest": "^5.1.1",
|
|
45
49
|
"vue": "^3.5.46",
|
|
46
50
|
"vue-tsc": "^3.3.14",
|
|
47
|
-
"swiftplot": "0.
|
|
51
|
+
"swiftplot": "0.6.0-rc.0"
|
|
48
52
|
},
|
|
49
53
|
"scripts": {
|
|
50
54
|
"build": "tsc -p tsconfig.build.json",
|