vue-chrts 0.1.7 → 0.1.9-test.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,23 +1,30 @@
1
- import { defineComponent as G, ref as T, computed as f, createApp as N, onUnmounted as P, createElementBlock as u, openBlock as l, normalizeClass as L, createVNode as s, createCommentVNode as g, unref as o, withCtx as M, createBlock as h, Fragment as b, renderList as U, mergeProps as j } from "vue";
2
- import { Position as C, CurveType as B } from "@unovis/ts";
3
- import { VisXYContainer as I, VisTooltip as S, VisArea as w, VisLine as z, VisAxis as x, VisCrosshair as R, VisBulletLegend as X } from "@unovis/vue";
4
- import Y from "../Tooltip.js";
5
- import { LegendPosition as H } from "../../types.js";
6
- const p = 24, V = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
1
+ import { defineComponent as A, computed as y, createApp as $, createElementBlock as c, openBlock as l, normalizeClass as T, createVNode as s, createCommentVNode as f, unref as o, withCtx as E, createBlock as k, Fragment as v, renderList as G, mergeProps as N } from "vue";
2
+ import { Position as L, CurveType as h } from "@unovis/ts";
3
+ import { VisXYContainer as P, VisTooltip as j, VisArea as I, VisLine as M, VisAxis as b, VisCrosshair as S, VisBulletLegend as U } from "@unovis/vue";
4
+ import w from "../Tooltip.js";
5
+ import { LegendPosition as z } from "../../types.js";
6
+ import { getFirstPropertyValue as R } from "../../utils.js";
7
+ const p = 24, C = 4, X = 0.5, B = "#3b82f6", Z = /* @__PURE__ */ A({
7
8
  __name: "AreaChart",
8
9
  props: {
9
10
  data: {},
10
11
  height: {},
11
12
  xLabel: {},
12
13
  yLabel: {},
14
+ padding: { default: () => ({
15
+ top: 5,
16
+ right: 5,
17
+ bottom: 5,
18
+ left: 5
19
+ }) },
13
20
  categories: {},
14
21
  xFormatter: {},
15
22
  yFormatter: {},
16
23
  curveType: {},
17
- xNumTicks: { default: (i) => i.data.length > p ? p / V : i.data.length - 1 },
24
+ xNumTicks: { default: (i) => i.data.length > p ? p / C : i.data.length - 1 },
18
25
  xExplicitTicks: {},
19
26
  minMaxTicksOnly: { type: Boolean },
20
- yNumTicks: { default: (i) => i.data.length > p ? p / V : i.data.length - 1 },
27
+ yNumTicks: { default: (i) => i.data.length > p ? p / C : i.data.length - 1 },
21
28
  hideLegend: { type: Boolean },
22
29
  hideTooltip: { type: Boolean },
23
30
  legendPosition: {},
@@ -29,33 +36,31 @@ const p = 24, V = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
29
36
  yGridLine: { type: Boolean }
30
37
  },
31
38
  setup(i) {
32
- const r = i, m = Object.values(r.categories).map((e) => e.color), d = T(null), k = T(null), D = f(() => (e, t) => {
39
+ const r = i, m = Object.values(r.categories).map((e) => e.color), F = y(() => (e) => {
33
40
  if (typeof window > "u" || typeof document > "u")
34
41
  return "";
35
42
  try {
36
- const n = N(Y, {
43
+ const t = $(w, {
37
44
  data: e,
38
45
  categories: r.categories,
39
- xValue: r.xFormatter(Math.floor(t))
40
- }), a = document.createElement("div");
41
- n.mount(a);
42
- const c = a.innerHTML;
43
- return n.unmount(), c;
46
+ toolTipTitle: R(e),
47
+ yFormatter: r.yFormatter
48
+ }), n = document.createElement("div");
49
+ t.mount(n);
50
+ const a = n.innerHTML;
51
+ return t.unmount(), a;
44
52
  } catch {
45
53
  return "";
46
54
  }
47
55
  });
48
- P(() => {
49
- d.value && (d.value.unmount(), d.value = null), k.value && (k.value = null);
50
- });
51
- function F(e) {
56
+ function V(e) {
52
57
  var t;
53
58
  return {
54
59
  y: (n) => Number(n[e]),
55
- color: ((t = r.categories[e]) == null ? void 0 : t.color) ?? A
60
+ color: ((t = r.categories[e]) == null ? void 0 : t.color) ?? B
56
61
  };
57
62
  }
58
- function O(e, t) {
63
+ function D(e, t) {
59
64
  return `
60
65
  <linearGradient id="gradient${e}-${t}" gradientTransform="rotate(90)">
61
66
  <stop offset="0%" style="stop-color:var(--vis-color0);stop-opacity:1" />
@@ -63,7 +68,7 @@ const p = 24, V = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
63
68
  </linearGradient>
64
69
  `;
65
70
  }
66
- function $(e, t) {
71
+ function O(e, t) {
67
72
  return `
68
73
  <linearGradient id="gradient${e}-${t}" gradientTransform="rotate(90)">
69
74
  <stop offset="0%" stop-color="${t}" stop-opacity="1" />
@@ -71,44 +76,45 @@ const p = 24, V = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
71
76
  </linearGradient>
72
77
  `;
73
78
  }
74
- const E = f(
79
+ const x = y(
75
80
  () => m.map(
76
- (e, t) => e != null && e.includes("#") ? $(t, e) : O(t, e ?? A)
81
+ (e, t) => e != null && e.includes("#") ? O(t, e) : D(t, e ?? B)
77
82
  ).join("")
78
- ), v = f(
79
- () => r.legendPosition === H.Top
83
+ ), g = y(
84
+ () => r.legendPosition === z.Top
80
85
  );
81
- return (e, t) => (l(), u("div", {
82
- class: L(["flex flex-col space-y-4", { "flex-col-reverse": v.value }])
86
+ return (e, t) => (l(), c("div", {
87
+ class: T(["flex flex-col space-y-4", { "flex-col-reverse": g.value }])
83
88
  }, [
84
- s(o(I), {
89
+ s(o(P), {
85
90
  data: e.data,
86
91
  height: e.height,
87
- "svg-defs": E.value
92
+ padding: e.padding,
93
+ "svg-defs": x.value
88
94
  }, {
89
- default: M(() => [
90
- e.hideTooltip ? g("", !0) : (l(), h(o(S), {
95
+ default: E(() => [
96
+ e.hideTooltip ? f("", !0) : (l(), k(o(j), {
91
97
  key: 0,
92
- "horizontal-placement": o(C).Right,
93
- "vertical-placement": o(C).Top
98
+ "horizontal-placement": o(L).Right,
99
+ "vertical-placement": o(L).Top
94
100
  }, null, 8, ["horizontal-placement", "vertical-placement"])),
95
- (l(!0), u(b, null, U(Object.keys(r.categories), (n, a) => (l(), u(b, { key: a }, [
96
- s(o(w), j({
97
- x: (c, y) => y,
101
+ (l(!0), c(v, null, G(Object.keys(r.categories), (n, a) => (l(), c(v, { key: a }, [
102
+ s(o(I), N({
103
+ x: (d, u) => u,
98
104
  ref_for: !0
99
- }, F(n), {
105
+ }, V(n), {
100
106
  color: `url(#gradient${a}-${o(m)[a]})`,
101
- opacity: q,
102
- "curve-type": e.curveType ?? o(B).MonotoneX
107
+ opacity: X,
108
+ "curve-type": e.curveType ?? o(h).MonotoneX
103
109
  }), null, 16, ["x", "color", "curve-type"]),
104
- s(o(z), {
105
- x: (c, y) => y,
106
- y: (c) => c[n],
110
+ s(o(M), {
111
+ x: (d, u) => u,
112
+ y: (d) => d[n],
107
113
  color: o(m)[a],
108
- "curve-type": e.curveType ?? o(B).MonotoneX
114
+ "curve-type": e.curveType ?? o(h).MonotoneX
109
115
  }, null, 8, ["x", "y", "color", "curve-type"])
110
116
  ], 64))), 128)),
111
- s(o(x), {
117
+ s(o(b), {
112
118
  type: "x",
113
119
  "tick-format": e.xFormatter,
114
120
  label: e.xLabel,
@@ -120,7 +126,7 @@ const p = 24, V = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
120
126
  "tick-values": e.xExplicitTicks,
121
127
  "min-max-ticks-only": e.minMaxTicksOnly
122
128
  }, null, 8, ["tick-format", "label", "domain-line", "grid-line", "num-ticks", "tick-line", "tick-values", "min-max-ticks-only"]),
123
- s(o(x), {
129
+ s(o(b), {
124
130
  type: "y",
125
131
  "num-ticks": e.yNumTicks,
126
132
  "tick-format": e.yFormatter,
@@ -129,19 +135,19 @@ const p = 24, V = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
129
135
  "domain-line": e.yDomainLine,
130
136
  "tick-line": e.yTickLine
131
137
  }, null, 8, ["num-ticks", "tick-format", "label", "grid-line", "domain-line", "tick-line"]),
132
- e.hideTooltip ? g("", !0) : (l(), h(o(R), {
138
+ e.hideTooltip ? f("", !0) : (l(), k(o(S), {
133
139
  key: 1,
134
140
  color: "#666",
135
- template: D.value
141
+ template: F.value
136
142
  }, null, 8, ["template"]))
137
143
  ]),
138
144
  _: 1
139
- }, 8, ["data", "height", "svg-defs"]),
140
- e.hideLegend ? g("", !0) : (l(), u("div", {
145
+ }, 8, ["data", "height", "padding", "svg-defs"]),
146
+ e.hideLegend ? f("", !0) : (l(), c("div", {
141
147
  key: 0,
142
- class: L(["flex items-center justify-end", { "pb-4": v.value }])
148
+ class: T(["flex items-center justify-end", { "pb-4": g.value }])
143
149
  }, [
144
- s(o(X), {
150
+ s(o(U), {
145
151
  items: Object.values(e.categories)
146
152
  }, null, 8, ["items"])
147
153
  ], 2))
@@ -149,5 +155,5 @@ const p = 24, V = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
149
155
  }
150
156
  });
151
157
  export {
152
- _ as default
158
+ Z as default
153
159
  };
@@ -19,6 +19,16 @@ export interface AreaChartProps<T> {
19
19
  * Optional label for the y-axis.
20
20
  */
21
21
  yLabel?: string;
22
+ /**
23
+ * Optional padding applied to the chart.
24
+ * Allows specifying individual padding values for the top, right, bottom, and left sides.
25
+ */
26
+ padding?: {
27
+ top: number;
28
+ right: number;
29
+ bottom: number;
30
+ left: number;
31
+ };
22
32
  /**
23
33
  * A record mapping category keys to `BulletLegendItemInterface` objects.
24
34
  * This defines the visual representation and labels for each category in the chart's legend.
@@ -1,63 +1,74 @@
1
- import { defineComponent as f, computed as h, createApp as y, createElementBlock as g, openBlock as a, createVNode as r, createElementVNode as v, unref as t, withCtx as _, createBlock as V, createCommentVNode as k } from "vue";
2
- import { VisXYContainer as C, VisArea as T, VisAxis as c, VisCrosshair as b, VisBulletLegend as x } from "@unovis/vue";
3
- import { CurveType as B } from "@unovis/ts";
4
- import N from "../Tooltip.js";
5
- const A = { class: "flex flex-col space-y-4" }, j = { class: "flex items center justify-end" }, H = /* @__PURE__ */ f({
1
+ import { defineComponent as y, computed as f, createApp as h, createElementBlock as g, openBlock as r, createVNode as n, createElementVNode as B, unref as t, withCtx as L, createBlock as v, createCommentVNode as k } from "vue";
2
+ import { VisXYContainer as x, VisArea as T, VisAxis as c, VisCrosshair as b, VisBulletLegend as V } from "@unovis/vue";
3
+ import { CurveType as _ } from "@unovis/ts";
4
+ import C from "../Tooltip.js";
5
+ const N = { class: "flex flex-col space-y-4" }, A = { class: "flex items center justify-end" }, G = /* @__PURE__ */ y({
6
6
  __name: "AreaStackedChart",
7
7
  props: {
8
8
  data: {},
9
9
  height: {},
10
10
  categories: {},
11
- hideTooltip: { type: Boolean }
11
+ hideTooltip: { type: Boolean },
12
+ xLabel: {},
13
+ yLabel: {},
14
+ padding: {},
15
+ hideLegend: { type: Boolean },
16
+ xGridLine: { type: Boolean },
17
+ xDomainLine: { type: Boolean },
18
+ yGridLine: { type: Boolean },
19
+ yDomainLine: { type: Boolean },
20
+ xTickLine: { type: Boolean },
21
+ yTickLine: { type: Boolean }
12
22
  },
13
- setup(s) {
14
- const n = s, l = h(() => (e, p) => {
23
+ setup(l) {
24
+ const i = l, s = f(() => (e, m) => {
15
25
  if (typeof window > "u" || typeof document > "u")
16
26
  return "";
17
27
  try {
18
- const o = y(N, {
28
+ const o = h(C, {
19
29
  data: e,
20
- categories: n.categories
21
- }), i = document.createElement("div");
22
- o.mount(i);
23
- const d = i.innerHTML;
24
- return o.unmount(), d;
30
+ categories: i.categories
31
+ }), a = document.createElement("div");
32
+ o.mount(a);
33
+ const u = a.innerHTML;
34
+ return o.unmount(), u;
25
35
  } catch {
26
36
  return "";
27
37
  }
28
- }), m = (e) => Number.parseInt(e.time), u = [(e) => e.firstTime, (e) => e.returning];
29
- return (e, p) => (a(), g("div", A, [
30
- r(t(C), {
38
+ }), p = (e) => Number.parseInt(e.time), d = [(e) => e.firstTime, (e) => e.returning];
39
+ return (e, m) => (r(), g("div", N, [
40
+ n(t(x), {
31
41
  data: e.data,
42
+ padding: e.padding,
32
43
  height: e.height
33
44
  }, {
34
- default: _(() => [
35
- r(t(T), {
36
- x: m,
37
- y: u,
38
- color: Object.values(n.categories).map((o) => o.color),
39
- "curve-type": t(B).Linear
45
+ default: L(() => [
46
+ n(t(T), {
47
+ x: p,
48
+ y: d,
49
+ color: Object.values(i.categories).map((o) => o.color),
50
+ "curve-type": t(_).Linear
40
51
  }, null, 8, ["color", "curve-type"]),
41
- r(t(c), {
52
+ n(t(c), {
42
53
  type: "x",
43
54
  label: "Time",
44
55
  "num-ticks": 12
45
56
  }),
46
- r(t(c), {
57
+ n(t(c), {
47
58
  type: "y",
48
59
  label: "Number of visitors",
49
60
  "num-ticks": 3
50
61
  }),
51
- e.hideTooltip ? k("", !0) : (a(), V(t(b), {
62
+ e.hideTooltip ? k("", !0) : (r(), v(t(b), {
52
63
  key: 0,
53
64
  color: "#666",
54
- template: l.value
65
+ template: s.value
55
66
  }, null, 8, ["template"]))
56
67
  ]),
57
68
  _: 1
58
- }, 8, ["data", "height"]),
59
- v("div", j, [
60
- r(t(x), {
69
+ }, 8, ["data", "padding", "height"]),
70
+ B("div", A, [
71
+ n(t(V), {
61
72
  items: Object.values(e.categories)
62
73
  }, null, 8, ["items"])
63
74
  ])
@@ -65,5 +76,5 @@ const A = { class: "flex flex-col space-y-4" }, j = { class: "flex items center
65
76
  }
66
77
  });
67
78
  export {
68
- H as default
79
+ G as default
69
80
  };
@@ -1,10 +1,4 @@
1
- import { BulletLegendItemInterface } from '@unovis/ts';
2
- export type AreaStackedChartProps<T> = {
3
- data: T[];
4
- height: number;
5
- categories: Record<string, BulletLegendItemInterface>;
6
- hideTooltip?: boolean;
7
- };
1
+ import { AreaStackedChartProps } from './types';
8
2
  declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
9
3
  props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, never> & AreaStackedChartProps<T> & Partial<{}>> & import('vue').PublicProps;
10
4
  expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
@@ -27,6 +27,16 @@ export interface AreaStackedChartProps<T> {
27
27
  * Optional label for the y-axis.
28
28
  */
29
29
  yLabel?: string;
30
+ /**
31
+ * Optional padding applied to the chart.
32
+ * Allows specifying individual padding values for the top, right, bottom, and left sides.
33
+ */
34
+ padding?: {
35
+ top: number;
36
+ right: number;
37
+ bottom: number;
38
+ left: number;
39
+ };
30
40
  /**
31
41
  * If `true`, hides the chart legend.
32
42
  */
@@ -1,6 +1,6 @@
1
- import { defineComponent as v, computed as c, createApp as x, createElementBlock as f, openBlock as d, normalizeClass as b, createVNode as r, createCommentVNode as V, unref as i, withCtx as P, createBlock as L } from "vue";
1
+ import { defineComponent as v, computed as c, createApp as V, createElementBlock as f, openBlock as l, normalizeClass as b, createVNode as r, createCommentVNode as x, unref as i, withCtx as P, createBlock as h } from "vue";
2
2
  import { Orientation as s, StackedBar as A, GroupedBar as O } from "@unovis/ts";
3
- import { VisXYContainer as C, VisTooltip as G, VisGroupedBar as N, VisStackedBar as j, VisAxis as h, VisBulletLegend as w } from "@unovis/vue";
3
+ import { VisXYContainer as C, VisTooltip as G, VisGroupedBar as N, VisStackedBar as j, VisAxis as L, VisBulletLegend as w } from "@unovis/vue";
4
4
  import E from "../Tooltip.js";
5
5
  import { LegendPosition as D } from "../../types.js";
6
6
  const S = /* @__PURE__ */ v({
@@ -11,6 +11,12 @@ const S = /* @__PURE__ */ v({
11
11
  height: {},
12
12
  xLabel: {},
13
13
  yLabel: {},
14
+ padding: { default: () => ({
15
+ top: 5,
16
+ right: 5,
17
+ bottom: 5,
18
+ left: 5
19
+ }) },
14
20
  categories: {},
15
21
  xFormatter: {},
16
22
  yFormatter: {},
@@ -41,24 +47,27 @@ const S = /* @__PURE__ */ v({
41
47
  ), y = c(() => (e, t) => {
42
48
  if (typeof window > "u" || typeof document > "u")
43
49
  return "";
44
- const u = Object.keys(a.categories), B = Object.keys(e).find((o) => !u.includes(o));
50
+ const u = Object.keys(a.categories), T = Object.keys(e).find((o) => !u.includes(o));
45
51
  try {
46
- const o = x(E, {
52
+ const o = V(E, {
47
53
  data: e,
48
54
  categories: a.categories,
49
- xValue: e[B]
55
+ toolTipTitle: e[T]
50
56
  }), k = document.createElement("div");
51
57
  o.mount(k);
52
- const T = k.innerHTML;
53
- return o.unmount(), T;
58
+ const B = k.innerHTML;
59
+ return o.unmount(), B;
54
60
  } catch {
55
61
  return "";
56
62
  }
57
63
  });
58
- return (e, t) => (d(), f("div", {
64
+ return (e, t) => (l(), f("div", {
59
65
  class: b(["flex flex-col space-y-4", { "flex-col-reverse": g.value }])
60
66
  }, [
61
- r(i(C), { height: e.height }, {
67
+ r(i(C), {
68
+ padding: e.padding,
69
+ height: e.height
70
+ }, {
62
71
  default: P(() => [
63
72
  r(i(G), {
64
73
  triggers: {
@@ -66,20 +75,20 @@ const S = /* @__PURE__ */ v({
66
75
  [i(A).selectors.bar]: y.value
67
76
  }
68
77
  }, null, 8, ["triggers"]),
69
- e.stacked ? (d(), L(i(j), {
78
+ e.stacked ? (l(), h(i(j), {
70
79
  key: 1,
71
80
  data: e.data,
72
- x: (u, l) => l,
81
+ x: (u, d) => d,
73
82
  y: m.value,
74
83
  color: p,
75
84
  "rounded-corners": e.radius ?? 0,
76
85
  "group-padding": e.groupPadding ?? 0,
77
86
  "bar-padding": e.barPadding ?? 0.2,
78
87
  orientation: e.orientation ?? i(s).Vertical
79
- }, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])) : (d(), L(i(N), {
88
+ }, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])) : (l(), h(i(N), {
80
89
  key: 0,
81
90
  data: e.data,
82
- x: (u, l) => l,
91
+ x: (u, d) => d,
83
92
  y: m.value,
84
93
  color: p,
85
94
  "rounded-corners": e.radius ?? 0,
@@ -87,7 +96,7 @@ const S = /* @__PURE__ */ v({
87
96
  "bar-padding": e.barPadding ?? 0.2,
88
97
  orientation: e.orientation ?? i(s).Vertical
89
98
  }, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])),
90
- r(i(h), {
99
+ r(i(L), {
91
100
  type: "x",
92
101
  "tick-format": e.xFormatter,
93
102
  label: e.xLabel,
@@ -98,7 +107,7 @@ const S = /* @__PURE__ */ v({
98
107
  "tick-values": e.xExplicitTicks,
99
108
  "min-max-ticks-only": e.minMaxTicksOnly
100
109
  }, null, 8, ["tick-format", "label", "grid-line", "domain-line", "tick-line", "num-ticks", "tick-values", "min-max-ticks-only"]),
101
- r(i(h), {
110
+ r(i(L), {
102
111
  type: "y",
103
112
  label: e.yLabel,
104
113
  "grid-line": e.orientation !== i(s).Horizontal && e.yGridLine,
@@ -109,8 +118,8 @@ const S = /* @__PURE__ */ v({
109
118
  }, null, 8, ["label", "grid-line", "domain-line", "tick-format", "num-ticks", "tick-line"])
110
119
  ]),
111
120
  _: 1
112
- }, 8, ["height"]),
113
- e.hideLegend ? V("", !0) : (d(), f("div", {
121
+ }, 8, ["padding", "height"]),
122
+ e.hideLegend ? x("", !0) : (l(), f("div", {
114
123
  key: 0,
115
124
  class: b(["flex items center justify-end", { "pb-4": g.value }])
116
125
  }, [
@@ -22,6 +22,16 @@ export interface BarChartProps<T> {
22
22
  * Optional label for the y-axis.
23
23
  */
24
24
  yLabel?: string;
25
+ /**
26
+ * Optional padding applied to the chart.
27
+ * Allows specifying individual padding values for the top, right, bottom, and left sides.
28
+ */
29
+ padding?: {
30
+ top: number;
31
+ right: number;
32
+ bottom: number;
33
+ left: number;
34
+ };
25
35
  /**
26
36
  * A record mapping category keys to `BulletLegendItemInterface` objects.
27
37
  * This defines the visual representation and labels for each category in the chart's legend.
@@ -1,15 +1,22 @@
1
- import { defineComponent as b, computed as d, createApp as x, createElementBlock as m, openBlock as l, normalizeClass as p, createVNode as r, createCommentVNode as y, unref as i, withCtx as B, createBlock as k, Fragment as C, renderList as V } from "vue";
2
- import { Position as g, CurveType as F } from "@unovis/ts";
3
- import { VisXYContainer as N, VisTooltip as O, VisLine as j, VisAxis as f, VisCrosshair as M, VisBulletLegend as P } from "@unovis/vue";
4
- import D from "../Tooltip.js";
5
- import { LegendPosition as E } from "../../types.js";
6
- const $ = /* @__PURE__ */ b({
1
+ import { defineComponent as b, computed as p, createApp as B, createElementBlock as s, openBlock as l, normalizeClass as u, createVNode as r, createCommentVNode as y, unref as i, withCtx as x, createBlock as g, Fragment as C, renderList as V } from "vue";
2
+ import { Position as k, CurveType as F } from "@unovis/ts";
3
+ import { VisXYContainer as N, VisTooltip as O, VisLine as P, VisAxis as f, VisCrosshair as j, VisBulletLegend as D } from "@unovis/vue";
4
+ import E from "../Tooltip.js";
5
+ import { LegendPosition as G } from "../../types.js";
6
+ import { getFirstPropertyValue as M } from "../../utils.js";
7
+ const R = /* @__PURE__ */ b({
7
8
  __name: "LineChart",
8
9
  props: {
9
10
  data: {},
10
11
  height: {},
11
12
  xLabel: {},
12
13
  yLabel: {},
14
+ padding: { default: () => ({
15
+ top: 5,
16
+ right: 5,
17
+ bottom: 5,
18
+ left: 5
19
+ }) },
13
20
  categories: {},
14
21
  xFormatter: {},
15
22
  yFormatter: {},
@@ -29,40 +36,42 @@ const $ = /* @__PURE__ */ b({
29
36
  yTickLine: { type: Boolean }
30
37
  },
31
38
  setup(t) {
32
- const n = t, h = Object.values(n.categories).map((e, c) => `var(--vis-color${c})`), L = (e) => Object.values(n.categories)[e].color ?? h[e], T = d(() => (e, c) => {
39
+ const n = t, h = Object.values(n.categories).map((e, c) => `var(--vis-color${c})`), L = (e) => Object.values(n.categories)[e].color ?? h[e], T = p(() => (e, c) => {
33
40
  if (typeof window > "u" || typeof document > "u")
34
41
  return "";
35
42
  try {
36
- const o = x(D, {
43
+ const o = B(E, {
37
44
  data: e,
38
45
  categories: n.categories,
39
- xValue: n.xFormatter(Math.floor(c))
46
+ toolTipTitle: M(e),
47
+ yFormatter: n.yFormatter
40
48
  }), a = document.createElement("div");
41
49
  o.mount(a);
42
- const s = a.innerHTML;
43
- return o.unmount(), s;
50
+ const m = a.innerHTML;
51
+ return o.unmount(), m;
44
52
  } catch {
45
53
  return "";
46
54
  }
47
- }), u = d(
48
- () => n.legendPosition === E.Top
55
+ }), d = p(
56
+ () => n.legendPosition === G.Top
49
57
  );
50
- return (e, c) => (l(), m("div", {
51
- class: p(["flex flex-col space-y-4", { "flex-col-reverse": u.value }])
58
+ return (e, c) => (l(), s("div", {
59
+ class: u(["flex flex-col space-y-4", { "flex-col-reverse": d.value }])
52
60
  }, [
53
61
  r(i(N), {
54
62
  data: e.data,
63
+ padding: e.padding,
55
64
  height: e.height
56
65
  }, {
57
- default: B(() => [
66
+ default: x(() => [
58
67
  r(i(O), {
59
- "horizontal-placement": i(g).Right,
60
- "vertical-placement": i(g).Top
68
+ "horizontal-placement": i(k).Right,
69
+ "vertical-placement": i(k).Top
61
70
  }, null, 8, ["horizontal-placement", "vertical-placement"]),
62
- (l(!0), m(C, null, V(Object.keys(n.categories), (o, a) => (l(), k(i(j), {
71
+ (l(!0), s(C, null, V(Object.keys(n.categories), (o, a) => (l(), g(i(P), {
63
72
  key: a,
64
- x: (s, v) => v,
65
- y: (s) => s[o],
73
+ x: (m, v) => v,
74
+ y: (m) => m[o],
66
75
  color: L(a),
67
76
  "curve-type": e.curveType ?? i(F).MonotoneX
68
77
  }, null, 8, ["x", "y", "color", "curve-type"]))), 128)),
@@ -87,19 +96,19 @@ const $ = /* @__PURE__ */ b({
87
96
  "grid-line": e.yGridLine,
88
97
  "tick-line": e.yTickLine
89
98
  }, null, 8, ["tick-format", "label", "num-ticks", "domain-line", "grid-line", "tick-line"]),
90
- e.hideTooltip ? y("", !0) : (l(), k(i(M), {
99
+ e.hideTooltip ? y("", !0) : (l(), g(i(j), {
91
100
  key: 0,
92
101
  color: "#666",
93
102
  template: T.value
94
103
  }, null, 8, ["template"]))
95
104
  ]),
96
105
  _: 1
97
- }, 8, ["data", "height"]),
98
- e.hideLegend ? y("", !0) : (l(), m("div", {
106
+ }, 8, ["data", "padding", "height"]),
107
+ e.hideLegend ? y("", !0) : (l(), s("div", {
99
108
  key: 0,
100
- class: p(["flex items center justify-end", { "pb-4": u.value }])
109
+ class: u(["flex items center justify-end", { "pb-4": d.value }])
101
110
  }, [
102
- r(i(P), {
111
+ r(i(D), {
103
112
  items: Object.values(e.categories)
104
113
  }, null, 8, ["items"])
105
114
  ], 2))
@@ -107,5 +116,5 @@ const $ = /* @__PURE__ */ b({
107
116
  }
108
117
  });
109
118
  export {
110
- $ as default
119
+ R as default
111
120
  };
@@ -18,6 +18,16 @@ export interface LineChartProps<T> {
18
18
  * Optional label for the y-axis.
19
19
  */
20
20
  yLabel?: string;
21
+ /**
22
+ * Optional padding applied to the chart.
23
+ * Allows specifying individual padding values for the top, right, bottom, and left sides.
24
+ */
25
+ padding?: {
26
+ top: number;
27
+ right: number;
28
+ bottom: number;
29
+ left: number;
30
+ };
21
31
  /**
22
32
  * A record mapping category keys to `BulletLegendItemInterface` objects.
23
33
  * This defines the visual representation and labels for each category in the chart's legend.
@@ -1,41 +1,42 @@
1
- import { defineComponent as b, computed as v, createElementBlock as r, openBlock as l, createElementVNode as o, toDisplayString as i, Fragment as h, renderList as f, normalizeStyle as a } from "vue";
2
- const x = {
1
+ import { defineComponent as b, computed as v, createElementBlock as r, openBlock as l, createElementVNode as o, toDisplayString as i, Fragment as y, renderList as h, normalizeStyle as n } from "vue";
2
+ const f = {
3
3
  class: "capitalize border-b mb-1 pb-1",
4
4
  style: {
5
5
  color: "var(--tooltip-value-color)",
6
6
  borderColor: "rgba(255, 255, 255, 0.05)"
7
7
  }
8
- }, y = /* @__PURE__ */ b({
8
+ }, F = /* @__PURE__ */ b({
9
9
  __name: "Tooltip",
10
10
  props: {
11
11
  data: {},
12
12
  categories: {},
13
- xValue: {}
13
+ toolTipTitle: {},
14
+ yFormatter: { type: Function }
14
15
  },
15
- setup(c) {
16
- const n = c, p = ["_index", "_stacked", "_ending"], d = v(() => Object.entries(n.data ?? []).filter(
17
- ([e, u]) => !p.includes(e) && Object.keys(n.categories).includes(e)
16
+ setup(p) {
17
+ const a = p, d = ["_index", "_stacked", "_ending"], m = v(() => Object.entries(a.data ?? []).filter(
18
+ ([e, g]) => !d.includes(e) && Object.keys(a.categories).includes(e)
18
19
  ));
19
- return (e, u) => (l(), r("div", null, [
20
- o("div", x, i(e.xValue), 1),
21
- (l(!0), r(h, null, f(d.value, ([t, g], m) => {
22
- var s;
20
+ return (e, g) => (l(), r("div", null, [
21
+ o("div", f, i(e.toolTipTitle), 1),
22
+ (l(!0), r(y, null, h(m.value, ([t, s], u) => {
23
+ var c;
23
24
  return l(), r("div", {
24
25
  key: t,
25
26
  style: { display: "flex", "align-items": "center", "margin-bottom": "4px" }
26
27
  }, [
27
28
  o("span", {
28
- style: a([{ width: "8px", height: "8px", "border-radius": "4px", "margin-right": "8px" }, {
29
- backgroundColor: (s = e.categories[t]) != null && s.color ? e.categories[t].color : `var(--vis-color${m})`
29
+ style: n([{ width: "8px", height: "8px", "border-radius": "4px", "margin-right": "8px" }, {
30
+ backgroundColor: (c = e.categories[t]) != null && c.color ? e.categories[t].color : `var(--vis-color${u})`
30
31
  }])
31
32
  }, null, 4),
32
33
  o("div", null, [
33
34
  o("span", {
34
- style: a([{ "font-weight": "600", "margin-right": "8px" }, { color: "var(--tooltip-label-color)" }])
35
+ style: n([{ "font-weight": "600", "margin-right": "8px" }, { color: "var(--tooltip-label-color)" }])
35
36
  }, i(e.categories[t].name) + ":", 1),
36
37
  o("span", {
37
- style: a([{ "font-weight": "400" }, { color: "var(--tooltip-value-color)" }])
38
- }, i(g), 1)
38
+ style: n([{ "font-weight": "400" }, { color: "var(--tooltip-value-color)" }])
39
+ }, i(e.yFormatter ? e.yFormatter(s) : s), 1)
39
40
  ])
40
41
  ]);
41
42
  }), 128))
@@ -43,5 +44,5 @@ const x = {
43
44
  }
44
45
  });
45
46
  export {
46
- y as default
47
+ F as default
47
48
  };
@@ -3,7 +3,8 @@ declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>
3
3
  props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, never> & {
4
4
  data: T;
5
5
  categories: Record<string, BulletLegendItemInterface>;
6
- xValue: string | number;
6
+ toolTipTitle: string | number;
7
+ yFormatter?: (value: T) => any;
7
8
  } & Partial<{}>> & import('vue').PublicProps;
8
9
  expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
9
10
  attrs: any;
package/dist/utils.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare function getDistributedIndices(length: number, numTicks: number): number[];
2
+ export declare function getFirstPropertyValue(obj: unknown): undefined;
package/dist/utils.js ADDED
@@ -0,0 +1,9 @@
1
+ function r(e) {
2
+ if (e && Object.keys(e).length > 0) {
3
+ const t = Object.keys(e)[0];
4
+ return e[t];
5
+ }
6
+ }
7
+ export {
8
+ r as getFirstPropertyValue
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-chrts",
3
- "version": "0.1.7",
3
+ "version": "0.1.9-test.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -14,6 +14,12 @@
14
14
  "require": "./dist/index.umd.cjs"
15
15
  }
16
16
  },
17
+ "scripts": {
18
+ "dev": "vite",
19
+ "build": "vue-tsc -b && vite build",
20
+ "preview": "vite preview",
21
+ "release": "commit-and-tag-version"
22
+ },
17
23
  "peerDependencies": {
18
24
  "vue": "^3.5.13"
19
25
  },
@@ -34,10 +40,5 @@
34
40
  "vue-router": "^4.5.0",
35
41
  "vue-tsc": "^2.2.4"
36
42
  },
37
- "scripts": {
38
- "dev": "vite",
39
- "build": "vue-tsc -b && vite build",
40
- "preview": "vite preview",
41
- "release": "commit-and-tag-version"
42
- }
43
- }
43
+ "packageManager": "pnpm@8.15.4+sha256.cea6d0bdf2de3a0549582da3983c70c92ffc577ff4410cbf190817ddc35137c2"
44
+ }