@swiftplot/vue 0.7.0 → 0.9.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 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. `swiftplot/schema.json` is a JSON Schema of the
17
+ swiftplot, and [`llms.txt`](https://swiftplot.dev/llms.txt) its index. The guide for the version installed ships in the
18
+ package, at `node_modules/swiftplot/llms-full.txt`. `swiftplot/schema.json` is a JSON Schema of the
18
19
  easy charts' props, for a model that answers with a chart as JSON; the recipes
19
20
  [Charts for json-render](https://swiftplot.dev/guides/json-render) and [Vercel AI SDK](https://swiftplot.dev/guides/ai-sdk)
20
21
  put it to work in those libraries.
@@ -60,9 +61,9 @@ Each point comes from profiling uPlot, the fastest of the other twelve libraries
60
61
 
61
62
  - **Axis text is DOM, not canvas text.** uPlot's axis drawing cost 17–21 ms at 4× CPU slowdown at every data size.
62
63
  - **Each mark has its own x column.** No aligned table, so no join step.
63
- - **Step lines and bands are reduced to one min/max per pixel column** before the path is built.
64
+ - **Lines and areas are reduced to one min/max per pixel column** before the path is built, and only the rows the window shows are read.
64
65
  - **Typed-array columns in, scale maths inlined** in the draw loops.
65
- - **Scatter switches to WebGL2 at 20,000 points, bars, error bars, box plots and candlesticks at 10,000, and a sankey at 1,000 nodes and links together.** WebGL2 set-up costs about 4 ms, so a scatter on Canvas 2D mounts sooner below roughly 20,000 points. When the browser takes a WebGL context away, as it does with many WebGL charts on one page, that chart falls back to Canvas 2D.
66
+ - **Scatter switches to WebGL2 at 20,000 points, bars, error bars, box plots and candlesticks at 10,000, and a sankey at 1,000 nodes and links together.** Setting WebGL2 up has a fixed cost, so a scatter on Canvas 2D mounts sooner below roughly 20,000 points. Points are drawn as point sprites from one buffer in one draw call, and rectangles are instanced. When the browser takes a WebGL context away, as it does with many WebGL charts on one page, that chart falls back to Canvas 2D.
66
67
  - **Paths and GPU buffers are kept,** so a hover repaint never touches the data again.
67
68
 
68
69
  ## Measured
@@ -100,14 +101,14 @@ Gzip size of the minified bundle of each entry in `site/scripts/size/`, built fr
100
101
 
101
102
  | entry | imports | KB |
102
103
  | ------------------ | ------------------------------------------------------- | ---: |
103
- | plot-line | `plot` and `line` from `swiftplot` | 15.7 |
104
- | plot-line-features | the same with `tooltip`, `legend`, `zoom` and `animate` | 21.5 |
105
- | line-chart | `lineChart` from `swiftplot/charts` | 45.1 |
106
- | all-charts | every chart of `swiftplot/charts` | 64.0 |
107
- | react-line-chart | `LineChart` from `@swiftplot/react`, React not counted | 47.0 |
108
- | vue-line-chart | `LineChart` from `@swiftplot/vue`, Vue not counted | 47.7 |
109
- | element-line | `define` from `swiftplot/element` with `lineChart` | 46.7 |
110
- | element-all | `swiftplot/element/all`, every chart as `<swift-plot>` | 65.8 |
104
+ | plot-line | `plot` and `line` from `swiftplot` | 17.5 |
105
+ | plot-line-features | the same with `tooltip`, `legend`, `zoom` and `animate` | 23.8 |
106
+ | line-chart | `lineChart` from `swiftplot/charts` | 53.2 |
107
+ | all-charts | every chart of `swiftplot/charts` | 73.5 |
108
+ | react-line-chart | `LineChart` from `@swiftplot/react`, React not counted | 55.3 |
109
+ | vue-line-chart | `LineChart` from `@swiftplot/vue`, Vue not counted | 56.0 |
110
+ | element-line | `define` from `swiftplot/element` with `lineChart` | 54.9 |
111
+ | element-all | `swiftplot/element/all`, every chart as `<swift-plot>` | 75.2 |
111
112
 
112
113
  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.
113
114
 
package/dist/bind.d.ts CHANGED
@@ -3,6 +3,7 @@ import { type Component, type Prop } from 'vue';
3
3
  export type Mount<P> = (el: HTMLElement, props: P) => {
4
4
  update(partial: Partial<P>): void;
5
5
  destroy(): void;
6
+ refresh(): void;
6
7
  readonly overlay: HTMLElement;
7
8
  };
8
9
  /** Rendered over the chart, in its overlay, from its layout and what the pointer is over. */
package/dist/bind.js CHANGED
@@ -178,6 +178,7 @@ export function bind(chart, declared) {
178
178
  }
179
179
  return bound ? host.value : null;
180
180
  },
181
+ refresh: () => bound?.refresh(),
181
182
  };
182
183
  for (const k of Object.keys(props))
183
184
  Object.defineProperty(exposed, k, { get: () => props[k], enumerable: true });
@@ -190,6 +191,7 @@ export function bind(chart, declared) {
190
191
  const attempted = shallowRef();
191
192
  let reported;
192
193
  let sizing;
194
+ let inline;
193
195
  let drop;
194
196
  // emit calls a .once listener (onClickOnce, an attr) on its first emit only, for the life of the component.
195
197
  const fired = new Set();
@@ -240,6 +242,9 @@ export function bind(chart, declared) {
240
242
  if ((!bound || !equal(next, sizing)) && style.height === undefined && props.height === undefined)
241
243
  drop = fallback(el, install);
242
244
  sizing = next;
245
+ // Without layout the core sizes the chart by the host's inline size, read again only on an update.
246
+ const size = [el.style.width, el.style.height];
247
+ const resized = !equal(size, inline);
243
248
  // width and height size the host only: the core measures it on both axes, so its ResizeObserver
244
249
  // follows whatever else resizes the host (min-/max-, !important, a parent, a media query).
245
250
  const now = chartProps();
@@ -267,37 +272,62 @@ export function bind(chart, declared) {
267
272
  bound.update(diff);
268
273
  applied.value = { ...applied.value, ...diff };
269
274
  };
275
+ const report = (e) => {
276
+ if (!listens('error'))
277
+ throw e;
278
+ const key = keyOf(e, now);
279
+ if (equal(reported, key))
280
+ return;
281
+ reported = key;
282
+ send('error', e);
283
+ };
284
+ const created = !bound;
285
+ let thrown;
286
+ let restore = false;
270
287
  try {
271
- if (!bound)
288
+ if (created)
272
289
  bound = chart(el, now);
273
- else if (held) {
290
+ else if (held)
274
291
  callbacks();
275
- return;
276
- }
277
292
  else {
278
293
  const diff = {};
279
294
  for (const k of changed(applied.value, now))
280
295
  diff[k] = now[k];
281
- if (failed || Object.keys(diff).length)
296
+ if (Object.keys(diff).length)
282
297
  bound.update(diff);
298
+ else
299
+ restore = !!failed;
283
300
  }
284
301
  }
285
302
  catch (e) {
303
+ thrown = { e };
286
304
  if (bound)
287
305
  callbacks();
288
- if (!listens('error'))
289
- throw e;
290
- const key = keyOf(e, now);
291
- if (equal(reported, key))
292
- return;
293
- reported = key;
294
- send('error', e);
295
- return;
296
306
  }
297
- applied.value = now;
298
- if (slotted)
299
- overlay.value = bound.overlay;
300
- reported = undefined;
307
+ let unmeasured;
308
+ if (bound) {
309
+ if (restore || (resized && !created))
310
+ try {
311
+ bound.update({});
312
+ }
313
+ catch (e) {
314
+ if (restore)
315
+ thrown = { e };
316
+ else
317
+ unmeasured = { e };
318
+ }
319
+ inline = size;
320
+ }
321
+ if (thrown)
322
+ report(thrown.e);
323
+ else if (!held) {
324
+ applied.value = now;
325
+ if (slotted)
326
+ overlay.value = bound.overlay;
327
+ reported = undefined;
328
+ }
329
+ if (unmeasured)
330
+ report(unmeasured.e);
301
331
  };
302
332
  const settle = () => due && sync();
303
333
  onMounted(settle);
package/dist/index.js CHANGED
@@ -2,7 +2,8 @@ import { areaChart, barChart, boxPlotChart, candlestickChart, comboChart, funnel
2
2
  import { bind } from './bind.js';
3
3
  const flag = { type: [Boolean, Object], default: undefined };
4
4
  const bool = { type: Boolean, default: undefined };
5
- const base = {
5
+ const choice = { type: [Boolean, String], default: undefined };
6
+ const oneMark = {
6
7
  data: null,
7
8
  dataVersion: null,
8
9
  colors: null,
@@ -23,19 +24,25 @@ const base = {
23
24
  selected: null,
24
25
  pointer: null,
25
26
  };
26
- const axes = { xAxis: null, yAxis: null, zoom: flag, view: null };
27
+ const base = { ...oneMark, focused: null };
28
+ const axes = { xAxis: null, yAxis: null, grid: choice, zoom: flag, view: null };
27
29
  const overlays = { rules: null, zones: null, brush: flag };
28
30
  const xy = { ...base, ...axes, ...overlays, x: null, y: null, y2: null, series: null, y2Axis: null };
29
31
  export const LineChart = /*#__PURE__*/ bind(lineChart, () => ({
30
32
  ...xy,
33
+ follow: bool,
31
34
  curve: null,
32
35
  fill: flag,
33
36
  errorBars: null,
34
37
  join: bool,
35
38
  cumulative: bool,
39
+ dash: null,
40
+ dashes: null,
41
+ dashFrom: null,
36
42
  }));
37
43
  export const AreaChart = /*#__PURE__*/ bind(areaChart, () => ({
38
44
  ...xy,
45
+ follow: bool,
39
46
  curve: null,
40
47
  join: bool,
41
48
  stack: bool,
@@ -46,33 +53,40 @@ export const BarChart = /*#__PURE__*/ bind(barChart, () => ({
46
53
  stack: bool,
47
54
  cumulative: bool,
48
55
  errorBars: null,
56
+ text: { type: [Boolean, Function, Object], default: undefined },
57
+ horizontal: bool,
58
+ color: null,
49
59
  }));
50
60
  export const ScatterChart = /*#__PURE__*/ bind(scatterChart, () => ({
51
61
  ...xy,
62
+ follow: bool,
52
63
  r: null,
53
64
  alpha: null,
54
65
  ring: null,
55
66
  shape: null,
67
+ shapes: null,
56
68
  errorBars: null,
57
69
  }));
58
70
  export const PieChart = /*#__PURE__*/ bind(pieChart, () => ({
59
- ...base,
71
+ ...oneMark,
60
72
  label: null,
61
73
  value: null,
62
74
  inner: null,
63
75
  text: bool,
64
76
  sweep: null,
65
77
  center: null,
78
+ stroke: null,
79
+ strokeWidth: null,
66
80
  }));
67
81
  export const FunnelChart = /*#__PURE__*/ bind(funnelChart, () => ({
68
- ...base,
82
+ ...oneMark,
69
83
  label: null,
70
84
  value: null,
71
85
  text: bool,
72
86
  fill: null,
73
87
  }));
74
88
  export const RadialBarChart = /*#__PURE__*/ bind(radialBarChart, () => ({
75
- ...base,
89
+ ...oneMark,
76
90
  label: null,
77
91
  value: null,
78
92
  max: null,
@@ -87,32 +101,35 @@ export const RadarChart = /*#__PURE__*/ bind(radarChart, () => ({
87
101
  fill: null,
88
102
  }));
89
103
  export const HeatmapChart = /*#__PURE__*/ bind(heatmapChart, () => ({
90
- ...base,
104
+ ...oneMark,
91
105
  x: null,
92
106
  y: null,
93
107
  value: null,
94
108
  color: null,
95
109
  xAxis: null,
96
110
  yAxis: null,
111
+ grid: choice,
97
112
  }));
98
113
  export const HistogramChart = /*#__PURE__*/ bind(histogramChart, () => ({
99
- ...base,
114
+ ...oneMark,
100
115
  ...axes,
101
116
  x: null,
102
117
  bins: null,
103
- cumulative: { type: [Boolean, String], default: undefined },
118
+ cumulative: choice,
104
119
  }));
105
120
  export const BoxPlotChart = /*#__PURE__*/ bind(boxPlotChart, () => ({
106
- ...base,
121
+ ...oneMark,
107
122
  x: null,
108
123
  y: null,
109
124
  fill: null,
110
125
  xAxis: null,
111
126
  yAxis: null,
127
+ grid: choice,
112
128
  }));
113
129
  export const CandlestickChart = /*#__PURE__*/ bind(candlestickChart, () => ({
114
- ...base,
130
+ ...oneMark,
115
131
  ...axes,
132
+ follow: bool,
116
133
  x: null,
117
134
  open: null,
118
135
  high: null,
@@ -125,6 +142,7 @@ export const ComboChart = /*#__PURE__*/ bind(comboChart, () => ({
125
142
  ...base,
126
143
  ...axes,
127
144
  ...overlays,
145
+ follow: bool,
128
146
  y2Axis: null,
129
147
  x: null,
130
148
  lines: null,
@@ -133,9 +151,12 @@ export const ComboChart = /*#__PURE__*/ bind(comboChart, () => ({
133
151
  y2Bars: null,
134
152
  stack: bool,
135
153
  cumulative: bool,
154
+ dash: null,
155
+ dashes: null,
156
+ dashFrom: null,
136
157
  }));
137
158
  export const SankeyChart = /*#__PURE__*/ bind(sankeyChart, () => ({
138
- ...base,
159
+ ...oneMark,
139
160
  source: null,
140
161
  target: null,
141
162
  value: null,
@@ -143,12 +164,12 @@ export const SankeyChart = /*#__PURE__*/ bind(sankeyChart, () => ({
143
164
  text: bool,
144
165
  }));
145
166
  export const TreemapChart = /*#__PURE__*/ bind(treemapChart, () => ({
146
- ...base,
167
+ ...oneMark,
147
168
  text: bool,
148
169
  shade: null,
149
170
  }));
150
171
  export const SunburstChart = /*#__PURE__*/ bind(sunburstChart, () => ({
151
- ...base,
172
+ ...oneMark,
152
173
  text: bool,
153
174
  shade: null,
154
175
  }));
@@ -159,15 +180,20 @@ export const Plot = /*#__PURE__*/ bind(mount, () => ({
159
180
  x: null,
160
181
  y: null,
161
182
  y2: null,
183
+ grid: choice,
184
+ valueAxis: null,
162
185
  frame: null,
163
186
  marks: null,
164
187
  use: null,
188
+ a11y: null,
189
+ table: null,
165
190
  description: null,
166
191
  locale: null,
167
192
  dim: null,
168
193
  theme: null,
169
194
  view: null,
170
195
  hidden: null,
196
+ focused: null,
171
197
  selected: null,
172
198
  pointer: null,
173
199
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swiftplot/vue",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Vue components for swiftplot charts",
5
5
  "keywords": [
6
6
  "chart",
@@ -38,7 +38,7 @@
38
38
  ],
39
39
  "peerDependencies": {
40
40
  "vue": "^3.4",
41
- "swiftplot": "^0.7.0"
41
+ "swiftplot": "^0.9.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^24.19.2",
@@ -50,7 +50,7 @@
50
50
  "vitest": "^5.1.1",
51
51
  "vue": "^3.5.46",
52
52
  "vue-tsc": "^3.3.14",
53
- "swiftplot": "0.7.0"
53
+ "swiftplot": "0.9.0"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "tsc -p tsconfig.build.json",