vue-chrts 0.1.0-beta.4 → 0.1.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.
@@ -1,9 +1,9 @@
1
- import { defineComponent as V, computed as f, createApp as C, createElementBlock as c, openBlock as a, normalizeClass as g, createVNode as l, createCommentVNode as d, unref as t, withCtx as G, createBlock as k, Fragment as h, renderList as N, mergeProps as $ } from "vue";
2
- import { Position as v, CurveType as T } from "@unovis/ts";
3
- import { VisXYContainer as P, VisTooltip as j, VisArea as D, VisLine as F, VisAxis as L, VisCrosshair as M, VisBulletLegend as O } from "@unovis/vue";
4
- import A from "../Tooltip.js";
5
- import { LegendPosition as E } from "../../types.js";
6
- const Y = /* @__PURE__ */ V({
1
+ import { defineComponent as E, ref as T, computed as g, createApp as F, onUnmounted as $, createElementBlock as p, openBlock as r, normalizeClass as L, createVNode as s, createCommentVNode as v, unref as o, withCtx as N, createBlock as h, Fragment as b, renderList as G, mergeProps as P } from "vue";
2
+ import { Position as x, CurveType as C } from "@unovis/ts";
3
+ import { VisXYContainer as U, VisTooltip as j, VisArea as I, VisLine as M, VisAxis as B, VisCrosshair as w, VisBulletLegend as z } from "@unovis/vue";
4
+ import R from "../Tooltip.js";
5
+ import { LegendPosition as X } from "../../types.js";
6
+ const m = 24, A = 4, Y = 0.5, H = "#3b82f6", Z = /* @__PURE__ */ E({
7
7
  __name: "AreaChart",
8
8
  props: {
9
9
  data: {},
@@ -14,82 +14,91 @@ const Y = /* @__PURE__ */ V({
14
14
  xFormatter: {},
15
15
  yFormatter: {},
16
16
  curveType: {},
17
- xNumTicks: { default: (i) => i.data.length > 24 ? 24 / 4 : i.data.length - 1 },
17
+ xNumTicks: { default: (i) => i.data.length > m ? m / A : i.data.length - 1 },
18
18
  xExplicitTicks: {},
19
- minMaxTicksOnly: {},
20
- yNumTicks: { default: (i) => i.data.length > 24 ? 24 / 4 : i.data.length - 1 },
19
+ minMaxTicksOnly: { type: Boolean },
20
+ yNumTicks: { default: (i) => i.data.length > m ? m / A : i.data.length - 1 },
21
21
  hideLegend: { type: Boolean },
22
22
  hideTooltip: { type: Boolean },
23
23
  xGridLine: { type: Boolean },
24
24
  xDomainLine: { type: Boolean },
25
25
  yGridLine: { type: Boolean },
26
26
  yDomainLine: { type: Boolean },
27
+ xTickLine: { type: Boolean },
27
28
  legendPosition: {}
28
29
  },
29
30
  setup(i) {
30
- const s = i, m = Object.values(s.categories).map((e) => e.color), b = f(() => (e) => {
31
+ const l = i, d = Object.values(l.categories).map((e) => e.color), n = T(null), a = T(null), D = g(() => (e) => {
31
32
  if (typeof window > "u" || typeof document > "u")
32
33
  return "";
33
34
  try {
34
- const o = C(A, {
35
- data: e,
36
- categories: s.categories
37
- }), n = document.createElement("div");
38
- o.mount(n);
39
- const r = n.innerHTML;
40
- return o.unmount(), r;
41
- } catch {
42
- return "";
35
+ if (a.value || (a.value = document.createElement("div")), !n.value)
36
+ n.value = F(R, {
37
+ data: e,
38
+ categories: l.categories
39
+ }), n.value.mount(a.value);
40
+ else {
41
+ const t = n.value._instance;
42
+ t != null && t.proxy && (t.proxy.$props.data = e, t.proxy.$props.categories = l.categories);
43
+ }
44
+ return a.value.innerHTML;
45
+ } catch (t) {
46
+ return console.error("Error generating tooltip:", t), "";
43
47
  }
44
48
  });
45
- function x(e) {
46
- var o;
49
+ $(() => {
50
+ n.value && (n.value.unmount(), n.value = null), a.value && (a.value = null);
51
+ });
52
+ function O(e) {
53
+ var t;
47
54
  return {
48
- y: (n) => Number(n[e]),
49
- color: ((o = s.categories[e]) == null ? void 0 : o.color) ?? "#3b82f6"
55
+ y: (c) => Number(c[e]),
56
+ color: ((t = l.categories[e]) == null ? void 0 : t.color) ?? H
50
57
  };
51
58
  }
52
- const B = m.map(
53
- (e, o) => `
54
- <linearGradient id="gradient${o}-${e}" gradientTransform="rotate(90)">
59
+ const V = g(
60
+ () => d.map(
61
+ (e, t) => `
62
+ <linearGradient id="gradient${t}-${e}" gradientTransform="rotate(90)">
55
63
  <stop offset="0%" stop-color="${e}" stop-opacity="1" />
56
64
  <stop offset="100%" stop-color="${e}" stop-opacity="0" />
57
65
  </linearGradient>
58
66
  `
59
- ).join(""), y = f(
60
- () => s.legendPosition === E.Top
67
+ ).join("")
68
+ ), k = g(
69
+ () => l.legendPosition === X.Top
61
70
  );
62
- return (e, o) => (a(), c("div", {
63
- class: g(["flex flex-col space-y-4", { "flex-col-reverse": y.value }])
71
+ return (e, t) => (r(), p("div", {
72
+ class: L(["flex flex-col space-y-4", { "flex-col-reverse": k.value }])
64
73
  }, [
65
- l(t(P), {
74
+ s(o(U), {
66
75
  data: e.data,
67
76
  height: e.height,
68
- "svg-defs": t(B)
77
+ "svg-defs": V.value
69
78
  }, {
70
- default: G(() => [
71
- e.hideTooltip ? d("", !0) : (a(), k(t(j), {
79
+ default: N(() => [
80
+ e.hideTooltip ? v("", !0) : (r(), h(o(j), {
72
81
  key: 0,
73
- "horizontal-placement": t(v).Right,
74
- "vertical-placement": t(v).Top
82
+ "horizontal-placement": o(x).Right,
83
+ "vertical-placement": o(x).Top
75
84
  }, null, 8, ["horizontal-placement", "vertical-placement"])),
76
- (a(!0), c(h, null, N(Object.keys(s.categories), (n, r) => (a(), c(h, { key: r }, [
77
- l(t(D), $({
78
- x: (p, u) => u,
85
+ (r(!0), p(b, null, G(Object.keys(l.categories), (c, u) => (r(), p(b, { key: u }, [
86
+ s(o(I), P({
87
+ x: (y, f) => f,
79
88
  ref_for: !0
80
- }, x(n), {
81
- color: `url(#gradient${r}-${t(m)[r]})`,
82
- opacity: 0.5,
83
- "curve-type": e.curveType ?? t(T).MonotoneX
89
+ }, O(c), {
90
+ color: `url(#gradient${u}-${o(d)[u]})`,
91
+ opacity: Y,
92
+ "curve-type": e.curveType ?? o(C).MonotoneX
84
93
  }), null, 16, ["x", "color", "curve-type"]),
85
- l(t(F), {
86
- x: (p, u) => u,
87
- y: (p) => p[n],
88
- color: t(m)[r],
89
- "curve-type": e.curveType ?? t(T).MonotoneX
94
+ s(o(M), {
95
+ x: (y, f) => f,
96
+ y: (y) => y[c],
97
+ color: o(d)[u],
98
+ "curve-type": e.curveType ?? o(C).MonotoneX
90
99
  }, null, 8, ["x", "y", "color", "curve-type"])
91
100
  ], 64))), 128)),
92
- l(t(L), {
101
+ s(o(B), {
93
102
  type: "x",
94
103
  "tick-format": e.xFormatter,
95
104
  label: e.xLabel,
@@ -97,10 +106,11 @@ const Y = /* @__PURE__ */ V({
97
106
  "domain-line": e.xDomainLine,
98
107
  "grid-line": e.xGridLine,
99
108
  "num-ticks": e.xNumTicks,
109
+ "tick-line": e.xTickLine,
100
110
  "tick-values": e.xExplicitTicks,
101
111
  "min-max-ticks-only": e.minMaxTicksOnly
102
- }, null, 8, ["tick-format", "label", "domain-line", "grid-line", "num-ticks", "tick-values", "min-max-ticks-only"]),
103
- l(t(L), {
112
+ }, null, 8, ["tick-format", "label", "domain-line", "grid-line", "num-ticks", "tick-line", "tick-values", "min-max-ticks-only"]),
113
+ s(o(B), {
104
114
  type: "y",
105
115
  "num-ticks": e.yNumTicks,
106
116
  "tick-format": e.yFormatter,
@@ -109,19 +119,19 @@ const Y = /* @__PURE__ */ V({
109
119
  "domain-line": e.yDomainLine,
110
120
  "tick-line": !!e.yGridLine
111
121
  }, null, 8, ["num-ticks", "tick-format", "label", "grid-line", "domain-line", "tick-line"]),
112
- e.hideTooltip ? d("", !0) : (a(), k(t(M), {
122
+ e.hideTooltip ? v("", !0) : (r(), h(o(w), {
113
123
  key: 1,
114
124
  color: "#666",
115
- template: b.value
125
+ template: D.value
116
126
  }, null, 8, ["template"]))
117
127
  ]),
118
128
  _: 1
119
129
  }, 8, ["data", "height", "svg-defs"]),
120
- e.hideLegend ? d("", !0) : (a(), c("div", {
130
+ e.hideLegend ? v("", !0) : (r(), p("div", {
121
131
  key: 0,
122
- class: g(["flex items center justify-end", { "pb-4": y.value }])
132
+ class: L(["flex items-center justify-end", { "pb-4": k.value }])
123
133
  }, [
124
- l(t(O), {
134
+ s(o(z), {
125
135
  items: Object.values(e.categories)
126
136
  }, null, 8, ["items"])
127
137
  ], 2))
@@ -129,5 +139,5 @@ const Y = /* @__PURE__ */ V({
129
139
  }
130
140
  });
131
141
  export {
132
- Y as default
142
+ Z as default
133
143
  };
@@ -27,10 +27,10 @@ export interface AreaChartProps<T> {
27
27
  /**
28
28
  * A function that formats the x-axis tick labels.
29
29
  * @param i The x-axis key of the item to be formatted.
30
- * @param idx The index of the data point.
30
+ * @param idx The index of the data point (optional).
31
31
  * @returns The formatted x-axis label.
32
32
  */
33
- xFormatter: (i: number, idx: number) => string | number;
33
+ xFormatter: (i: number, idx?: number) => string | number;
34
34
  /**
35
35
  * An optional function that formats the y-axis tick labels.
36
36
  * @param i The y-axis key of the item to be formatted.
@@ -54,7 +54,7 @@ export interface AreaChartProps<T> {
54
54
  /**
55
55
  * Force only first and last ticks on the x-axis.
56
56
  */
57
- minMaxTicksOnly?: number;
57
+ minMaxTicksOnly?: boolean;
58
58
  /**
59
59
  * The desired number of ticks on the y-axis.
60
60
  */
@@ -83,6 +83,10 @@ export interface AreaChartProps<T> {
83
83
  * If `true`, displays a domain line (axis line) along the y-axis.
84
84
  */
85
85
  yDomainLine?: boolean;
86
+ /**
87
+ * If `true`, displays tick lines on the x-axis.
88
+ */
89
+ xTickLine?: boolean;
86
90
  /**
87
91
  * Optional position for the legend, if applicable.
88
92
  * See `LegendPosition` for available options.
@@ -1,9 +1,9 @@
1
- import { defineComponent as b, computed as u, createApp as h, createElementBlock as y, openBlock as d, normalizeClass as k, createVNode as t, createCommentVNode as B, unref as i, withCtx as T, createBlock as f } from "vue";
2
- import { Orientation as s, StackedBar as v, GroupedBar as V } from "@unovis/ts";
3
- import { VisXYContainer as P, VisTooltip as x, VisGroupedBar as C, VisStackedBar as G, VisAxis as L, VisBulletLegend as N } from "@unovis/vue";
4
- import A from "../Tooltip.js";
5
- import { LegendPosition as O } from "../../types.js";
6
- const M = /* @__PURE__ */ b({
1
+ import { defineComponent as h, computed as u, createApp as b, createElementBlock as y, openBlock as d, normalizeClass as k, createVNode as r, createCommentVNode as B, unref as i, withCtx as T, createBlock as f } from "vue";
2
+ import { Orientation as s, StackedBar as v, GroupedBar as x } from "@unovis/ts";
3
+ import { VisXYContainer as V, VisTooltip as P, VisGroupedBar as A, VisStackedBar as C, VisAxis as L, VisBulletLegend as G } from "@unovis/vue";
4
+ import N from "../Tooltip.js";
5
+ import { LegendPosition as w } from "../../types.js";
6
+ const M = /* @__PURE__ */ h({
7
7
  __name: "BarChart",
8
8
  props: {
9
9
  data: {},
@@ -15,7 +15,7 @@ const M = /* @__PURE__ */ b({
15
15
  xFormatter: {},
16
16
  yFormatter: {},
17
17
  yNumTicks: { default: (a) => a.data.length > 24 ? 24 / 4 : a.data.length - 1 },
18
- minMaxTicksOnly: {},
18
+ minMaxTicksOnly: { type: Boolean },
19
19
  xNumTicks: { default: (a) => a.data.length > 24 ? 24 / 4 : a.data.length - 1 },
20
20
  xExplicitTicks: {},
21
21
  yAxis: {},
@@ -33,19 +33,22 @@ const M = /* @__PURE__ */ b({
33
33
  yGridLine: { type: Boolean, default: !0 }
34
34
  },
35
35
  setup(a) {
36
- const r = a, m = u(() => r.yAxis.map((e) => (n) => n[e])), c = (e, n) => Object.values(r.categories)[n].color, p = u(
37
- () => r.legendPosition === O.Top
36
+ const o = a;
37
+ if (!o.yAxis || o.yAxis.length === 0)
38
+ throw new Error("yAxis is required");
39
+ const c = u(() => o.yAxis.map((e) => (n) => n[e])), m = (e, n) => Object.values(o.categories)[n].color, p = u(
40
+ () => o.legendPosition === w.Top
38
41
  ), g = u(() => (e) => {
39
42
  if (typeof window > "u" || typeof document > "u")
40
43
  return "";
41
44
  try {
42
- const n = h(A, {
45
+ const n = b(N, {
43
46
  data: e,
44
- categories: r.categories
47
+ categories: o.categories
45
48
  }), l = document.createElement("div");
46
49
  n.mount(l);
47
- const o = l.innerHTML;
48
- return n.unmount(), o;
50
+ const t = l.innerHTML;
51
+ return n.unmount(), t;
49
52
  } catch {
50
53
  return "";
51
54
  }
@@ -53,55 +56,55 @@ const M = /* @__PURE__ */ b({
53
56
  return (e, n) => (d(), y("div", {
54
57
  class: k(["flex flex-col space-y-4", { "flex-col-reverse": p.value }])
55
58
  }, [
56
- t(i(P), { height: e.height }, {
59
+ r(i(V), { height: e.height }, {
57
60
  default: T(() => [
58
- t(i(x), {
61
+ r(i(P), {
59
62
  triggers: {
60
- [i(V).selectors.bar]: g.value,
63
+ [i(x).selectors.bar]: g.value,
61
64
  [i(v).selectors.bar]: g.value
62
65
  }
63
66
  }, null, 8, ["triggers"]),
64
- e.stacked ? (d(), f(i(G), {
67
+ e.stacked ? (d(), f(i(C), {
65
68
  key: 1,
66
69
  data: e.data,
67
- x: (l, o) => o,
68
- y: m.value,
69
- color: c,
70
+ x: (l, t) => t,
71
+ y: c.value,
72
+ color: m,
70
73
  "rounded-corners": e.radius ?? 0,
71
74
  "group-padding": e.groupPadding ?? 0,
72
75
  "bar-padding": e.barPadding ?? 0.2,
73
76
  orientation: e.orientation ?? i(s).Vertical
74
- }, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])) : (d(), f(i(C), {
77
+ }, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])) : (d(), f(i(A), {
75
78
  key: 0,
76
79
  data: e.data,
77
- x: (l, o) => o,
78
- y: m.value,
79
- color: c,
80
+ x: (l, t) => t,
81
+ y: c.value,
82
+ color: m,
80
83
  "rounded-corners": e.radius ?? 0,
81
84
  "group-padding": e.groupPadding ?? 0,
82
85
  "bar-padding": e.barPadding ?? 0.2,
83
86
  orientation: e.orientation ?? i(s).Vertical
84
87
  }, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])),
85
- t(i(L), {
88
+ r(i(L), {
86
89
  type: "x",
87
90
  "tick-format": e.xFormatter,
88
91
  label: e.xLabel,
89
92
  "grid-line": e.xGridLine,
90
- "domain-line": e.xDomainLine,
93
+ "domain-line": !!e.xDomainLine,
91
94
  "tick-line": e.xTickLine,
92
95
  "num-ticks": e.xNumTicks,
93
96
  "tick-values": e.xExplicitTicks,
94
97
  "min-max-ticks-only": e.minMaxTicksOnly
95
98
  }, null, 8, ["tick-format", "label", "grid-line", "domain-line", "tick-line", "num-ticks", "tick-values", "min-max-ticks-only"]),
96
- t(i(L), {
99
+ r(i(L), {
97
100
  type: "y",
98
101
  label: e.yLabel,
99
102
  "grid-line": e.orientation !== i(s).Horizontal && e.yGridLine,
100
- "domain-line": e.yDomainLine,
101
- "tick-format": e.yFormatter,
103
+ "domain-line": !!e.yDomainLine,
104
+ "tick-format": () => "",
102
105
  "num-ticks": e.yNumTicks,
103
106
  "tick-line": e.yTickLine
104
- }, null, 8, ["label", "grid-line", "domain-line", "tick-format", "num-ticks", "tick-line"])
107
+ }, null, 8, ["label", "grid-line", "domain-line", "num-ticks", "tick-line"])
105
108
  ]),
106
109
  _: 1
107
110
  }, 8, ["height"]),
@@ -109,7 +112,7 @@ const M = /* @__PURE__ */ b({
109
112
  key: 0,
110
113
  class: k(["flex items center justify-end", { "pb-4": p.value }])
111
114
  }, [
112
- t(i(N), {
115
+ r(i(G), {
113
116
  items: Object.values(e.categories)
114
117
  }, null, 8, ["items"])
115
118
  ], 2))
@@ -30,10 +30,10 @@ export interface BarChartProps<T> {
30
30
  /**
31
31
  * A function that formats the x-axis tick labels.
32
32
  * @param i The x-axis key of the item to be formatted.
33
- * @param idx The index of the data point.
33
+ * @param idx The index of the data point (optional).
34
34
  * @returns The formatted x-axis label.
35
35
  */
36
- xFormatter: (i: number, idx: number) => string | number;
36
+ xFormatter: (i: number, idx?: number) => string | number;
37
37
  /**
38
38
  * An optional function that formats the y-axis tick labels.
39
39
  * @param i The y-axis key of the item to be formatted.
@@ -48,7 +48,7 @@ export interface BarChartProps<T> {
48
48
  /**
49
49
  * Force only first and last ticks on the x-axis.
50
50
  */
51
- minMaxTicksOnly?: number;
51
+ minMaxTicksOnly?: boolean;
52
52
  /**
53
53
  * The desired number of ticks on the x-axis.
54
54
  */
@@ -16,7 +16,7 @@ const X = /* @__PURE__ */ v({
16
16
  curveType: {},
17
17
  xNumTicks: { default: (t) => t.data.length > 24 ? 24 / 4 : t.data.length - 1 },
18
18
  xExplicitTicks: {},
19
- minMaxTicksOnly: {},
19
+ minMaxTicksOnly: { type: Boolean },
20
20
  yNumTicks: { default: (t) => t.data.length > 24 ? 24 / 4 : t.data.length - 1 },
21
21
  hideTooltip: { type: Boolean },
22
22
  hideLegend: { type: Boolean },
@@ -26,17 +26,17 @@ export interface LineChartProps<T> {
26
26
  /**
27
27
  * A function that formats the x-axis tick labels.
28
28
  * @param i The x-axis key of the item to be formatted.
29
- * @param idx The index of the data point.
29
+ * @param idx The index of the data point (optional).
30
30
  * @returns The formatted x-axis label.
31
31
  */
32
- xFormatter: (i: number, idx: number) => string | number;
32
+ xFormatter: (i: number, idx?: number) => string | number;
33
33
  /**
34
34
  * An optional function that formats the y-axis tick labels.
35
35
  * @param i The y-axis key of the item to be formatted.
36
36
  * @param idx The index of the data point.
37
37
  * @returns The formatted y-axis label.
38
38
  */
39
- yFormatter?: (i: number, idx: number) => string;
39
+ yFormatter?: (i: number, idx?: number) => string;
40
40
  /**
41
41
  * The type of curve to use for the line chart.
42
42
  * See `CurveType` for available options.
@@ -53,7 +53,7 @@ export interface LineChartProps<T> {
53
53
  /**
54
54
  * Force only first and last ticks on the x-axis.
55
55
  */
56
- minMaxTicksOnly?: number;
56
+ minMaxTicksOnly?: boolean;
57
57
  /**
58
58
  * The desired number of ticks on the y-axis.
59
59
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-chrts",
3
- "version": "0.1.0-beta.4",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"