vue-chrts 2.0.0-beta.4 → 2.0.0-beta.5

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 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 = {
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 = {
8
8
  ref: "slotWrapper",
9
9
  style: { display: "none" }
10
- }, te = 0.5, D = "#3b82f6", se = /* @__PURE__ */ W({
10
+ }, F = 0.5, A = "#3b82f6", ye = /* @__PURE__ */ z({
11
11
  __name: "AreaChart",
12
12
  props: {
13
13
  data: {},
@@ -34,7 +34,7 @@ const _ = ["id"], ee = {
34
34
  yNumTicks: {},
35
35
  hideLegend: { type: Boolean, default: !1 },
36
36
  hideTooltip: { type: Boolean },
37
- legendPosition: { default: I.BottomCenter },
37
+ legendPosition: { default: ae.BottomCenter },
38
38
  legendStyle: { default: void 0 },
39
39
  xDomainLine: { type: Boolean },
40
40
  yDomainLine: { type: Boolean },
@@ -50,37 +50,38 @@ const _ = ["id"], ee = {
50
50
  xAxisConfig: {},
51
51
  yAxisConfig: {},
52
52
  yDomain: {},
53
- xDomain: {}
53
+ xDomain: {},
54
+ stacked: { type: Boolean }
54
55
  },
55
56
  emits: ["click"],
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})`
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})`
60
61
  );
61
62
  return Object.values(n.categories).map(
62
- (l, i) => l.color ?? a[i]
63
+ (l, a) => l.color ?? i[a]
63
64
  );
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) => {
69
- var r;
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;
70
71
  return `
71
- <linearGradient id="gradient${i}-${t}" gradientTransform="rotate(90)">
72
- ${((r = n.gradientStops) == null ? void 0 : r.map(
72
+ <linearGradient id="gradient${a}-${t}" gradientTransform="rotate(90)">
73
+ ${((o = n.gradientStops) == null ? void 0 : o.map(
73
74
  (s) => `<stop offset="${s.offset}" stop-color="${t}" stop-opacity="${s.stopOpacity}" />`
74
75
  ).join("")) ?? ""}
75
76
  <stop offset="100%" stop-color="${t}" stop-opacity="0" />
76
77
  </linearGradient>
77
78
  `;
78
- }, l = (i, t) => {
79
- var r;
79
+ }, l = (a, t) => {
80
+ var o;
80
81
  return `
81
- <linearGradient id="gradient${i}-${t}" gradientTransform="rotate(90)">
82
+ <linearGradient id="gradient${a}-${t}" gradientTransform="rotate(90)">
82
83
 
83
- ${((r = n.gradientStops) == null ? void 0 : r.map(
84
+ ${((o = n.gradientStops) == null ? void 0 : o.map(
84
85
  (s) => `
85
86
  <stop offset="${s.offset}" style="stop-color:var(${t});stop-opacity:${s.stopOpacity}" />
86
87
  `
@@ -88,67 +89,94 @@ const _ = ["id"], ee = {
88
89
  </linearGradient>
89
90
  `;
90
91
  };
91
- return v.value.map(
92
- (i, t) => i != null && i.includes("#") ? a(t, i) : l(t, i ?? D)
92
+ return g.value.map(
93
+ (a, t) => a != null && a.includes("#") ? i(t, a) : l(t, a ?? A)
93
94
  ).join("");
94
95
  });
95
- function j(a) {
96
+ function P(i) {
96
97
  var l;
97
98
  return {
98
- y: (i) => Number(i[a]),
99
- color: ((l = n.categories[a]) == null ? void 0 : l.color) ?? D
99
+ y: (a) => Number(a[i]),
100
+ color: ((l = n.categories[i]) == null ? void 0 : l.color) ?? A
100
101
  };
101
102
  }
102
- function N(a) {
103
- return typeof window > "u" ? "" : p.value ? p.value.innerHTML : "";
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;
112
+ });
113
+ }), L = d(() => (i, l) => g.value[l] ?? A);
114
+ function E(i) {
115
+ return typeof window > "u" ? "" : C.value ? C.value.innerHTML : "";
104
116
  }
105
- function P(a) {
106
- return u.value = a, N();
117
+ function Y(i) {
118
+ return m.value = i, E();
107
119
  }
108
- return (a, l) => {
109
- var i;
120
+ return (i, l) => {
121
+ var a;
110
122
  return c(), f("div", {
111
- style: x({
123
+ style: p({
112
124
  display: "flex",
113
- flexDirection: V.value ? "column-reverse" : "column",
125
+ flexDirection: S.value ? "column-reverse" : "column",
114
126
  gap: "var(--vis-legend-spacing)"
115
127
  }),
116
- id: (i = e.markerConfig) == null ? void 0 : i.id,
117
- onClick: l[0] || (l[0] = (t) => B("click", t, u.value))
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))
118
131
  }, [
119
- y(o(H), {
132
+ u(r(_), {
120
133
  data: e.data,
121
134
  height: e.height,
122
135
  padding: e.padding,
123
- "svg-defs": S.value + F.value,
136
+ "svg-defs": M.value + N.value,
124
137
  "y-domain": e.yDomain,
125
138
  "x-domain": e.xDomain
126
139
  }, {
127
- default: R(() => [
128
- e.hideTooltip ? d("", !0) : (c(), g(o(q), {
140
+ default: J(() => [
141
+ e.hideTooltip ? y("", !0) : (c(), k(r(ee), {
129
142
  key: 0,
130
- "horizontal-placement": o(C).Right,
131
- "vertical-placement": o(C).Top
143
+ "horizontal-placement": r($).Right,
144
+ "vertical-placement": r($).Top
132
145
  }, 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
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
153
+ }, 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,
159
+ "line-width": e.lineWidth
160
+ }, 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({
163
+ 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
140
168
  }), null, 16, ["x", "color", "opacity", "curve-type"]),
141
- y(o(K), {
142
- x: (s, h) => h,
169
+ u(r(D), {
170
+ x: (s, x) => x,
143
171
  y: (s) => s[t],
144
- color: v.value[r],
145
- "curve-type": e.curveType ?? o(A).MonotoneX,
172
+ color: g.value[o],
173
+ "curve-type": e.curveType ?? r(h).MonotoneX,
146
174
  "line-width": e.lineWidth,
147
- lineDashArray: e.lineDashArray ? e.lineDashArray[r] : void 0
175
+ lineDashArray: e.lineDashArray ? e.lineDashArray[o] : void 0
148
176
  }, null, 8, ["x", "y", "color", "curve-type", "line-width", "lineDashArray"])
149
177
  ], 64))), 128)),
150
- e.hideXAxis ? d("", !0) : (c(), g(o($), k({
151
- key: 1,
178
+ e.hideXAxis ? y("", !0) : (c(), k(r(O), v({
179
+ key: 3,
152
180
  type: "x",
153
181
  label: e.xLabel,
154
182
  "label-margin": 8,
@@ -160,8 +188,8 @@ const _ = ["id"], ee = {
160
188
  "tick-line": e.xTickLine,
161
189
  "min-max-ticks-only": e.minMaxTicksOnly
162
190
  }, 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,
191
+ e.hideYAxis ? y("", !0) : (c(), k(r(O), v({
192
+ key: 4,
165
193
  type: "y",
166
194
  label: e.yLabel,
167
195
  "num-ticks": e.yNumTicks,
@@ -170,19 +198,19 @@ const _ = ["id"], ee = {
170
198
  "domain-line": e.yDomainLine,
171
199
  "tick-line": e.yTickLine
172
200
  }, 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))
201
+ e.hideTooltip ? y("", !0) : (c(), k(r(te), v({ key: 5 }, e.crosshairConfig, { template: Y }), null, 16))
174
202
  ]),
175
203
  _: 1
176
204
  }, 8, ["data", "height", "padding", "svg-defs", "y-domain", "x-domain"]),
177
- n.hideLegend ? d("", !0) : (c(), f("div", {
205
+ n.hideLegend ? y("", !0) : (c(), f("div", {
178
206
  key: 0,
179
- style: x({
207
+ style: p({
180
208
  display: "flex",
181
- justifyContent: G.value
209
+ justifyContent: W.value
182
210
  })
183
211
  }, [
184
- y(o(Z), {
185
- style: x([
212
+ u(r(ie), {
213
+ style: p([
186
214
  n.legendStyle,
187
215
  "display: flex; gap: var(--vis-legend-spacing);"
188
216
  ]),
@@ -192,23 +220,23 @@ const _ = ["id"], ee = {
192
220
  }))
193
221
  }, null, 8, ["style", "items"])
194
222
  ], 4)),
195
- X("div", ee, [
196
- o(O).tooltip ? L(a.$slots, "tooltip", {
223
+ q("div", oe, [
224
+ r(G).tooltip ? b(i.$slots, "tooltip", {
197
225
  key: 0,
198
- values: u.value
199
- }) : u.value ? L(a.$slots, "fallback", { key: 1 }, () => [
200
- y(U, {
201
- data: u.value,
226
+ values: m.value
227
+ }) : m.value ? b(i.$slots, "fallback", { key: 1 }, () => [
228
+ u(I, {
229
+ data: m.value,
202
230
  categories: e.categories,
203
231
  "title-formatter": n.tooltipTitleFormatter,
204
232
  yFormatter: n.yFormatter
205
233
  }, null, 8, ["data", "categories", "title-formatter", "yFormatter"])
206
- ]) : d("", !0)
234
+ ]) : y("", !0)
207
235
  ], 512)
208
- ], 12, _);
236
+ ], 14, ne);
209
237
  };
210
238
  }
211
239
  });
212
240
  export {
213
- se as default
241
+ ye as default
214
242
  };
@@ -165,4 +165,9 @@ export interface AreaChartProps<T> {
165
165
  * The domain for the x-axis, specified as a tuple of two values.
166
166
  */
167
167
  xDomain?: [number | undefined, number | undefined];
168
+ /**
169
+ * If `true`, creates a stacked area chart where areas are stacked on top of each other.
170
+ * When false (default), areas are overlaid on top of each other.
171
+ */
172
+ stacked?: boolean;
168
173
  }
@@ -36,15 +36,16 @@ const g = /* @__PURE__ */ n({
36
36
  xAxisConfig: {},
37
37
  yAxisConfig: {},
38
38
  yDomain: {},
39
- xDomain: {}
39
+ xDomain: {},
40
+ stacked: { type: Boolean }
40
41
  },
41
42
  setup(o) {
42
- const i = o;
43
- return a(), (e, h) => (l(), r(x, p(i, { "hide-area": !0 }), s({ _: 2 }, [
43
+ const t = o;
44
+ return a(), (e, B) => (l(), r(x, p(t, { "hide-area": !0 }), s({ _: 2 }, [
44
45
  e.$slots.tooltip ? {
45
46
  name: "tooltip",
46
- fn: y((t) => [
47
- c(e.$slots, "tooltip", m(d(t)))
47
+ fn: y((i) => [
48
+ c(e.$slots, "tooltip", m(d(i)))
48
49
  ]),
49
50
  key: "0"
50
51
  } : void 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-chrts",
3
- "version": "2.0.0-beta.4",
3
+ "version": "2.0.0-beta.5",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"