vue-chrts 2.0.0-beta.5 → 2.1.0-beta.0.1

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 z, useSlots as R, useTemplateRef as U, ref as H, computed as d, createElementBlock as f, openBlock as c, normalizeClass as K, normalizeStyle as p, createVNode as u, createCommentVNode as y, createElementVNode as q, unref as r, withCtx as J, createBlock as k, Fragment as T, renderList as Q, mergeProps as v, renderSlot as b } from "vue";
2
- import { Position as $, CurveType as h } from "@unovis/ts";
3
- import { createMarkers as Z } from "../../utils.js";
4
- import I from "../Tooltip.js";
5
- import { VisXYContainer as _, VisTooltip as ee, VisArea as B, VisLine as D, VisAxis as O, VisCrosshair as te, VisBulletLegend as ie } from "@unovis/vue";
6
- import { LegendPosition as ae } from "../../types.js";
7
- const ne = ["id"], oe = {
1
+ import { defineComponent as H, useSlots as I, useTemplateRef as K, ref as q, getCurrentInstance as J, computed as c, createElementBlock as f, openBlock as d, normalizeClass as Q, normalizeStyle as p, createVNode as u, createCommentVNode as m, createElementVNode as Z, unref as l, withCtx as _, createBlock as k, Fragment as T, renderList as ee, mergeProps as v, renderSlot as B } from "vue";
2
+ import { Position as D, CurveType as h } from "@unovis/ts";
3
+ import { createScopedMarkers as te } from "../../utils.js";
4
+ import ie from "../Tooltip.js";
5
+ import { VisXYContainer as ne, VisTooltip as ae, VisArea as O, VisLine as V, VisAxis as F, VisCrosshair as oe, VisBulletLegend as re } from "@unovis/vue";
6
+ import { LegendPosition as le } from "../../types.js";
7
+ const se = ["id"], ce = {
8
8
  ref: "slotWrapper",
9
9
  style: { display: "none" }
10
- }, F = 0.5, A = "#3b82f6", ye = /* @__PURE__ */ z({
10
+ }, S = 0.5, C = "#3b82f6", ke = /* @__PURE__ */ H({
11
11
  __name: "AreaChart",
12
12
  props: {
13
13
  data: {},
@@ -34,7 +34,7 @@ const ne = ["id"], oe = {
34
34
  yNumTicks: {},
35
35
  hideLegend: { type: Boolean, default: !1 },
36
36
  hideTooltip: { type: Boolean },
37
- legendPosition: { default: ae.BottomCenter },
37
+ legendPosition: { default: le.BottomCenter },
38
38
  legendStyle: { default: void 0 },
39
39
  xDomainLine: { type: Boolean },
40
40
  yDomainLine: { type: Boolean },
@@ -54,128 +54,137 @@ const ne = ["id"], oe = {
54
54
  stacked: { type: Boolean }
55
55
  },
56
56
  emits: ["click"],
57
- setup(e, { emit: V }) {
58
- const j = V, n = e, G = R(), C = U("slotWrapper"), m = H(), g = d(() => {
59
- const i = Object.values(n.categories).map(
60
- (l, a) => `var(--vis-color${a})`
57
+ setup(e, { emit: j }) {
58
+ var b;
59
+ const G = j, a = e, N = I(), A = K("slotWrapper"), y = q(), L = `area-${((b = J()) == null ? void 0 : b.uid) ?? Math.random().toString(36).slice(2)}`, g = c(() => {
60
+ const t = Object.values(a.categories).map(
61
+ (o, n) => `var(--vis-color${n})`
61
62
  );
62
- return Object.values(n.categories).map(
63
- (l, a) => l.color ?? i[a]
63
+ return Object.values(a.categories).map(
64
+ (o, n) => o.color ?? t[n]
64
65
  );
65
- }), N = d(() => {
66
- var i;
67
- return (i = n.markerConfig) != null && i.config ? Z(n.markerConfig) : "";
68
- }), S = d(() => n.legendPosition.startsWith("top")), W = d(() => n.legendPosition.includes("left") ? "flex-start" : n.legendPosition.includes("right") ? "flex-end" : "center"), M = d(() => {
69
- const i = (a, t) => {
70
- var o;
66
+ }), M = c(() => {
67
+ var t;
68
+ return (t = a.markerConfig) != null && t.config ? te(a.markerConfig, L) : "";
69
+ }), W = c(() => {
70
+ var o;
71
+ if (!((o = a.markerConfig) != null && o.config)) return {};
72
+ const t = {};
73
+ for (const n of Object.keys(a.markerConfig.config))
74
+ t[`--vis-marker-${n}`] = `url("#${a.markerConfig.id}--${L}--${n}")`;
75
+ return t;
76
+ }), P = c(() => a.legendPosition.startsWith("top")), w = c(() => a.legendPosition.includes("left") ? "flex-start" : a.legendPosition.includes("right") ? "flex-end" : "center"), X = c(() => {
77
+ const t = (n, i) => {
78
+ var r;
71
79
  return `
72
- <linearGradient id="gradient${a}-${t}" gradientTransform="rotate(90)">
73
- ${((o = n.gradientStops) == null ? void 0 : o.map(
74
- (s) => `<stop offset="${s.offset}" stop-color="${t}" stop-opacity="${s.stopOpacity}" />`
80
+ <linearGradient id="gradient${n}-${i}" gradientTransform="rotate(90)">
81
+ ${((r = a.gradientStops) == null ? void 0 : r.map(
82
+ (s) => `<stop offset="${s.offset}" stop-color="${i}" stop-opacity="${s.stopOpacity}" />`
75
83
  ).join("")) ?? ""}
76
- <stop offset="100%" stop-color="${t}" stop-opacity="0" />
84
+ <stop offset="100%" stop-color="${i}" stop-opacity="0" />
77
85
  </linearGradient>
78
86
  `;
79
- }, l = (a, t) => {
80
- var o;
87
+ }, o = (n, i) => {
88
+ var r;
81
89
  return `
82
- <linearGradient id="gradient${a}-${t}" gradientTransform="rotate(90)">
90
+ <linearGradient id="gradient${n}-${i}" gradientTransform="rotate(90)">
83
91
 
84
- ${((o = n.gradientStops) == null ? void 0 : o.map(
92
+ ${((r = a.gradientStops) == null ? void 0 : r.map(
85
93
  (s) => `
86
- <stop offset="${s.offset}" style="stop-color:var(${t});stop-opacity:${s.stopOpacity}" />
94
+ <stop offset="${s.offset}" style="stop-color:var(${i});stop-opacity:${s.stopOpacity}" />
87
95
  `
88
96
  ).join("")) ?? ""}
89
97
  </linearGradient>
90
98
  `;
91
99
  };
92
100
  return g.value.map(
93
- (a, t) => a != null && a.includes("#") ? i(t, a) : l(t, a ?? A)
101
+ (n, i) => n != null && n.includes("#") ? t(i, n) : o(i, n ?? C)
94
102
  ).join("");
95
103
  });
96
- function P(i) {
97
- var l;
104
+ function E(t) {
105
+ var o;
98
106
  return {
99
- y: (a) => Number(a[i]),
100
- color: ((l = n.categories[i]) == null ? void 0 : l.color) ?? A
107
+ y: (n) => Number(n[t]),
108
+ color: ((o = a.categories[t]) == null ? void 0 : o.color) ?? C
101
109
  };
102
110
  }
103
- const w = d(() => Object.keys(n.categories).map(
104
- (i) => (l) => Number(l[i])
105
- )), X = d(() => {
106
- const i = Object.keys(n.categories);
107
- return i.map((l, a) => (t) => {
108
- let o = 0;
109
- for (let s = 0; s <= a; s++)
110
- o += Number(t[i[s]]) || 0;
111
- return o;
111
+ const Y = c(() => Object.keys(a.categories).map(
112
+ (t) => (o) => Number(o[t])
113
+ )), z = c(() => {
114
+ const t = Object.keys(a.categories);
115
+ return t.map((o, n) => (i) => {
116
+ let r = 0;
117
+ for (let s = 0; s <= n; s++)
118
+ r += Number(i[t[s]]) || 0;
119
+ return r;
112
120
  });
113
- }), L = d(() => (i, l) => g.value[l] ?? A);
114
- function E(i) {
115
- return typeof window > "u" ? "" : C.value ? C.value.innerHTML : "";
121
+ }), $ = c(() => (t, o) => g.value[o] ?? C);
122
+ function R(t) {
123
+ return typeof window > "u" ? "" : A.value ? A.value.innerHTML : "";
116
124
  }
117
- function Y(i) {
118
- return m.value = i, E();
125
+ function U(t) {
126
+ return y.value = t, R();
119
127
  }
120
- return (i, l) => {
121
- var a;
122
- return c(), f("div", {
128
+ return (t, o) => {
129
+ var n;
130
+ return d(), f("div", {
123
131
  style: p({
124
132
  display: "flex",
125
- flexDirection: S.value ? "column-reverse" : "column",
126
- gap: "var(--vis-legend-spacing)"
133
+ flexDirection: P.value ? "column-reverse" : "column",
134
+ gap: "var(--vis-legend-spacing)",
135
+ ...W.value
127
136
  }),
128
- class: K({ "stacked-area-chart": e.stacked }),
129
- id: (a = e.markerConfig) == null ? void 0 : a.id,
130
- onClick: l[0] || (l[0] = (t) => j("click", t, m.value))
137
+ class: Q({ "stacked-area-chart": e.stacked }),
138
+ id: (n = e.markerConfig) == null ? void 0 : n.id,
139
+ onClick: o[0] || (o[0] = (i) => G("click", i, y.value))
131
140
  }, [
132
- u(r(_), {
141
+ u(l(ne), {
133
142
  data: e.data,
134
143
  height: e.height,
135
144
  padding: e.padding,
136
- "svg-defs": M.value + N.value,
145
+ "svg-defs": X.value + M.value,
137
146
  "y-domain": e.yDomain,
138
147
  "x-domain": e.xDomain
139
148
  }, {
140
- default: J(() => [
141
- e.hideTooltip ? y("", !0) : (c(), k(r(ee), {
149
+ default: _(() => [
150
+ e.hideTooltip ? m("", !0) : (d(), k(l(ae), {
142
151
  key: 0,
143
- "horizontal-placement": r($).Right,
144
- "vertical-placement": r($).Top
152
+ "horizontal-placement": l(D).Right,
153
+ "vertical-placement": l(D).Top
145
154
  }, null, 8, ["horizontal-placement", "vertical-placement"])),
146
- e.stacked ? (c(), f(T, { key: 1 }, [
147
- u(r(B), {
148
- x: (t, o) => o,
149
- y: w.value,
150
- color: L.value,
151
- opacity: e.hideArea ? 0 : F,
152
- "curve-type": e.curveType ?? r(h).MonotoneX
155
+ e.stacked ? (d(), f(T, { key: 1 }, [
156
+ u(l(O), {
157
+ x: (i, r) => r,
158
+ y: Y.value,
159
+ color: $.value,
160
+ opacity: e.hideArea ? 0 : S,
161
+ "curve-type": e.curveType ?? l(h).MonotoneX
153
162
  }, null, 8, ["x", "y", "color", "opacity", "curve-type"]),
154
- u(r(D), {
155
- x: (t, o) => o,
156
- y: X.value,
157
- color: L.value,
158
- "curve-type": e.curveType ?? r(h).MonotoneX,
163
+ u(l(V), {
164
+ x: (i, r) => r,
165
+ y: z.value,
166
+ color: $.value,
167
+ "curve-type": e.curveType ?? l(h).MonotoneX,
159
168
  "line-width": e.lineWidth
160
169
  }, null, 8, ["x", "y", "color", "curve-type", "line-width"])
161
- ], 64)) : (c(!0), f(T, { key: 2 }, Q(Object.keys(n.categories), (t, o) => (c(), f(T, { key: t }, [
162
- u(r(B), v({
170
+ ], 64)) : (d(!0), f(T, { key: 2 }, ee(Object.keys(a.categories), (i, r) => (d(), f(T, { key: i }, [
171
+ u(l(O), v({
163
172
  x: (s, x) => x
164
- }, { ref_for: !0 }, P(t), {
165
- color: `url(#gradient${o}-${g.value[o]})`,
166
- opacity: e.hideArea ? 0 : F,
167
- "curve-type": e.curveType ?? r(h).MonotoneX
173
+ }, { ref_for: !0 }, E(i), {
174
+ color: `url(#gradient${r}-${g.value[r]})`,
175
+ opacity: e.hideArea ? 0 : S,
176
+ "curve-type": e.curveType ?? l(h).MonotoneX
168
177
  }), null, 16, ["x", "color", "opacity", "curve-type"]),
169
- u(r(D), {
178
+ u(l(V), {
170
179
  x: (s, x) => x,
171
- y: (s) => s[t],
172
- color: g.value[o],
173
- "curve-type": e.curveType ?? r(h).MonotoneX,
180
+ y: (s) => s[i],
181
+ color: g.value[r],
182
+ "curve-type": e.curveType ?? l(h).MonotoneX,
174
183
  "line-width": e.lineWidth,
175
- lineDashArray: e.lineDashArray ? e.lineDashArray[o] : void 0
184
+ lineDashArray: e.lineDashArray ? e.lineDashArray[r] : void 0
176
185
  }, null, 8, ["x", "y", "color", "curve-type", "line-width", "lineDashArray"])
177
186
  ], 64))), 128)),
178
- e.hideXAxis ? y("", !0) : (c(), k(r(O), v({
187
+ e.hideXAxis ? m("", !0) : (d(), k(l(F), v({
179
188
  key: 3,
180
189
  type: "x",
181
190
  label: e.xLabel,
@@ -188,7 +197,7 @@ const ne = ["id"], oe = {
188
197
  "tick-line": e.xTickLine,
189
198
  "min-max-ticks-only": e.minMaxTicksOnly
190
199
  }, e.xAxisConfig), null, 16, ["label", "num-ticks", "tick-format", "tick-values", "grid-line", "domain-line", "tick-line", "min-max-ticks-only"])),
191
- e.hideYAxis ? y("", !0) : (c(), k(r(O), v({
200
+ e.hideYAxis ? m("", !0) : (d(), k(l(F), v({
192
201
  key: 4,
193
202
  type: "y",
194
203
  label: e.yLabel,
@@ -198,45 +207,45 @@ const ne = ["id"], oe = {
198
207
  "domain-line": e.yDomainLine,
199
208
  "tick-line": e.yTickLine
200
209
  }, e.yAxisConfig), null, 16, ["label", "num-ticks", "tick-format", "grid-line", "domain-line", "tick-line"])),
201
- e.hideTooltip ? y("", !0) : (c(), k(r(te), v({ key: 5 }, e.crosshairConfig, { template: Y }), null, 16))
210
+ e.hideTooltip ? m("", !0) : (d(), k(l(oe), v({ key: 5 }, e.crosshairConfig, { template: U }), null, 16))
202
211
  ]),
203
212
  _: 1
204
213
  }, 8, ["data", "height", "padding", "svg-defs", "y-domain", "x-domain"]),
205
- n.hideLegend ? y("", !0) : (c(), f("div", {
214
+ a.hideLegend ? m("", !0) : (d(), f("div", {
206
215
  key: 0,
207
216
  style: p({
208
217
  display: "flex",
209
- justifyContent: W.value
218
+ justifyContent: w.value
210
219
  })
211
220
  }, [
212
- u(r(ie), {
221
+ u(l(re), {
213
222
  style: p([
214
- n.legendStyle,
223
+ a.legendStyle,
215
224
  "display: flex; gap: var(--vis-legend-spacing);"
216
225
  ]),
217
- items: Object.values(n.categories).map((t) => ({
218
- ...t,
219
- color: Array.isArray(t.color) ? t.color[0] : t.color
226
+ items: Object.values(a.categories).map((i) => ({
227
+ ...i,
228
+ color: Array.isArray(i.color) ? i.color[0] : i.color
220
229
  }))
221
230
  }, null, 8, ["style", "items"])
222
231
  ], 4)),
223
- q("div", oe, [
224
- r(G).tooltip ? b(i.$slots, "tooltip", {
232
+ Z("div", ce, [
233
+ l(N).tooltip ? B(t.$slots, "tooltip", {
225
234
  key: 0,
226
- values: m.value
227
- }) : m.value ? b(i.$slots, "fallback", { key: 1 }, () => [
228
- u(I, {
229
- data: m.value,
235
+ values: y.value
236
+ }) : y.value ? B(t.$slots, "fallback", { key: 1 }, () => [
237
+ u(ie, {
238
+ data: y.value,
230
239
  categories: e.categories,
231
- "title-formatter": n.tooltipTitleFormatter,
232
- yFormatter: n.yFormatter
240
+ "title-formatter": a.tooltipTitleFormatter,
241
+ yFormatter: a.yFormatter
233
242
  }, null, 8, ["data", "categories", "title-formatter", "yFormatter"])
234
- ]) : y("", !0)
243
+ ]) : m("", !0)
235
244
  ], 512)
236
- ], 14, ne);
245
+ ], 14, se);
237
246
  };
238
247
  }
239
248
  });
240
249
  export {
241
- ye as default
250
+ ke as default
242
251
  };
@@ -0,0 +1,206 @@
1
+ import { defineComponent as N, useSlots as W, useTemplateRef as E, ref as G, computed as c, createElementBlock as m, openBlock as o, normalizeStyle as f, createVNode as x, createCommentVNode as u, createElementVNode as z, unref as a, withCtx as H, createBlock as d, Fragment as X, renderList as j, mergeProps as k, renderSlot as p } from "vue";
2
+ import { Orientation as y, CurveType as A, Position as L, StackedBar as q, GroupedBar as $ } from "@unovis/ts";
3
+ import { VisXYContainer as R, VisTooltip as U, VisGroupedBar as I, VisStackedBar as J, VisLine as K, VisAxis as B, VisCrosshair as Q, VisBulletLegend as Z } from "@unovis/vue";
4
+ import _ from "../Tooltip.js";
5
+ import { LegendPosition as ee } from "../../types.js";
6
+ const te = {
7
+ ref: "slotWrapper",
8
+ style: { display: "none" }
9
+ }, de = /* @__PURE__ */ N({
10
+ __name: "DualChart",
11
+ props: {
12
+ data: {},
13
+ height: {},
14
+ xLabel: {},
15
+ yLabel: {},
16
+ yLabelSecondary: {},
17
+ padding: { default: () => ({
18
+ top: 5,
19
+ right: 5,
20
+ bottom: 5,
21
+ left: 5
22
+ }) },
23
+ barCategories: {},
24
+ lineCategories: {},
25
+ barYAxis: {},
26
+ lineYAxis: {},
27
+ xFormatter: {},
28
+ yFormatter: {},
29
+ tooltipTitleFormatter: {},
30
+ curveType: { default: A.MonotoneX },
31
+ lineWidth: { default: 2 },
32
+ xNumTicks: {},
33
+ xExplicitTicks: {},
34
+ minMaxTicksOnly: { type: Boolean },
35
+ yNumTicks: {},
36
+ hideLegend: { type: Boolean, default: !1 },
37
+ hideTooltip: { type: Boolean, default: !1 },
38
+ legendPosition: { default: ee.BottomCenter },
39
+ legendStyle: { default: void 0 },
40
+ xDomainLine: { type: Boolean },
41
+ yDomainLine: { type: Boolean },
42
+ xTickLine: { type: Boolean },
43
+ yTickLine: { type: Boolean },
44
+ xGridLine: { type: Boolean },
45
+ yGridLine: { type: Boolean, default: !0 },
46
+ hideXAxis: { type: Boolean },
47
+ hideYAxis: { type: Boolean },
48
+ crosshairConfig: {},
49
+ xAxisConfig: {},
50
+ yAxisConfig: {},
51
+ yDomain: {},
52
+ xDomain: {},
53
+ stacked: { type: Boolean },
54
+ groupPadding: { default: 0 },
55
+ barPadding: { default: 0.2 },
56
+ radius: {},
57
+ orientation: { default: y.Vertical }
58
+ },
59
+ emits: ["click"],
60
+ setup(e, { emit: Y }) {
61
+ const P = Y, t = e, V = W(), g = E("slotWrapper"), s = G();
62
+ if (!t.barYAxis || t.barYAxis.length === 0)
63
+ throw console.error("[DualChart] barYAxis prop is required and must contain at least one field key"), new Error("DualChart: 'barYAxis' is required and must contain at least one field key. Provide an array of property keys from your data type (e.g., ['revenue', 'costs'])");
64
+ if (!t.lineYAxis || t.lineYAxis.length === 0)
65
+ throw console.error("[DualChart] lineYAxis prop is required and must contain at least one field key"), new Error("DualChart: 'lineYAxis' is required and must contain at least one field key. Provide an array of property keys from your data type (e.g., ['profit', 'target'])");
66
+ const h = c(() => t.barYAxis.map((n) => (l) => l[n])), D = c(() => t.lineYAxis.map((n) => (l) => l[n])), v = (n, l) => {
67
+ var i;
68
+ return (i = Object.values(t.barCategories)[l]) == null ? void 0 : i.color;
69
+ }, b = c(() => ({
70
+ ...t.barCategories,
71
+ ...t.lineCategories
72
+ })), F = c(() => t.legendPosition.startsWith("top")), w = c(() => t.legendPosition.includes("left") ? "flex-start" : t.legendPosition.includes("right") ? "flex-end" : "center");
73
+ function C(n) {
74
+ s.value = n;
75
+ }
76
+ function M(n) {
77
+ return typeof window > "u" ? "" : g.value ? g.value.innerHTML : "";
78
+ }
79
+ function O(n) {
80
+ return s.value = n, M();
81
+ }
82
+ return (n, l) => (o(), m("div", {
83
+ style: f({
84
+ display: "flex",
85
+ flexDirection: F.value ? "column-reverse" : "column",
86
+ gap: "var(--vis-legend-spacing)"
87
+ }),
88
+ onClick: l[0] || (l[0] = (i) => P("click", i, s.value))
89
+ }, [
90
+ x(a(R), {
91
+ padding: e.padding,
92
+ height: e.height,
93
+ data: e.data
94
+ }, {
95
+ default: H(() => [
96
+ e.hideTooltip ? u("", !0) : (o(), d(a(U), {
97
+ key: 0,
98
+ triggers: {
99
+ [a($).selectors.bar]: (i) => {
100
+ var r;
101
+ return C(i), i ? (r = g.value) == null ? void 0 : r.innerHTML : "";
102
+ },
103
+ [a(q).selectors.bar]: (i) => {
104
+ var r;
105
+ return C(i), i ? (r = g.value) == null ? void 0 : r.innerHTML : "";
106
+ }
107
+ },
108
+ "horizontal-placement": a(L).Right,
109
+ "vertical-placement": a(L).Top
110
+ }, null, 8, ["triggers", "horizontal-placement", "vertical-placement"])),
111
+ e.stacked ? (o(), d(a(J), {
112
+ key: 2,
113
+ data: e.data,
114
+ x: (i, r) => r,
115
+ y: h.value,
116
+ color: v,
117
+ "rounded-corners": e.radius ?? 0,
118
+ "group-padding": e.groupPadding ?? 0,
119
+ "bar-padding": e.barPadding ?? 0.2,
120
+ orientation: e.orientation ?? a(y).Vertical
121
+ }, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])) : (o(), d(a(I), {
122
+ key: 1,
123
+ data: e.data,
124
+ x: (i, r) => r,
125
+ y: h.value,
126
+ color: v,
127
+ "rounded-corners": e.radius ?? 0,
128
+ "group-padding": e.groupPadding ?? 0,
129
+ "bar-padding": e.barPadding ?? 0.2,
130
+ orientation: e.orientation ?? a(y).Vertical
131
+ }, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])),
132
+ (o(!0), m(X, null, j(D.value, (i, r) => {
133
+ var T;
134
+ return o(), d(a(K), {
135
+ key: `line-${r}`,
136
+ data: e.data,
137
+ x: (ie, S) => S,
138
+ y: i,
139
+ color: (T = Object.values(t.lineCategories)[r]) == null ? void 0 : T.color,
140
+ "curve-type": e.curveType ?? a(A).MonotoneX,
141
+ "line-width": e.lineWidth
142
+ }, null, 8, ["data", "x", "y", "color", "curve-type", "line-width"]);
143
+ }), 128)),
144
+ e.hideXAxis ? u("", !0) : (o(), d(a(B), k({
145
+ key: 3,
146
+ type: "x",
147
+ "tick-format": e.xFormatter,
148
+ label: e.xLabel,
149
+ "grid-line": e.xGridLine,
150
+ "domain-line": !!e.xDomainLine,
151
+ "tick-line": e.xTickLine,
152
+ "num-ticks": e.xNumTicks,
153
+ "tick-values": e.xExplicitTicks,
154
+ minMaxTicksOnly: e.minMaxTicksOnly
155
+ }, e.xAxisConfig), null, 16, ["tick-format", "label", "grid-line", "domain-line", "tick-line", "num-ticks", "tick-values", "minMaxTicksOnly"])),
156
+ e.hideYAxis ? u("", !0) : (o(), d(a(B), k({
157
+ key: 4,
158
+ type: "y",
159
+ label: e.yLabel,
160
+ "grid-line": e.orientation !== a(y).Horizontal && e.yGridLine,
161
+ "domain-line": !!e.yDomainLine,
162
+ "tick-format": e.yFormatter,
163
+ "num-ticks": e.yNumTicks,
164
+ "tick-line": e.yTickLine
165
+ }, e.yAxisConfig), null, 16, ["label", "grid-line", "domain-line", "tick-format", "num-ticks", "tick-line"])),
166
+ e.hideTooltip ? u("", !0) : (o(), d(a(Q), k({ key: 5 }, e.crosshairConfig, { template: O }), null, 16))
167
+ ]),
168
+ _: 1
169
+ }, 8, ["padding", "height", "data"]),
170
+ t.hideLegend ? u("", !0) : (o(), m("div", {
171
+ key: 0,
172
+ style: f({
173
+ display: "flex",
174
+ justifyContent: w.value
175
+ })
176
+ }, [
177
+ x(a(Z), {
178
+ style: f([
179
+ t.legendStyle,
180
+ "display: flex; gap: var(--vis-legend-spacing);"
181
+ ]),
182
+ items: Object.values(b.value).map((i) => ({
183
+ ...i,
184
+ color: Array.isArray(i.color) ? i.color[0] : i.color
185
+ }))
186
+ }, null, 8, ["style", "items"])
187
+ ], 4)),
188
+ z("div", te, [
189
+ a(V).tooltip ? p(n.$slots, "tooltip", {
190
+ key: 0,
191
+ values: s.value
192
+ }) : s.value ? p(n.$slots, "fallback", { key: 1 }, () => [
193
+ x(_, {
194
+ data: s.value,
195
+ categories: b.value,
196
+ "title-formatter": t.tooltipTitleFormatter,
197
+ yFormatter: t.orientation === a(y).Horizontal ? t.xFormatter : t.yFormatter
198
+ }, null, 8, ["data", "categories", "title-formatter", "yFormatter"])
199
+ ]) : u("", !0)
200
+ ], 512)
201
+ ], 4));
202
+ }
203
+ });
204
+ export {
205
+ de as default
206
+ };
@@ -0,0 +1,21 @@
1
+ import { DualChartProps } from './types';
2
+ declare const _default: <T extends {}>(__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<{
3
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
4
+ readonly onClick?: ((event: MouseEvent, values?: T | undefined) => any) | undefined;
5
+ } & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, "onClick"> & DualChartProps<T> & Partial<{}>> & import('vue').PublicProps;
6
+ expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
7
+ attrs: any;
8
+ slots: {
9
+ tooltip?(_: {
10
+ values: T | undefined;
11
+ }): any;
12
+ fallback?(_: {}): any;
13
+ };
14
+ emit: (e: "click", event: MouseEvent, values?: T) => void;
15
+ }>) => import('vue').VNode & {
16
+ __ctx?: Awaited<typeof __VLS_setup>;
17
+ };
18
+ export default _default;
19
+ type __VLS_PrettifyLocal<T> = {
20
+ [K in keyof T]: T[K];
21
+ } & {};
@@ -0,0 +1,4 @@
1
+ import f from "./DualChart.js";
2
+ export {
3
+ f as default
4
+ };
@@ -0,0 +1,187 @@
1
+ import { axisFormatter, CrosshairConfig, LegendPosition, AxisConfig, BulletLegendItemInterface, Orientation } from '../../types';
2
+ import { CurveType } from '@unovis/ts';
3
+ export interface DualChartProps<T> {
4
+ /**
5
+ * The data to be displayed in the dual chart.
6
+ * Each element of the array represents a data point.
7
+ * The structure of 'T' should be compatible with the chart's rendering logic.
8
+ */
9
+ data: T[];
10
+ /**
11
+ * The height of the chart in pixels.
12
+ */
13
+ height: number;
14
+ /**
15
+ * Optional label for the x-axis.
16
+ */
17
+ xLabel?: string;
18
+ /**
19
+ * Optional label for the y-axis (used for both bar and line by default).
20
+ */
21
+ yLabel?: string;
22
+ /**
23
+ * Optional label for the secondary y-axis (line chart).
24
+ */
25
+ yLabelSecondary?: string;
26
+ /**
27
+ * Optional padding applied to the chart.
28
+ * Allows specifying individual padding values for the top, right, bottom, and left sides.
29
+ */
30
+ padding?: {
31
+ top: number;
32
+ right: number;
33
+ bottom: number;
34
+ left: number;
35
+ };
36
+ /**
37
+ * A record mapping bar category keys to `BulletLegendItemInterface` objects.
38
+ * This defines the visual representation and labels for bar categories in the chart's legend.
39
+ */
40
+ barCategories: Record<string, BulletLegendItemInterface>;
41
+ /**
42
+ * A record mapping line category keys to `BulletLegendItemInterface` objects.
43
+ * This defines the visual representation and labels for line categories in the chart's legend.
44
+ */
45
+ lineCategories: Record<string, BulletLegendItemInterface>;
46
+ /**
47
+ * An array of property keys from the data object type 'T' to be used for the bar chart y-axis values.
48
+ */
49
+ barYAxis: (keyof T)[];
50
+ /**
51
+ * An array of property keys from the data object type 'T' to be used for the line chart y-axis values.
52
+ */
53
+ lineYAxis: (keyof T)[];
54
+ /**
55
+ * @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.
56
+ * @param {number} i - The index of the tick in the `ticks` array.
57
+ * @param {(number[]|Date[])} ticks - An array of all tick values for the x-axis.
58
+ * @returns {string} The formatted string representation of the tick.
59
+ */
60
+ xFormatter?: axisFormatter;
61
+ /**
62
+ * @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.
63
+ * @param {number} i - The index of the tick in the `ticks` array.
64
+ * @param {(number[]|Date[])} ticks - An array of all tick values for the y-axis.
65
+ * @returns {string} The formatted string representation of the tick.
66
+ */
67
+ yFormatter?: axisFormatter;
68
+ /**
69
+ * Use custom formatter for tooltip titles
70
+ */
71
+ tooltipTitleFormatter?: (data: T) => string | number;
72
+ /**
73
+ * The type of curve to use for the line chart lines.
74
+ * See `CurveType` for available options.
75
+ */
76
+ curveType?: CurveType;
77
+ /**
78
+ * The width of the line in pixels. Default is 2px.
79
+ */
80
+ lineWidth?: number;
81
+ /**
82
+ * The desired number of ticks on the x-axis.
83
+ */
84
+ xNumTicks?: number;
85
+ /**
86
+ * Force specific ticks on the x-axis.
87
+ */
88
+ xExplicitTicks?: (number | string | Date)[];
89
+ /**
90
+ * Force only first and last ticks on the x-axis.
91
+ */
92
+ minMaxTicksOnly?: boolean;
93
+ /**
94
+ * The desired number of ticks on the y-axis.
95
+ */
96
+ yNumTicks?: number;
97
+ /**
98
+ * If `true`, hides the chart legend.
99
+ */
100
+ hideLegend?: boolean;
101
+ /**
102
+ * If `true`, hides the chart tooltip.
103
+ */
104
+ hideTooltip?: boolean;
105
+ /**
106
+ * Optional position for the legend, if applicable.
107
+ * See `LegendPosition` for available options.
108
+ */
109
+ legendPosition?: LegendPosition;
110
+ /**
111
+ * Optional style object for the legend container. Allows custom CSS styling.
112
+ */
113
+ legendStyle?: string | Record<string, string>;
114
+ /**
115
+ * If `true`, displays a domain line (axis line) along the x-axis.
116
+ */
117
+ xDomainLine?: boolean;
118
+ /**
119
+ * If `true`, displays a domain line (axis line) along the y-axis.
120
+ */
121
+ yDomainLine?: boolean;
122
+ /**
123
+ * If `true`, displays tick lines on the x-axis.
124
+ */
125
+ xTickLine?: boolean;
126
+ /**
127
+ * If `true`, displays tick lines on the y-axis.
128
+ */
129
+ yTickLine?: boolean;
130
+ /**
131
+ * If `true`, displays grid lines along the x-axis.
132
+ */
133
+ xGridLine?: boolean;
134
+ /**
135
+ * If `true`, displays grid lines along the y-axis.
136
+ */
137
+ yGridLine?: boolean;
138
+ /**
139
+ * If `true`, hide the x-axis.
140
+ */
141
+ hideXAxis?: boolean;
142
+ /**
143
+ * If `true`, hide the y-axis.
144
+ */
145
+ hideYAxis?: boolean;
146
+ /**
147
+ * Crosshair configuration object for customizing the appearance of the crosshair line.
148
+ */
149
+ crosshairConfig?: CrosshairConfig;
150
+ /**
151
+ * Axis configuration object for customizing the appearance of the axes.
152
+ */
153
+ xAxisConfig?: AxisConfig;
154
+ /**
155
+ * Axis configuration object for customizing the appearance of the axes.
156
+ */
157
+ yAxisConfig?: AxisConfig;
158
+ /**
159
+ * The domain for the y-axis, specified as a tuple of two values.
160
+ */
161
+ yDomain?: [number | undefined, number | undefined];
162
+ /**
163
+ * The domain for the x-axis, specified as a tuple of two values.
164
+ */
165
+ xDomain?: [number | undefined, number | undefined];
166
+ /**
167
+ * If `true`, creates stacked bars.
168
+ */
169
+ stacked?: boolean;
170
+ /**
171
+ * The padding between groups of bars in pixels.
172
+ */
173
+ groupPadding?: number;
174
+ /**
175
+ * Fractional padding between the bars in the range of [0,1). Default: 0.2
176
+ */
177
+ barPadding?: number;
178
+ /**
179
+ * Rounded corners for top bars. Boolean or number (to set the radius in pixels). Default: 2
180
+ */
181
+ radius?: number;
182
+ /**
183
+ * The orientation of the bars (vertical or horizontal).
184
+ * See `Orientation` for available options.
185
+ */
186
+ orientation?: Orientation;
187
+ }
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import { default as BarChart } from './components/BarChart/BarChart.vue';
4
4
  import { default as DonutChart } from './components/DonutChart/DonutChart.vue';
5
5
  import { default as BubbleChart } from './components/BubbleChart/BubbleChart.vue';
6
6
  import { default as GanttChart } from './components/GanttChart/GanttChart.vue';
7
- import { LegendPosition, CurveType, Orientation, BulletLegendItemInterface, MarkerConfig, CrosshairConfig, DonutType } from './types';
8
- export { AreaChart, LineChart, BarChart, DonutChart, BubbleChart, GanttChart, Orientation, CurveType, LegendPosition, DonutType };
7
+ import { default as DualChart } from './components/DualChart/DualChart.vue';
8
+ import { LegendPosition, CurveType, Orientation, MarkerConfig, CrosshairConfig, DonutType, BulletLegendItemInterface } from './types';
9
+ export { AreaChart, LineChart, BarChart, DonutChart, BubbleChart, GanttChart, DualChart, Orientation, CurveType, LegendPosition, DonutType };
9
10
  export type { BulletLegendItemInterface, MarkerConfig, CrosshairConfig };
package/dist/index.js CHANGED
@@ -1,20 +1,22 @@
1
- import { default as e } from "./components/AreaChart/AreaChart.js";
1
+ import { default as a } from "./components/AreaChart/AreaChart.js";
2
2
  import { default as o } from "./components/LineChart/LineChart.js";
3
- import { default as p } from "./components/BarChart/BarChart.js";
4
- import { default as m } from "./components/DonutChart/DonutChart.js";
3
+ import { default as u } from "./components/BarChart/BarChart.js";
4
+ import { default as l } from "./components/DonutChart/DonutChart.js";
5
5
  import { default as x } from "./components/BubbleChart/BubbleChart.js";
6
- import { default as l } from "./components/GanttChart/GanttChart.js";
7
- import { CurveType as C, LegendPosition as h, Orientation as i } from "./types.js";
8
- import { DonutType as y } from "./components/DonutChart/types.js";
6
+ import { default as n } from "./components/GanttChart/GanttChart.js";
7
+ import { default as C } from "./components/DualChart/DualChart.js";
8
+ import { CurveType as i, LegendPosition as D, Orientation as b } from "./types.js";
9
+ import { DonutType as B } from "./components/DonutChart/types.js";
9
10
  export {
10
- e as AreaChart,
11
- p as BarChart,
11
+ a as AreaChart,
12
+ u as BarChart,
12
13
  x as BubbleChart,
13
- C as CurveType,
14
- m as DonutChart,
15
- y as DonutType,
16
- l as GanttChart,
17
- h as LegendPosition,
14
+ i as CurveType,
15
+ l as DonutChart,
16
+ B as DonutType,
17
+ C as DualChart,
18
+ n as GanttChart,
19
+ D as LegendPosition,
18
20
  o as LineChart,
19
- i as Orientation
21
+ b as Orientation
20
22
  };
package/dist/utils.d.ts CHANGED
@@ -3,6 +3,9 @@ export declare function getDistributedIndices(length: number, numTicks: number):
3
3
  export declare function getFirstPropertyValue(obj: unknown): undefined;
4
4
  export declare const markerShape: (type: string, size: number, strokeWidth: number, color: string, strokeColor: string) => string;
5
5
  export declare function createMarkers(markerConfig: MarkerConfig): string;
6
+ export declare function createScopedMarkers(markerConfig: MarkerConfig, scopeId: string, options?: {
7
+ includeLegacy?: boolean;
8
+ }): string;
6
9
  export declare const flattenData: (data: any[], xAxis: string) => {
7
10
  month: any;
8
11
  }[];
package/dist/utils.js CHANGED
@@ -1,50 +1,54 @@
1
- function p(t) {
2
- if (t && Object.keys(t).length > 0) {
3
- const e = Object.keys(t)[0];
4
- return t[e];
1
+ function i(e) {
2
+ if (e && Object.keys(e).length > 0) {
3
+ const r = Object.keys(e)[0];
4
+ return e[r];
5
5
  }
6
6
  }
7
- const o = (t, e, r, n, $) => {
8
- switch (t) {
7
+ const s = (e, r, t, a, $) => {
8
+ switch (e) {
9
9
  case "circle":
10
- return `<circle cx="${e / 2}" cy="${e / 2}" r="${(e - r) / 2}" stroke-width="${r}" stroke="${$}" fill="${n}" />`;
10
+ return `<circle cx="${r / 2}" cy="${r / 2}" r="${(r - t) / 2}" stroke-width="${t}" stroke="${$}" fill="${a}" />`;
11
11
  case "square":
12
- return `<rect x="${r / 2}" y="${r / 2}" width="${e - r}" height="${e - r}" stroke-width="${r}" stroke="${$}" fill="${n}" />`;
12
+ return `<rect x="${t / 2}" y="${t / 2}" width="${r - t}" height="${r - t}" stroke-width="${t}" stroke="${$}" fill="${a}" />`;
13
13
  case "triangle":
14
- return `<polygon points="${e / 2},${r / 2} ${e - r / 2},${e - r / 2} ${r / 2},${e - r / 2}" stroke-width="${r}" stroke="${$}" fill="${n}" />`;
14
+ return `<polygon points="${r / 2},${t / 2} ${r - t / 2},${r - t / 2} ${t / 2},${r - t / 2}" stroke-width="${t}" stroke="${$}" fill="${a}" />`;
15
15
  case "diamond":
16
- return `<polygon points="${e / 2},${r / 2} ${e - r / 2},${e / 2} ${e / 2},${e - r / 2} ${r / 2},${e / 2}" stroke-width="${r}" stroke="${$}" fill="${n}" />`;
16
+ return `<polygon points="${r / 2},${t / 2} ${r - t / 2},${r / 2} ${r / 2},${r - t / 2} ${t / 2},${r / 2}" stroke-width="${t}" stroke="${$}" fill="${a}" />`;
17
17
  default:
18
18
  return "";
19
19
  }
20
20
  };
21
- function m(t) {
22
- return Object.entries(t.config).map(([e, r]) => {
23
- const n = r.type || "circle", $ = r.size || 10, c = r.strokeWidth || 2, a = r.color || "#000", l = r.strokeColor || r.color || "#000";
24
- return `<marker id="${t.id}-${e}" viewBox="0 0 ${$} ${$}" refX="${$ / 2}" refY="${$ / 2}" markerWidth="${$ / 2}" markerHeight="${$ / 2}">
25
- ${o(n, $, c, a, l)}
26
- </marker>`;
21
+ function f(e, r, t) {
22
+ const a = ($, n) => {
23
+ const o = n.type || "circle", c = n.size || 10, l = n.strokeWidth || 2, u = n.color || "#000", p = n.strokeColor || n.color || "#000";
24
+ return `<marker id="${$}" viewBox="0 0 ${c} ${c}" refX="${c / 2}" refY="${c / 2}" markerWidth="${c / 2}" markerHeight="${c / 2}" orient="auto">
25
+ ${s(o, c, l, u, p)}
26
+ </marker>`;
27
+ };
28
+ return Object.entries(e.config).flatMap(([$, n]) => {
29
+ const o = `${e.id}--${r}--${$}`, c = [a(o, n)];
30
+ return c.push(a(`${e.id}-${$}`, n)), c;
27
31
  }).join(`
28
32
  `);
29
33
  }
30
- function u(t) {
31
- return t.charAt(0).toUpperCase() + t.slice(1);
34
+ function m(e) {
35
+ return e.charAt(0).toUpperCase() + e.slice(1);
32
36
  }
33
- const f = (t, e) => {
34
- const r = Object.keys(t[0]).filter(($) => $ !== e), n = Object.keys(t[0][r[0]]);
35
- return t.map(($) => ({
37
+ const y = (e, r) => {
38
+ const t = Object.keys(e[0]).filter(($) => $ !== r), a = Object.keys(e[0][t[0]]);
39
+ return e.map(($) => ({
36
40
  month: $.month,
37
- ...r.flatMap(
38
- (c) => n.map((a) => ({
39
- [`${c}${u(a)}`]: $[c][a]
41
+ ...t.flatMap(
42
+ (n) => a.map((o) => ({
43
+ [`${n}${m(o)}`]: $[n][o]
40
44
  }))
41
- ).reduce((c, a) => ({ ...c, ...a }), {})
45
+ ).reduce((n, o) => ({ ...n, ...o }), {})
42
46
  }));
43
- }, y = (t) => Intl.DateTimeFormat().format(t);
47
+ }, w = (e) => Intl.DateTimeFormat().format(e);
44
48
  export {
45
- m as createMarkers,
46
- y as dateFormatter,
47
- f as flattenData,
48
- p as getFirstPropertyValue,
49
- o as markerShape
49
+ f as createScopedMarkers,
50
+ w as dateFormatter,
51
+ y as flattenData,
52
+ i as getFirstPropertyValue,
53
+ s as markerShape
50
54
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-chrts",
3
- "version": "2.0.0-beta.5",
3
+ "version": "2.1.0-beta.0.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"