vue-chrts 0.1.8 → 0.1.9

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,10 @@
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 n, 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 V, 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, x = 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: {},
@@ -20,10 +21,10 @@ const p = 24, x = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
20
21
  xFormatter: {},
21
22
  yFormatter: {},
22
23
  curveType: {},
23
- xNumTicks: { default: (i) => i.data.length > p ? p / x : i.data.length - 1 },
24
+ xNumTicks: { default: (i) => i.data.length > p ? p / C : i.data.length - 1 },
24
25
  xExplicitTicks: {},
25
26
  minMaxTicksOnly: { type: Boolean },
26
- yNumTicks: { default: (i) => i.data.length > p ? p / x : i.data.length - 1 },
27
+ yNumTicks: { default: (i) => i.data.length > p ? p / C : i.data.length - 1 },
27
28
  hideLegend: { type: Boolean },
28
29
  hideTooltip: { type: Boolean },
29
30
  legendPosition: {},
@@ -35,33 +36,31 @@ const p = 24, x = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
35
36
  yGridLine: { type: Boolean }
36
37
  },
37
38
  setup(i) {
38
- 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) => {
39
40
  if (typeof window > "u" || typeof document > "u")
40
41
  return "";
41
42
  try {
42
- const o = N(Y, {
43
+ const t = $(w, {
43
44
  data: e,
44
45
  categories: r.categories,
45
- xValue: r.xFormatter(Math.floor(t))
46
- }), a = document.createElement("div");
47
- o.mount(a);
48
- const c = a.innerHTML;
49
- return o.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;
50
52
  } catch {
51
53
  return "";
52
54
  }
53
55
  });
54
- P(() => {
55
- d.value && (d.value.unmount(), d.value = null), k.value && (k.value = null);
56
- });
57
- function F(e) {
56
+ function V(e) {
58
57
  var t;
59
58
  return {
60
- y: (o) => Number(o[e]),
61
- color: ((t = r.categories[e]) == null ? void 0 : t.color) ?? A
59
+ y: (n) => Number(n[e]),
60
+ color: ((t = r.categories[e]) == null ? void 0 : t.color) ?? B
62
61
  };
63
62
  }
64
- function O(e, t) {
63
+ function D(e, t) {
65
64
  return `
66
65
  <linearGradient id="gradient${e}-${t}" gradientTransform="rotate(90)">
67
66
  <stop offset="0%" style="stop-color:var(--vis-color0);stop-opacity:1" />
@@ -69,7 +68,7 @@ const p = 24, x = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
69
68
  </linearGradient>
70
69
  `;
71
70
  }
72
- function $(e, t) {
71
+ function O(e, t) {
73
72
  return `
74
73
  <linearGradient id="gradient${e}-${t}" gradientTransform="rotate(90)">
75
74
  <stop offset="0%" stop-color="${t}" stop-opacity="1" />
@@ -77,45 +76,45 @@ const p = 24, x = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
77
76
  </linearGradient>
78
77
  `;
79
78
  }
80
- const E = f(
79
+ const x = y(
81
80
  () => m.map(
82
- (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)
83
82
  ).join("")
84
- ), v = f(
85
- () => r.legendPosition === H.Top
83
+ ), g = y(
84
+ () => r.legendPosition === z.Top
86
85
  );
87
- return (e, t) => (l(), u("div", {
88
- 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 }])
89
88
  }, [
90
- s(n(I), {
89
+ s(o(P), {
91
90
  data: e.data,
92
91
  height: e.height,
93
92
  padding: e.padding,
94
- "svg-defs": E.value
93
+ "svg-defs": x.value
95
94
  }, {
96
- default: M(() => [
97
- e.hideTooltip ? g("", !0) : (l(), h(n(S), {
95
+ default: E(() => [
96
+ e.hideTooltip ? f("", !0) : (l(), k(o(j), {
98
97
  key: 0,
99
- "horizontal-placement": n(C).Right,
100
- "vertical-placement": n(C).Top
98
+ "horizontal-placement": o(L).Right,
99
+ "vertical-placement": o(L).Top
101
100
  }, null, 8, ["horizontal-placement", "vertical-placement"])),
102
- (l(!0), u(b, null, U(Object.keys(r.categories), (o, a) => (l(), u(b, { key: a }, [
103
- s(n(w), j({
104
- 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,
105
104
  ref_for: !0
106
- }, F(o), {
107
- color: `url(#gradient${a}-${n(m)[a]})`,
108
- opacity: q,
109
- "curve-type": e.curveType ?? n(B).MonotoneX
105
+ }, V(n), {
106
+ color: `url(#gradient${a}-${o(m)[a]})`,
107
+ opacity: X,
108
+ "curve-type": e.curveType ?? o(h).MonotoneX
110
109
  }), null, 16, ["x", "color", "curve-type"]),
111
- s(n(z), {
112
- x: (c, y) => y,
113
- y: (c) => c[o],
114
- color: n(m)[a],
115
- "curve-type": e.curveType ?? n(B).MonotoneX
110
+ s(o(M), {
111
+ x: (d, u) => u,
112
+ y: (d) => d[n],
113
+ color: o(m)[a],
114
+ "curve-type": e.curveType ?? o(h).MonotoneX
116
115
  }, null, 8, ["x", "y", "color", "curve-type"])
117
116
  ], 64))), 128)),
118
- s(n(V), {
117
+ s(o(b), {
119
118
  type: "x",
120
119
  "tick-format": e.xFormatter,
121
120
  label: e.xLabel,
@@ -127,7 +126,7 @@ const p = 24, x = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
127
126
  "tick-values": e.xExplicitTicks,
128
127
  "min-max-ticks-only": e.minMaxTicksOnly
129
128
  }, null, 8, ["tick-format", "label", "domain-line", "grid-line", "num-ticks", "tick-line", "tick-values", "min-max-ticks-only"]),
130
- s(n(V), {
129
+ s(o(b), {
131
130
  type: "y",
132
131
  "num-ticks": e.yNumTicks,
133
132
  "tick-format": e.yFormatter,
@@ -136,19 +135,19 @@ const p = 24, x = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
136
135
  "domain-line": e.yDomainLine,
137
136
  "tick-line": e.yTickLine
138
137
  }, null, 8, ["num-ticks", "tick-format", "label", "grid-line", "domain-line", "tick-line"]),
139
- e.hideTooltip ? g("", !0) : (l(), h(n(R), {
138
+ e.hideTooltip ? f("", !0) : (l(), k(o(S), {
140
139
  key: 1,
141
140
  color: "#666",
142
- template: D.value
141
+ template: F.value
143
142
  }, null, 8, ["template"]))
144
143
  ]),
145
144
  _: 1
146
145
  }, 8, ["data", "height", "padding", "svg-defs"]),
147
- e.hideLegend ? g("", !0) : (l(), u("div", {
146
+ e.hideLegend ? f("", !0) : (l(), c("div", {
148
147
  key: 0,
149
- class: L(["flex items-center justify-end", { "pb-4": v.value }])
148
+ class: T(["flex items-center justify-end", { "pb-4": g.value }])
150
149
  }, [
151
- s(n(X), {
150
+ s(o(U), {
152
151
  items: Object.values(e.categories)
153
152
  }, null, 8, ["items"])
154
153
  ], 2))
@@ -156,5 +155,5 @@ const p = 24, x = 4, q = 0.5, A = "#3b82f6", _ = /* @__PURE__ */ G({
156
155
  }
157
156
  });
158
157
  export {
159
- _ as default
158
+ Z as default
160
159
  };
@@ -47,16 +47,16 @@ const S = /* @__PURE__ */ v({
47
47
  ), y = c(() => (e, t) => {
48
48
  if (typeof window > "u" || typeof document > "u")
49
49
  return "";
50
- 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));
51
51
  try {
52
52
  const o = V(E, {
53
53
  data: e,
54
54
  categories: a.categories,
55
- xValue: e[B]
55
+ toolTipTitle: e[T]
56
56
  }), k = document.createElement("div");
57
57
  o.mount(k);
58
- const T = k.innerHTML;
59
- return o.unmount(), T;
58
+ const B = k.innerHTML;
59
+ return o.unmount(), B;
60
60
  } catch {
61
61
  return "";
62
62
  }
@@ -1,9 +1,10 @@
1
- import { defineComponent as b, computed as u, createApp as B, createElementBlock as s, openBlock as l, normalizeClass as p, createVNode as r, createCommentVNode as y, unref as i, withCtx as x, createBlock as g, Fragment as C, renderList as V } from "vue";
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
2
  import { Position as k, 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({
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: {},
@@ -35,14 +36,15 @@ const $ = /* @__PURE__ */ b({
35
36
  yTickLine: { type: Boolean }
36
37
  },
37
38
  setup(t) {
38
- 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 = u(() => (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) => {
39
40
  if (typeof window > "u" || typeof document > "u")
40
41
  return "";
41
42
  try {
42
- const o = B(D, {
43
+ const o = B(E, {
43
44
  data: e,
44
45
  categories: n.categories,
45
- xValue: n.xFormatter(Math.floor(c))
46
+ toolTipTitle: M(e),
47
+ yFormatter: n.yFormatter
46
48
  }), a = document.createElement("div");
47
49
  o.mount(a);
48
50
  const m = a.innerHTML;
@@ -50,11 +52,11 @@ const $ = /* @__PURE__ */ b({
50
52
  } catch {
51
53
  return "";
52
54
  }
53
- }), d = u(
54
- () => n.legendPosition === E.Top
55
+ }), d = p(
56
+ () => n.legendPosition === G.Top
55
57
  );
56
58
  return (e, c) => (l(), s("div", {
57
- class: p(["flex flex-col space-y-4", { "flex-col-reverse": d.value }])
59
+ class: u(["flex flex-col space-y-4", { "flex-col-reverse": d.value }])
58
60
  }, [
59
61
  r(i(N), {
60
62
  data: e.data,
@@ -66,7 +68,7 @@ const $ = /* @__PURE__ */ b({
66
68
  "horizontal-placement": i(k).Right,
67
69
  "vertical-placement": i(k).Top
68
70
  }, null, 8, ["horizontal-placement", "vertical-placement"]),
69
- (l(!0), s(C, null, V(Object.keys(n.categories), (o, a) => (l(), g(i(j), {
71
+ (l(!0), s(C, null, V(Object.keys(n.categories), (o, a) => (l(), g(i(P), {
70
72
  key: a,
71
73
  x: (m, v) => v,
72
74
  y: (m) => m[o],
@@ -94,7 +96,7 @@ const $ = /* @__PURE__ */ b({
94
96
  "grid-line": e.yGridLine,
95
97
  "tick-line": e.yTickLine
96
98
  }, null, 8, ["tick-format", "label", "num-ticks", "domain-line", "grid-line", "tick-line"]),
97
- e.hideTooltip ? y("", !0) : (l(), g(i(M), {
99
+ e.hideTooltip ? y("", !0) : (l(), g(i(j), {
98
100
  key: 0,
99
101
  color: "#666",
100
102
  template: T.value
@@ -104,9 +106,9 @@ const $ = /* @__PURE__ */ b({
104
106
  }, 8, ["data", "padding", "height"]),
105
107
  e.hideLegend ? y("", !0) : (l(), s("div", {
106
108
  key: 0,
107
- class: p(["flex items center justify-end", { "pb-4": d.value }])
109
+ class: u(["flex items center justify-end", { "pb-4": d.value }])
108
110
  }, [
109
- r(i(P), {
111
+ r(i(D), {
110
112
  items: Object.values(e.categories)
111
113
  }, null, 8, ["items"])
112
114
  ], 2))
@@ -114,5 +116,5 @@ const $ = /* @__PURE__ */ b({
114
116
  }
115
117
  });
116
118
  export {
117
- $ as default
119
+ R as default
118
120
  };
@@ -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.8",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"