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