vue-chrts 0.1.9 → 0.1.11

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