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

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 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({
8
7
  __name: "AreaChart",
9
8
  props: {
10
9
  data: {},
@@ -15,8 +14,10 @@ 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 > 24 ? 24 / 4 : i.data.length - 1 },
18
+ xExplicitTicks: {},
19
+ minMaxTicksOnly: {},
20
+ yNumTicks: { default: (i) => i.data.length > 24 ? 24 / 4 : i.data.length - 1 },
20
21
  hideLegend: { type: Boolean },
21
22
  hideTooltip: { type: Boolean },
22
23
  xGridLine: { type: Boolean },
@@ -25,82 +26,81 @@ const Q = /* @__PURE__ */ D({
25
26
  yDomainLine: { type: Boolean },
26
27
  legendPosition: {}
27
28
  },
28
- setup(a) {
29
- const n = a, u = Object.values(n.categories).map((e) => e.color), V = c(() => (e) => {
29
+ setup(i) {
30
+ const s = i, m = Object.values(s.categories).map((e) => e.color), b = f(() => (e) => {
30
31
  if (typeof window > "u" || typeof document > "u")
31
32
  return "";
32
33
  try {
33
- const o = N(M, {
34
+ const o = C(A, {
34
35
  data: e,
35
- categories: n.categories
36
- }), i = document.createElement("div");
37
- o.mount(i);
38
- const r = i.innerHTML;
36
+ categories: s.categories
37
+ }), n = document.createElement("div");
38
+ o.mount(n);
39
+ const r = n.innerHTML;
39
40
  return o.unmount(), r;
40
41
  } catch {
41
42
  return "";
42
43
  }
43
44
  });
44
- function C(e) {
45
+ function x(e) {
45
46
  var o;
46
47
  return {
47
- y: (i) => Number(i[e]),
48
- color: ((o = n.categories[e]) == null ? void 0 : o.color) ?? "#3b82f6"
48
+ y: (n) => Number(n[e]),
49
+ color: ((o = s.categories[e]) == null ? void 0 : o.color) ?? "#3b82f6"
49
50
  };
50
51
  }
51
- const G = u.map(
52
+ const B = m.map(
52
53
  (e, o) => `
53
54
  <linearGradient id="gradient${o}-${e}" gradientTransform="rotate(90)">
54
55
  <stop offset="0%" stop-color="${e}" stop-opacity="1" />
55
56
  <stop offset="100%" stop-color="${e}" stop-opacity="0" />
56
57
  </linearGradient>
57
58
  `
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 }])
59
+ ).join(""), y = f(
60
+ () => s.legendPosition === E.Top
61
+ );
62
+ return (e, o) => (a(), c("div", {
63
+ class: g(["flex flex-col space-y-4", { "flex-col-reverse": y.value }])
66
64
  }, [
67
- s(t(j), {
68
- data: p.value,
65
+ l(t(P), {
66
+ data: e.data,
69
67
  height: e.height,
70
- "svg-defs": t(G)
68
+ "svg-defs": t(B)
71
69
  }, {
72
- default: $(() => [
73
- e.hideTooltip ? g("", !0) : (l(), k(t(F), {
70
+ default: G(() => [
71
+ e.hideTooltip ? d("", !0) : (a(), k(t(j), {
74
72
  key: 0,
75
- "horizontal-placement": t(T).Right,
76
- "vertical-placement": t(T).Top
73
+ "horizontal-placement": t(v).Right,
74
+ "vertical-placement": t(v).Top
77
75
  }, 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,
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,
81
79
  ref_for: !0
82
- }, C(i), {
83
- color: `url(#gradient${r}-${t(u)[r]})`,
80
+ }, x(n), {
81
+ color: `url(#gradient${r}-${t(m)[r]})`,
84
82
  opacity: 0.5,
85
- "curve-type": e.curveType ?? t(b).MonotoneX
83
+ "curve-type": e.curveType ?? t(T).MonotoneX
86
84
  }), 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
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
92
90
  }, null, 8, ["x", "y", "color", "curve-type"])
93
91
  ], 64))), 128)),
94
- s(t(B), {
92
+ l(t(L), {
95
93
  type: "x",
96
- "num-ticks": p.value.length,
97
- "tick-format": (i, r) => e.xFormatter(p.value[i], r),
94
+ "tick-format": e.xFormatter,
98
95
  label: e.xLabel,
99
- "grid-line": e.xGridLine,
96
+ "label-margin": 8,
100
97
  "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), {
98
+ "grid-line": e.xGridLine,
99
+ "num-ticks": e.xNumTicks,
100
+ "tick-values": e.xExplicitTicks,
101
+ "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), {
104
104
  type: "y",
105
105
  "num-ticks": e.yNumTicks,
106
106
  "tick-format": e.yFormatter,
@@ -109,19 +109,19 @@ const Q = /* @__PURE__ */ D({
109
109
  "domain-line": e.yDomainLine,
110
110
  "tick-line": !!e.yGridLine
111
111
  }, null, 8, ["num-ticks", "tick-format", "label", "grid-line", "domain-line", "tick-line"]),
112
- e.hideTooltip ? g("", !0) : (l(), k(t(z), {
112
+ e.hideTooltip ? d("", !0) : (a(), k(t(M), {
113
113
  key: 1,
114
114
  color: "#666",
115
- template: V.value
115
+ template: b.value
116
116
  }, null, 8, ["template"]))
117
117
  ]),
118
118
  _: 1
119
119
  }, 8, ["data", "height", "svg-defs"]),
120
- e.hideLegend ? g("", !0) : (l(), d("div", {
120
+ e.hideLegend ? d("", !0) : (a(), c("div", {
121
121
  key: 0,
122
- class: v(["flex items center justify-end", { "pb-4": h.value }])
122
+ class: g(["flex items center justify-end", { "pb-4": y.value }])
123
123
  }, [
124
- s(t(I), {
124
+ l(t(O), {
125
125
  items: Object.values(e.categories)
126
126
  }, null, 8, ["items"])
127
127
  ], 2))
@@ -129,5 +129,5 @@ const Q = /* @__PURE__ */ D({
129
129
  }
130
130
  });
131
131
  export {
132
- Q as default
132
+ Y as default
133
133
  };
@@ -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.
29
+ * @param i The x-axis key of the item to be formatted.
30
30
  * @param idx The index of the data point.
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
  */
@@ -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,71 +32,68 @@ 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
90
  "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), {
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,
@@ -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.
32
+ * @param i The x-axis key of the item to be formatted.
33
33
  * @param idx The index of the data point.
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,14 +25,14 @@ 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.
28
+ * @param i The x-axis key of the item to be formatted.
29
29
  * @param idx The index of the data point.
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
  */
@@ -43,17 +43,25 @@ export interface LineChartProps<T> {
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.4",
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
- };