@wick-charts/vue 0.7.0 → 0.8.1

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
@@ -5,13 +5,13 @@
5
5
  [![codecov](https://codecov.io/gh/mo4islona/wick-charts/branch/main/graph/badge.svg)](https://codecov.io/gh/mo4islona/wick-charts) [![license](https://img.shields.io/github/license/mo4islona/wick-charts.svg)](./LICENSE)
6
6
  [![npm @wick-charts/vue](https://img.shields.io/npm/v/@wick-charts/vue.svg?label=%40wick-charts%2Fvue)](https://www.npmjs.com/package/@wick-charts/vue)
7
7
 
8
- High-performance timeseries charts for **React**, **Vue**, and **Svelte**. Canvas-rendered, tree-shakeable, zero runtime dependencies.
8
+ Realtime, animated charts for **React**, **Vue** and **Svelte**. Canvas-rendered, tree-shakeable, zero runtime dependencies.
9
9
 
10
10
  [Live Demo](https://wick-charts.eeff.io/) · [Docs](https://wick-charts.eeff.io/api/chart-container/)
11
11
 
12
12
  ## Features
13
13
 
14
- - **Candlestick, Line, Bar, Band, Pie, Sparkline** — all from one package
14
+ - **Chart types** — candlestick, line and area, band, bar, heatmap, pie and donut, sparkline, all from one package
15
15
  - **Real-time streaming** — append/update at 60fps with coordinated animations
16
16
  - **22 built-in themes** plus `createTheme()` for custom palettes
17
17
  - **Interactive** — zoom, pan, crosshair, tooltips
@@ -49,13 +49,15 @@ const props = defineProps(['data']);
49
49
  </template>
50
50
  ```
51
51
 
52
+ `ChartContainer` fills its parent (`width` and `height` are `100%`), so give the parent a height. The container also has a 240px `min-height`, so a parent with no height still shows a chart. For a smaller chart, such as a sparkline in a table row, set `min-height: 0` (`minHeight: 0` in React) in the container's `style`.
53
+
52
54
  ## API
53
55
 
54
56
  Every component, prop, type, and slot context lives in the docs site:
55
57
 
56
58
  [wick-charts.eeff.io/api/chart-container/](https://wick-charts.eeff.io/api/chart-container/)
57
59
 
58
- Start there for [ChartContainer](https://wick-charts.eeff.io/api/chart-container/), then drill into the series ([Candlestick](https://wick-charts.eeff.io/api/candlestick-series/), [Line](https://wick-charts.eeff.io/api/line-series/), [Bar](https://wick-charts.eeff.io/api/bar-series/), [Band](https://wick-charts.eeff.io/api/band-series/), [Pie](https://wick-charts.eeff.io/api/pie-series/), [Sparkline](https://wick-charts.eeff.io/api/sparkline/)) and overlays ([Tooltip](https://wick-charts.eeff.io/api/tooltip/), [InfoBar](https://wick-charts.eeff.io/api/info-bar/), [Crosshair](https://wick-charts.eeff.io/api/crosshair/), [Legend](https://wick-charts.eeff.io/api/legend/), [YAxis](https://wick-charts.eeff.io/api/y-axis/), [XAxis](https://wick-charts.eeff.io/api/x-axis/), [Navigator](https://wick-charts.eeff.io/api/navigator/), …).
60
+ Start there for [ChartContainer](https://wick-charts.eeff.io/api/chart-container/), then drill into the series ([Candlestick](https://wick-charts.eeff.io/api/candlestick-series/), [Line](https://wick-charts.eeff.io/api/line-series/), [Bar](https://wick-charts.eeff.io/api/bar-series/), [Band](https://wick-charts.eeff.io/api/band-series/), [Pie](https://wick-charts.eeff.io/api/pie-series/), [Heatmap](https://wick-charts.eeff.io/api/heatmap-series/), [Sparkline](https://wick-charts.eeff.io/api/sparkline/)) and overlays ([Tooltip](https://wick-charts.eeff.io/api/tooltip/), [InfoBar](https://wick-charts.eeff.io/api/info-bar/), [Crosshair](https://wick-charts.eeff.io/api/crosshair/), [Legend](https://wick-charts.eeff.io/api/legend/), [YAxis](https://wick-charts.eeff.io/api/y-axis/), [XAxis](https://wick-charts.eeff.io/api/x-axis/), [Navigator](https://wick-charts.eeff.io/api/navigator/), …).
59
61
 
60
62
  ## No framework? Use the engine directly
61
63
 
@@ -112,6 +114,20 @@ Tree-shaken React scenarios via `pnpm size` (esbuild, minified, browser target,
112
114
 
113
115
  Upgrading across versions? See [MIGRATION.md](https://github.com/mo4islona/wick-charts/blob/main/MIGRATION.md) for per-version breaking-change notes and code snippets.
114
116
 
117
+ ## Contributing
118
+
119
+ Bug reports, feature requests and pull requests are welcome. Open an [issue](https://github.com/mo4islona/wick-charts/issues) first for anything larger than a small fix, so we can agree on the approach.
120
+
121
+ ```bash
122
+ pnpm install
123
+ pnpm dev # docs site with every chart type at http://localhost:5173
124
+ pnpm test # unit and integration tests
125
+ pnpm lint # Biome
126
+ pnpm typecheck
127
+ ```
128
+
129
+ A pull request should pass `pnpm test`, `pnpm lint` and `pnpm typecheck`, and add a test for each bug fix.
130
+
115
131
  ## License
116
132
 
117
133
  MIT
@@ -1,8 +1,8 @@
1
- import { defineComponent as u, ref as d, onMounted as c, onUnmounted as p, watch as n, createCommentVNode as f } from "vue";
2
- import { toLayers as m, EMPTY_SYNC_STATE as v, syncLayers as S } from "./core/dist/data/sync.js";
3
- import { BandSeriesDef as y } from "./core/dist/series/band.js";
4
- import { useChartInstance as _ } from "./context.js";
5
- const B = /* @__PURE__ */ u({
1
+ import { defineComponent as d, ref as f, onMounted as m, onUnmounted as v, watch as o, createCommentVNode as S } from "vue";
2
+ import { toLayers as c, syncLayers as y, EMPTY_SYNC_STATE as _ } from "./core/dist/data/sync.js";
3
+ import { BandSeriesDef as b } from "./core/dist/series/band.js";
4
+ import { useChartInstance as h } from "./context.js";
5
+ const V = /* @__PURE__ */ d({
6
6
  __name: "BandSeries",
7
7
  props: {
8
8
  data: {},
@@ -11,42 +11,52 @@ const B = /* @__PURE__ */ u({
11
11
  visible: { type: Boolean, default: !0 },
12
12
  scale: {}
13
13
  },
14
- setup(l) {
15
- const a = l, r = _(), s = d(null);
16
- let i = [];
17
- function o(e, t) {
18
- i = S({ chart: r, id: e, data: t, prev: i });
14
+ setup(p) {
15
+ const r = p, i = h(), s = f(null);
16
+ let a = [], n = 0;
17
+ function l(e, t) {
18
+ a = y({ chart: i, id: e, data: t, prev: a });
19
19
  }
20
- return c(() => {
21
- const e = m(a.data).length, t = r.addSeries(y, {
22
- ...a.options,
23
- scale: a.scale,
24
- layers: e,
25
- id: a.id
20
+ function u(e) {
21
+ n = c(e).length;
22
+ const t = i.addSeries(b, {
23
+ ...r.options,
24
+ scale: r.scale,
25
+ layers: n,
26
+ id: r.id
26
27
  });
27
- s.value = t, i = new Array(e).fill(v), o(t, a.data), r.setSeriesVisible(t, a.visible);
28
- }), p(() => {
29
- s.value && r.removeSeries(s.value);
30
- }), n(
31
- () => a.data,
28
+ s.value = t, a = new Array(n).fill(_), l(t, e), i.setSeriesVisible(t, r.visible);
29
+ }
30
+ return m(() => {
31
+ u(r.data);
32
+ }), v(() => {
33
+ s.value && i.removeSeries(s.value);
34
+ }), o(
35
+ () => r.data,
32
36
  (e) => {
33
37
  const t = s.value;
34
- t && o(t, e);
38
+ if (t) {
39
+ if (c(e).length !== n) {
40
+ i.removeSeries(t), u(e);
41
+ return;
42
+ }
43
+ l(t, e);
44
+ }
35
45
  }
36
- ), n(
37
- () => [a.options, a.scale],
46
+ ), o(
47
+ () => [r.options, r.scale],
38
48
  ([e, t]) => {
39
- s.value && r.updateSeriesOptions(s.value, e ? { ...e, scale: t } : { scale: t });
49
+ s.value && i.updateSeriesOptions(s.value, e ? { ...e, scale: t } : { scale: t });
40
50
  },
41
51
  { deep: !0 }
42
- ), n(
43
- () => a.visible,
52
+ ), o(
53
+ () => r.visible,
44
54
  (e) => {
45
- s.value && r.setSeriesVisible(s.value, e);
55
+ s.value && i.setSeriesVisible(s.value, e);
46
56
  }
47
- ), (e, t) => f("", !0);
57
+ ), (e, t) => S("", !0);
48
58
  }
49
59
  });
50
60
  export {
51
- B as default
61
+ V as default
52
62
  };
@@ -1,8 +1,8 @@
1
- import { defineComponent as u, ref as c, onMounted as d, onUnmounted as p, watch as o, createCommentVNode as f } from "vue";
2
- import { toLayers as m, EMPTY_SYNC_STATE as v, syncLayers as S } from "./core/dist/data/sync.js";
3
- import { BarSeriesDef as y } from "./core/dist/series/bar.js";
4
- import { useChartInstance as _ } from "./context.js";
5
- const B = /* @__PURE__ */ u({
1
+ import { defineComponent as f, ref as d, onMounted as m, onUnmounted as v, watch as o, createCommentVNode as S } from "vue";
2
+ import { toLayers as c, syncLayers as y, EMPTY_SYNC_STATE as _ } from "./core/dist/data/sync.js";
3
+ import { BarSeriesDef as b } from "./core/dist/series/bar.js";
4
+ import { useChartInstance as h } from "./context.js";
5
+ const g = /* @__PURE__ */ f({
6
6
  __name: "BarSeries",
7
7
  props: {
8
8
  data: {},
@@ -11,42 +11,52 @@ const B = /* @__PURE__ */ u({
11
11
  visible: { type: Boolean, default: !0 },
12
12
  scale: {}
13
13
  },
14
- setup(l) {
15
- const a = l, s = _(), r = c(null);
16
- let i = [];
17
- function n(e, t) {
18
- i = S({ chart: s, id: e, data: t, prev: i });
14
+ setup(p) {
15
+ const t = p, i = h(), s = d(null);
16
+ let n = [], a = 0;
17
+ function l(e, r) {
18
+ n = y({ chart: i, id: e, data: r, prev: n });
19
19
  }
20
- return d(() => {
21
- const e = m(a.data).length, t = s.addSeries(y, {
22
- ...a.options,
23
- scale: a.scale,
24
- layers: e,
25
- id: a.id
20
+ function u(e) {
21
+ a = c(e).length;
22
+ const r = i.addSeries(b, {
23
+ ...t.options,
24
+ scale: t.scale,
25
+ layers: a,
26
+ id: t.id
26
27
  });
27
- r.value = t, i = new Array(e).fill(v), n(t, a.data), s.setSeriesVisible(t, a.visible);
28
- }), p(() => {
29
- r.value && s.removeSeries(r.value);
28
+ s.value = r, n = new Array(a).fill(_), l(r, e), i.setSeriesVisible(r, t.visible);
29
+ }
30
+ return m(() => {
31
+ u(t.data);
32
+ }), v(() => {
33
+ s.value && i.removeSeries(s.value);
30
34
  }), o(
31
- () => a.data,
35
+ () => t.data,
32
36
  (e) => {
33
- const t = r.value;
34
- t && n(t, e);
37
+ const r = s.value;
38
+ if (r) {
39
+ if (c(e).length !== a) {
40
+ i.removeSeries(r), u(e);
41
+ return;
42
+ }
43
+ l(r, e);
44
+ }
35
45
  }
36
46
  ), o(
37
- () => [a.options, a.scale],
38
- ([e, t]) => {
39
- r.value && s.updateSeriesOptions(r.value, e ? { ...e, scale: t } : { scale: t });
47
+ () => [t.options, t.scale],
48
+ ([e, r]) => {
49
+ s.value && i.updateSeriesOptions(s.value, e ? { ...e, scale: r } : { scale: r });
40
50
  },
41
51
  { deep: !0 }
42
52
  ), o(
43
- () => a.visible,
53
+ () => t.visible,
44
54
  (e) => {
45
- r.value && s.setSeriesVisible(r.value, e);
55
+ s.value && i.setSeriesVisible(s.value, e);
46
56
  }
47
- ), (e, t) => f("", !0);
57
+ ), (e, r) => S("", !0);
48
58
  }
49
59
  });
50
60
  export {
51
- B as default
61
+ g as default
52
62
  };
@@ -2,7 +2,7 @@ import { defineComponent as d, ref as p, onMounted as f, onUnmounted as m, watch
2
2
  import { toLayers as u, syncSeriesLayer as S, EMPTY_SYNC_STATE as b } from "./core/dist/data/sync.js";
3
3
  import { CandlestickSeriesDef as _ } from "./core/dist/series/candlestick.js";
4
4
  import { useChartInstance as y } from "./context.js";
5
- const V = /* @__PURE__ */ d({
5
+ const T = /* @__PURE__ */ d({
6
6
  __name: "CandlestickSeries",
7
7
  props: {
8
8
  data: {},
@@ -49,5 +49,5 @@ const V = /* @__PURE__ */ d({
49
49
  }
50
50
  });
51
51
  export {
52
- V as default
52
+ T as default
53
53
  };
@@ -25,7 +25,7 @@ const ie = { style: { display: "flex", "flex-direction": "row", flex: "1", "min-
25
25
  grid: {},
26
26
  fade: { type: [Boolean, Object], default: void 0 },
27
27
  headerLayout: { default: "overlay" },
28
- animations: { type: [Boolean, Object] },
28
+ animations: { type: [Boolean, Object], default: void 0 },
29
29
  perf: {},
30
30
  onEdgeReached: {},
31
31
  onPointClick: {},
@@ -1,8 +1,8 @@
1
- import { defineComponent as u, ref as c, onMounted as d, onUnmounted as p, watch as n, createCommentVNode as f } from "vue";
2
- import { toLayers as m, EMPTY_SYNC_STATE as v, syncLayers as S } from "./core/dist/data/sync.js";
3
- import { LineSeriesDef as y } from "./core/dist/series/line.js";
4
- import { useChartInstance as _ } from "./context.js";
5
- const T = /* @__PURE__ */ u({
1
+ import { defineComponent as f, ref as d, onMounted as m, onUnmounted as v, watch as o, createCommentVNode as S } from "vue";
2
+ import { toLayers as c, syncLayers as y, EMPTY_SYNC_STATE as _ } from "./core/dist/data/sync.js";
3
+ import { LineSeriesDef as b } from "./core/dist/series/line.js";
4
+ import { useChartInstance as h } from "./context.js";
5
+ const g = /* @__PURE__ */ f({
6
6
  __name: "LineSeries",
7
7
  props: {
8
8
  data: {},
@@ -11,42 +11,52 @@ const T = /* @__PURE__ */ u({
11
11
  visible: { type: Boolean, default: !0 },
12
12
  scale: {}
13
13
  },
14
- setup(l) {
15
- const a = l, r = _(), s = c(null);
16
- let i = [];
17
- function o(e, t) {
18
- i = S({ chart: r, id: e, data: t, prev: i });
14
+ setup(p) {
15
+ const r = p, i = h(), s = d(null);
16
+ let a = [], n = 0;
17
+ function l(e, t) {
18
+ a = y({ chart: i, id: e, data: t, prev: a });
19
19
  }
20
- return d(() => {
21
- const e = m(a.data).length, t = r.addSeries(y, {
22
- ...a.options,
23
- scale: a.scale,
24
- layers: e,
25
- id: a.id
20
+ function u(e) {
21
+ n = c(e).length;
22
+ const t = i.addSeries(b, {
23
+ ...r.options,
24
+ scale: r.scale,
25
+ layers: n,
26
+ id: r.id
26
27
  });
27
- s.value = t, i = new Array(e).fill(v), o(t, a.data), r.setSeriesVisible(t, a.visible);
28
- }), p(() => {
29
- s.value && r.removeSeries(s.value);
30
- }), n(
31
- () => a.data,
28
+ s.value = t, a = new Array(n).fill(_), l(t, e), i.setSeriesVisible(t, r.visible);
29
+ }
30
+ return m(() => {
31
+ u(r.data);
32
+ }), v(() => {
33
+ s.value && i.removeSeries(s.value);
34
+ }), o(
35
+ () => r.data,
32
36
  (e) => {
33
37
  const t = s.value;
34
- t && o(t, e);
38
+ if (t) {
39
+ if (c(e).length !== n) {
40
+ i.removeSeries(t), u(e);
41
+ return;
42
+ }
43
+ l(t, e);
44
+ }
35
45
  }
36
- ), n(
37
- () => [a.options, a.scale],
46
+ ), o(
47
+ () => [r.options, r.scale],
38
48
  ([e, t]) => {
39
- s.value && r.updateSeriesOptions(s.value, e ? { ...e, scale: t } : { scale: t });
49
+ s.value && i.updateSeriesOptions(s.value, e ? { ...e, scale: t } : { scale: t });
40
50
  },
41
51
  { deep: !0 }
42
- ), n(
43
- () => a.visible,
52
+ ), o(
53
+ () => r.visible,
44
54
  (e) => {
45
- s.value && r.setSeriesVisible(s.value, e);
55
+ s.value && i.setSeriesVisible(s.value, e);
46
56
  }
47
- ), (e, t) => f("", !0);
57
+ ), (e, t) => S("", !0);
48
58
  }
49
59
  });
50
60
  export {
51
- T as default
61
+ g as default
52
62
  };
@@ -1,5 +1,5 @@
1
1
  import { ScalarSpring as g } from "../animation/scalar-spring.js";
2
- const l = 320, V = 0.15;
2
+ const u = 320, m = 0.15;
3
3
  class b {
4
4
  #t;
5
5
  #e;
@@ -8,53 +8,63 @@ class b {
8
8
  this.#t = new g(i), this.#e = i;
9
9
  }
10
10
  frame(i) {
11
- const { target: t, firstVisible: n, introFront: r, now: s, glide: a = !0, countUp: u = !0, reducedMotion: p = !1 } = i;
12
- if (p || !a && !u)
13
- return this.#t.snap(t, { now: s }), this.#e = t, this.#i = !0, { positionValue: t, textValue: t, opacity: 1, animating: !1 };
11
+ const { target: t, firstVisible: s, introFront: r, now: n, glide: a = !0, countUp: l = !0, reducedMotion: f = !1 } = i;
12
+ if (f || !a && !l)
13
+ return this.#t.snap(t, { now: n }), this.#e = t, this.#i = !0, { positionValue: t, textValue: t, opacity: 1, animating: !1 };
14
14
  if (r < 1) {
15
- const h = n + (t - n) * r, o = u ? h : t;
16
- return this.#t.snap(o, { now: s }), this.#e = o, this.#i = !0, { positionValue: o, textValue: o, opacity: this.#s(r), animating: !0 };
15
+ const p = s + (t - s) * r, o = l ? p : t;
16
+ return this.#t.snap(o, { now: n }), this.#e = o, this.#i = !0, { positionValue: o, textValue: o, opacity: this.#n(r), animating: !0 };
17
17
  }
18
18
  if (!this.#i)
19
- return this.#t.snap(t, { now: s }), this.#e = t, this.#i = !0, { positionValue: t, textValue: t, opacity: 1, animating: !1 };
19
+ return this.#t.snap(t, { now: n }), this.#e = t, this.#i = !0, { positionValue: t, textValue: t, opacity: 1, animating: !1 };
20
20
  if (!a)
21
- return this.#t.snap(t, { now: s }), this.#e = t, { positionValue: t, textValue: t, opacity: 1, animating: !1 };
22
- const c = i.settleMs ?? l;
21
+ return this.#t.snap(t, { now: n }), this.#e = t, { positionValue: t, textValue: t, opacity: 1, animating: !1 };
22
+ const c = i.settleMs ?? u;
23
23
  if (c <= 0)
24
- return this.#t.snap(t, { now: s }), this.#e = t, { positionValue: t, textValue: t, opacity: 1, animating: !1 };
25
- Math.abs(t - this.#e) > d && (this.#t.retarget(t, { now: s, settleMs: c }), this.#e = t);
26
- const f = this.#t.tick(s);
27
- return { positionValue: this.#t.current, textValue: t, opacity: 1, animating: f };
24
+ return this.#t.snap(t, { now: n }), this.#e = t, { positionValue: t, textValue: t, opacity: 1, animating: !1 };
25
+ Math.abs(t - this.#e) > y && (this.#t.retarget(t, { now: n, settleMs: c }), this.#e = t);
26
+ const h = this.#t.tick(n);
27
+ return { positionValue: this.#t.current, textValue: t, opacity: 1, animating: h };
28
28
  }
29
- #s(i) {
30
- return i >= 1 ? 1 : y(i / V);
29
+ #n(i) {
30
+ return i >= 1 ? 1 : V(i / m);
31
31
  }
32
32
  }
33
- const d = 1e-9;
34
- function y(e) {
33
+ const y = 1e-9;
34
+ function V(e) {
35
35
  return e <= 0 ? 0 : e >= 1 ? 1 : e;
36
36
  }
37
37
  function w(e) {
38
- return e === !1 ? { glide: !1, countUp: !1, settleMs: 0 } : e === void 0 || e === !0 ? { glide: !0, countUp: !0, settleMs: l } : {
38
+ return e === !1 ? { glide: !1, countUp: !1, settleMs: 0 } : e === void 0 || e === !0 ? { glide: !0, countUp: !0, settleMs: u } : {
39
39
  glide: e.glide ?? !0,
40
40
  countUp: e.countUp ?? !0,
41
- settleMs: e.settleMs ?? l
41
+ settleMs: e.settleMs ?? u
42
42
  };
43
43
  }
44
- function M(e, i, t) {
45
- const { from: n } = e.getVisibleRange();
46
- return e.getStackedValueAtTime(i, n) ?? t;
44
+ const d = 20;
45
+ function x(e) {
46
+ if (!(e > 0)) return 6;
47
+ if (e >= 1e3) return 0;
48
+ if (e >= 10) return 2;
49
+ if (e >= 0.1) return 4;
50
+ const i = Math.ceil(-Math.log10(e));
51
+ return Math.min(d, Math.max(6, i + 2));
47
52
  }
48
- function S(e, i) {
53
+ function S(e, i, t) {
54
+ const { from: s } = e.getVisibleRange();
55
+ return e.getStackedValueAtTime(i, s) ?? t;
56
+ }
57
+ function v(e, i) {
49
58
  if (i !== void 0) return i;
50
- const t = new Set(e.getSeriesIdsByType("band")), n = (a) => !t.has(a), r = e.getSeriesIdsByType("time", { visibleOnly: !0, singleLayerOnly: !0 }).filter(n);
59
+ const t = new Set(e.getSeriesIdsByType("band")), s = (a) => !t.has(a), r = e.getSeriesIdsByType("time", { visibleOnly: !0, singleLayerOnly: !0 }).filter(s);
51
60
  if (r.length > 0) return r[0];
52
- const s = e.getSeriesIdsByType("time", { visibleOnly: !0 }).filter(n);
53
- return s.length > 0 ? s[0] : null;
61
+ const n = e.getSeriesIdsByType("time", { visibleOnly: !0 }).filter(s);
62
+ return n.length > 0 ? n[0] : null;
54
63
  }
55
64
  export {
56
65
  b as BadgeAnimator,
57
- M as firstVisibleValue,
66
+ S as firstVisibleValue,
58
67
  w as resolveAnimate,
59
- S as resolveYLabelSeriesId
68
+ v as resolveYLabelSeriesId,
69
+ x as yLabelFractionDigits
60
70
  };