vue-chrts 1.0.2 → 2.0.0-beta.2

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,13 +1,13 @@
1
- import { defineComponent as N, useSlots as W, useTemplateRef as E, ref as M, computed as u, createElementBlock as y, openBlock as s, normalizeClass as w, normalizeStyle as k, createVNode as m, createCommentVNode as d, createElementVNode as X, unref as n, withCtx as z, createBlock as c, Fragment as h, renderList as R, mergeProps as f, renderSlot as T } from "vue";
2
- import { Position as C, CurveType as L } from "@unovis/ts";
3
- import { createMarkers as Y, getFirstPropertyValue as U } from "../../utils.js";
4
- import H from "../Tooltip.js";
5
- import { VisXYContainer as q, VisTooltip as J, VisArea as K, VisLine as Q, VisAxis as A, VisCrosshair as Z, VisBulletLegend as I } from "@unovis/vue";
6
- import { LegendPosition as _ } from "../../types.js";
7
- const ee = {
1
+ import { defineComponent as W, useSlots as E, useTemplateRef as M, ref as w, computed as m, createElementBlock as f, openBlock as c, normalizeStyle as x, createVNode as y, createCommentVNode as d, createElementVNode as X, unref as o, withCtx as R, createBlock as g, Fragment as T, renderList as Y, mergeProps as k, renderSlot as L } from "vue";
2
+ import { Position as C, CurveType as A } from "@unovis/ts";
3
+ import { createMarkers as z } from "../../utils.js";
4
+ import U from "../Tooltip.js";
5
+ import { VisXYContainer as H, VisTooltip as q, VisArea as J, VisLine as K, VisAxis as $, VisCrosshair as Q, VisBulletLegend as Z } from "@unovis/vue";
6
+ import { LegendPosition as I } from "../../types.js";
7
+ const _ = ["id"], ee = {
8
8
  ref: "slotWrapper",
9
9
  style: { display: "none" }
10
- }, ie = 0.5, $ = "#3b82f6", se = /* @__PURE__ */ N({
10
+ }, te = 0.5, D = "#3b82f6", se = /* @__PURE__ */ W({
11
11
  __name: "AreaChart",
12
12
  props: {
13
13
  data: {},
@@ -19,6 +19,7 @@ const ee = {
19
19
  markerConfig: {},
20
20
  xFormatter: {},
21
21
  yFormatter: {},
22
+ tooltipTitleFormatter: {},
22
23
  curveType: {},
23
24
  hideArea: { type: Boolean, default: !1 },
24
25
  gradientStops: { default: () => [
@@ -33,7 +34,7 @@ const ee = {
33
34
  yNumTicks: {},
34
35
  hideLegend: { type: Boolean, default: !1 },
35
36
  hideTooltip: { type: Boolean },
36
- legendPosition: { default: _.BottomCenter },
37
+ legendPosition: { default: I.BottomCenter },
37
38
  legendStyle: { default: void 0 },
38
39
  xDomainLine: { type: Boolean },
39
40
  yDomainLine: { type: Boolean },
@@ -52,154 +53,160 @@ const ee = {
52
53
  xDomain: {}
53
54
  },
54
55
  emits: ["click"],
55
- setup(D, { emit: b }) {
56
- const B = b, t = D, O = W(), v = E("slotWrapper"), p = M(), g = u(() => {
57
- const e = Object.values(t.categories).map(
58
- (a, i) => `var(--vis-color${i})`
56
+ setup(e, { emit: b }) {
57
+ const B = b, n = e, O = E(), p = M("slotWrapper"), u = w(), v = m(() => {
58
+ const a = Object.values(n.categories).map(
59
+ (l, i) => `var(--vis-color${i})`
59
60
  );
60
- return Object.values(t.categories).map(
61
- (a, i) => a.color ?? e[i]
61
+ return Object.values(n.categories).map(
62
+ (l, i) => l.color ?? a[i]
62
63
  );
63
- }), V = u(() => t.markerConfig ? Y(t.markerConfig) : ""), x = u(() => t.legendPosition.startsWith("top")), F = u(() => t.legendPosition.includes("left") ? "flex-start" : t.legendPosition.includes("right") ? "flex-end" : "center"), G = u(() => {
64
- const e = (i, o) => {
64
+ }), F = m(() => {
65
+ var a;
66
+ return (a = n.markerConfig) != null && a.config ? z(n.markerConfig) : "";
67
+ }), V = m(() => n.legendPosition.startsWith("top")), G = m(() => n.legendPosition.includes("left") ? "flex-start" : n.legendPosition.includes("right") ? "flex-end" : "center"), S = m(() => {
68
+ const a = (i, t) => {
65
69
  var r;
66
70
  return `
67
- <linearGradient id="gradient${i}-${o}" gradientTransform="rotate(90)">
68
- ${((r = t.gradientStops) == null ? void 0 : r.map(
69
- (l) => `<stop offset="${l.offset}" stop-color="${o}" stop-opacity="${l.stopOpacity}" />`
71
+ <linearGradient id="gradient${i}-${t}" gradientTransform="rotate(90)">
72
+ ${((r = n.gradientStops) == null ? void 0 : r.map(
73
+ (s) => `<stop offset="${s.offset}" stop-color="${t}" stop-opacity="${s.stopOpacity}" />`
70
74
  ).join("")) ?? ""}
71
- <stop offset="100%" stop-color="${o}" stop-opacity="0" />
75
+ <stop offset="100%" stop-color="${t}" stop-opacity="0" />
72
76
  </linearGradient>
73
77
  `;
74
- }, a = (i, o) => {
78
+ }, l = (i, t) => {
75
79
  var r;
76
80
  return `
77
- <linearGradient id="gradient${i}-${o}" gradientTransform="rotate(90)">
81
+ <linearGradient id="gradient${i}-${t}" gradientTransform="rotate(90)">
78
82
 
79
- ${((r = t.gradientStops) == null ? void 0 : r.map(
80
- (l) => `
81
- <stop offset="${l.offset}" style="stop-color:var(${o});stop-opacity:${l.stopOpacity}" />
83
+ ${((r = n.gradientStops) == null ? void 0 : r.map(
84
+ (s) => `
85
+ <stop offset="${s.offset}" style="stop-color:var(${t});stop-opacity:${s.stopOpacity}" />
82
86
  `
83
87
  ).join("")) ?? ""}
84
88
  </linearGradient>
85
89
  `;
86
90
  };
87
- return g.value.map(
88
- (i, o) => i != null && i.includes("#") ? e(o, i) : a(o, i ?? $)
91
+ return v.value.map(
92
+ (i, t) => i != null && i.includes("#") ? a(t, i) : l(t, i ?? D)
89
93
  ).join("");
90
94
  });
91
- function P(e) {
92
- var a;
95
+ function j(a) {
96
+ var l;
93
97
  return {
94
- y: (i) => Number(i[e]),
95
- color: ((a = t.categories[e]) == null ? void 0 : a.color) ?? $
98
+ y: (i) => Number(i[a]),
99
+ color: ((l = n.categories[a]) == null ? void 0 : l.color) ?? D
96
100
  };
97
101
  }
98
- function S(e) {
99
- return typeof window > "u" ? "" : v.value ? v.value.innerHTML : "";
102
+ function N(a) {
103
+ return typeof window > "u" ? "" : p.value ? p.value.innerHTML : "";
100
104
  }
101
- function j(e) {
102
- return p.value = e, S();
105
+ function P(a) {
106
+ return u.value = a, N();
103
107
  }
104
- return (e, a) => (s(), y("div", {
105
- style: k({
106
- display: "flex",
107
- flexDirection: x.value ? "column-reverse" : "column",
108
- gap: "var(--vis-legend-spacing)"
109
- }),
110
- class: w({ markers: !!t.markerConfig }),
111
- onClick: a[0] || (a[0] = (i) => B("click", i, p.value))
112
- }, [
113
- m(n(q), {
114
- data: e.data,
115
- height: e.height,
116
- padding: e.padding,
117
- "svg-defs": G.value + V.value,
118
- "y-domain": e.yDomain,
119
- "x-domain": e.xDomain
120
- }, {
121
- default: z(() => [
122
- e.hideTooltip ? d("", !0) : (s(), c(n(J), {
123
- key: 0,
124
- "horizontal-placement": n(C).Right,
125
- "vertical-placement": n(C).Top
126
- }, null, 8, ["horizontal-placement", "vertical-placement"])),
127
- (s(!0), y(h, null, R(Object.keys(t.categories), (i, o) => (s(), y(h, { key: i }, [
128
- m(n(K), f({
129
- x: (r, l) => l
130
- }, { ref_for: !0 }, P(i), {
131
- color: `url(#gradient${o}-${g.value[o]})`,
132
- opacity: e.hideArea ? 0 : ie,
133
- "curve-type": e.curveType ?? n(L).MonotoneX
134
- }), null, 16, ["x", "color", "opacity", "curve-type"]),
135
- m(n(Q), {
136
- x: (r, l) => l,
137
- y: (r) => r[i],
138
- color: g.value[o],
139
- "curve-type": e.curveType ?? n(L).MonotoneX,
140
- "line-width": e.lineWidth,
141
- lineDashArray: e.lineDashArray ? e.lineDashArray[o] : void 0
142
- }, null, 8, ["x", "y", "color", "curve-type", "line-width", "lineDashArray"])
143
- ], 64))), 128)),
144
- e.hideXAxis ? d("", !0) : (s(), c(n(A), f({
145
- key: 1,
146
- type: "x",
147
- label: e.xLabel,
148
- "label-margin": 8,
149
- "num-ticks": e.xNumTicks,
150
- "tick-format": e.xFormatter,
151
- "tick-values": e.xExplicitTicks,
152
- "grid-line": e.xGridLine,
153
- "domain-line": e.xDomainLine,
154
- "tick-line": e.xTickLine,
155
- "min-max-ticks-only": e.minMaxTicksOnly
156
- }, e.xAxisConfig), null, 16, ["label", "num-ticks", "tick-format", "tick-values", "grid-line", "domain-line", "tick-line", "min-max-ticks-only"])),
157
- e.hideYAxis ? d("", !0) : (s(), c(n(A), f({
158
- key: 2,
159
- type: "y",
160
- label: e.yLabel,
161
- "num-ticks": e.yNumTicks,
162
- "tick-format": e.yFormatter,
163
- "grid-line": e.yGridLine,
164
- "domain-line": e.yDomainLine,
165
- "tick-line": e.yTickLine
166
- }, e.yAxisConfig), null, 16, ["label", "num-ticks", "tick-format", "grid-line", "domain-line", "tick-line"])),
167
- e.hideTooltip ? d("", !0) : (s(), c(n(Z), f({ key: 3 }, e.crosshairConfig, { template: j }), null, 16))
168
- ]),
169
- _: 1
170
- }, 8, ["data", "height", "padding", "svg-defs", "y-domain", "x-domain"]),
171
- t.hideLegend ? d("", !0) : (s(), y("div", {
172
- key: 0,
173
- style: k({
108
+ return (a, l) => {
109
+ var i;
110
+ return c(), f("div", {
111
+ style: x({
174
112
  display: "flex",
175
- justifyContent: F.value
176
- })
113
+ flexDirection: V.value ? "column-reverse" : "column",
114
+ gap: "var(--vis-legend-spacing)"
115
+ }),
116
+ id: (i = e.markerConfig) == null ? void 0 : i.id,
117
+ onClick: l[0] || (l[0] = (t) => B("click", t, u.value))
177
118
  }, [
178
- m(n(I), {
179
- style: k([
180
- t.legendStyle,
181
- "display: flex; gap: var(--vis-legend-spacing);"
119
+ y(o(H), {
120
+ data: e.data,
121
+ height: e.height,
122
+ padding: e.padding,
123
+ "svg-defs": S.value + F.value,
124
+ "y-domain": e.yDomain,
125
+ "x-domain": e.xDomain
126
+ }, {
127
+ default: R(() => [
128
+ e.hideTooltip ? d("", !0) : (c(), g(o(q), {
129
+ key: 0,
130
+ "horizontal-placement": o(C).Right,
131
+ "vertical-placement": o(C).Top
132
+ }, null, 8, ["horizontal-placement", "vertical-placement"])),
133
+ (c(!0), f(T, null, Y(Object.keys(n.categories), (t, r) => (c(), f(T, { key: t }, [
134
+ y(o(J), k({
135
+ x: (s, h) => h
136
+ }, { ref_for: !0 }, j(t), {
137
+ color: `url(#gradient${r}-${v.value[r]})`,
138
+ opacity: e.hideArea ? 0 : te,
139
+ "curve-type": e.curveType ?? o(A).MonotoneX
140
+ }), null, 16, ["x", "color", "opacity", "curve-type"]),
141
+ y(o(K), {
142
+ x: (s, h) => h,
143
+ y: (s) => s[t],
144
+ color: v.value[r],
145
+ "curve-type": e.curveType ?? o(A).MonotoneX,
146
+ "line-width": e.lineWidth,
147
+ lineDashArray: e.lineDashArray ? e.lineDashArray[r] : void 0
148
+ }, null, 8, ["x", "y", "color", "curve-type", "line-width", "lineDashArray"])
149
+ ], 64))), 128)),
150
+ e.hideXAxis ? d("", !0) : (c(), g(o($), k({
151
+ key: 1,
152
+ type: "x",
153
+ label: e.xLabel,
154
+ "label-margin": 8,
155
+ "num-ticks": e.xNumTicks,
156
+ "tick-format": e.xFormatter,
157
+ "tick-values": e.xExplicitTicks,
158
+ "grid-line": e.xGridLine,
159
+ "domain-line": e.xDomainLine,
160
+ "tick-line": e.xTickLine,
161
+ "min-max-ticks-only": e.minMaxTicksOnly
162
+ }, e.xAxisConfig), null, 16, ["label", "num-ticks", "tick-format", "tick-values", "grid-line", "domain-line", "tick-line", "min-max-ticks-only"])),
163
+ e.hideYAxis ? d("", !0) : (c(), g(o($), k({
164
+ key: 2,
165
+ type: "y",
166
+ label: e.yLabel,
167
+ "num-ticks": e.yNumTicks,
168
+ "tick-format": e.yFormatter,
169
+ "grid-line": e.yGridLine,
170
+ "domain-line": e.yDomainLine,
171
+ "tick-line": e.yTickLine
172
+ }, e.yAxisConfig), null, 16, ["label", "num-ticks", "tick-format", "grid-line", "domain-line", "tick-line"])),
173
+ e.hideTooltip ? d("", !0) : (c(), g(o(Q), k({ key: 3 }, e.crosshairConfig, { template: P }), null, 16))
182
174
  ]),
183
- items: Object.values(t.categories).map((i) => ({
184
- ...i,
185
- color: Array.isArray(i.color) ? i.color[0] : i.color
186
- }))
187
- }, null, 8, ["style", "items"])
188
- ], 4)),
189
- X("div", ee, [
190
- n(O).tooltip ? T(e.$slots, "tooltip", {
175
+ _: 1
176
+ }, 8, ["data", "height", "padding", "svg-defs", "y-domain", "x-domain"]),
177
+ n.hideLegend ? d("", !0) : (c(), f("div", {
191
178
  key: 0,
192
- values: p.value
193
- }) : p.value ? T(e.$slots, "fallback", { key: 1 }, () => [
194
- m(H, {
195
- data: p.value,
196
- categories: e.categories,
197
- toolTipTitle: n(U)(p.value) ?? "",
198
- yFormatter: t.yFormatter
199
- }, null, 8, ["data", "categories", "toolTipTitle", "yFormatter"])
200
- ]) : d("", !0)
201
- ], 512)
202
- ], 6));
179
+ style: x({
180
+ display: "flex",
181
+ justifyContent: G.value
182
+ })
183
+ }, [
184
+ y(o(Z), {
185
+ style: x([
186
+ n.legendStyle,
187
+ "display: flex; gap: var(--vis-legend-spacing);"
188
+ ]),
189
+ items: Object.values(n.categories).map((t) => ({
190
+ ...t,
191
+ color: Array.isArray(t.color) ? t.color[0] : t.color
192
+ }))
193
+ }, null, 8, ["style", "items"])
194
+ ], 4)),
195
+ X("div", ee, [
196
+ o(O).tooltip ? L(a.$slots, "tooltip", {
197
+ key: 0,
198
+ values: u.value
199
+ }) : u.value ? L(a.$slots, "fallback", { key: 1 }, () => [
200
+ y(U, {
201
+ data: u.value,
202
+ categories: e.categories,
203
+ "title-formatter": n.tooltipTitleFormatter,
204
+ yFormatter: n.yFormatter
205
+ }, null, 8, ["data", "categories", "title-formatter", "yFormatter"])
206
+ ]) : d("", !0)
207
+ ], 512)
208
+ ], 12, _);
209
+ };
203
210
  }
204
211
  });
205
212
  export {
@@ -37,15 +37,25 @@ export interface AreaChartProps<T> {
37
37
  /**
38
38
  * A record mapping marker keys to show custom patterns.
39
39
  */
40
- markerConfig?: Record<string, MarkerConfig>;
40
+ markerConfig?: MarkerConfig;
41
41
  /**
42
- * A function that formats the x-axis tick labels.
42
+ * @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.
43
+ * @param {number} i - The index of the tick in the `ticks` array.
44
+ * @param {(number[]|Date[])} ticks - An array of all tick values for the x-axis.
45
+ * @returns {string} The formatted string representation of the tick.
43
46
  */
44
47
  xFormatter?: axisFormatter;
45
48
  /**
46
- * A function that formats the y-axis tick labels.
49
+ * @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.
50
+ * @param {number} i - The index of the tick in the `ticks` array.
51
+ * @param {(number[]|Date[])} ticks - An array of all tick values for the y-axis.
52
+ * @returns {string} The formatted string representation of the tick.
47
53
  */
48
54
  yFormatter?: axisFormatter;
55
+ /**
56
+ * Use custom formatter for tooltip titles
57
+ */
58
+ tooltipTitleFormatter?: (data: T) => string | number;
49
59
  /**
50
60
  * The type of curve to use for the area chart lines.
51
61
  * See `CurveType` for available options.