vue-chrts 0.1.0-beta.4 → 0.1.0-beta.5

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
19
  minMaxTicksOnly: {},
20
- yNumTicks: { default: (i) => i.data.length > 24 ? 24 / 4 : i.data.length - 1 },
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.
@@ -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.
@@ -87,7 +87,7 @@ const M = /* @__PURE__ */ b({
87
87
  "tick-format": e.xFormatter,
88
88
  label: e.xLabel,
89
89
  "grid-line": e.xGridLine,
90
- "domain-line": e.xDomainLine,
90
+ "domain-line": !!e.xDomainLine,
91
91
  "tick-line": e.xTickLine,
92
92
  "num-ticks": e.xNumTicks,
93
93
  "tick-values": e.xExplicitTicks,
@@ -97,7 +97,7 @@ const M = /* @__PURE__ */ b({
97
97
  type: "y",
98
98
  label: e.yLabel,
99
99
  "grid-line": e.orientation !== i(s).Horizontal && e.yGridLine,
100
- "domain-line": e.yDomainLine,
100
+ "domain-line": !!e.yDomainLine,
101
101
  "tick-format": e.yFormatter,
102
102
  "num-ticks": e.yNumTicks,
103
103
  "tick-line": e.yTickLine
@@ -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.
@@ -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.
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-beta.5",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"