vue-chrts 0.2.0-test.1 → 0.2.0-test.10

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 E, useSlots as x, useTemplateRef as P, ref as U, computed as k, createElementBlock as d, openBlock as a, normalizeClass as h, createVNode as c, createCommentVNode as r, createElementVNode as j, unref as i, withCtx as M, createBlock as u, Fragment as L, renderList as R, mergeProps as W, renderSlot as b } from "vue";
2
- import { Position as C, CurveType as B } from "@unovis/ts";
3
- import { getFirstPropertyValue as X } from "../../utils.js";
4
- import Y from "../Tooltip.js";
5
- import { VisXYContainer as w, VisTooltip as z, VisArea as I, VisLine as S, VisAxis as V, VisCrosshair as H, VisBulletLegend as K } from "@unovis/vue";
6
- import { LegendPosition as q } from "../../types.js";
7
- const J = {
1
+ import { defineComponent as U, useSlots as j, useTemplateRef as w, ref as R, computed as d, createElementBlock as c, openBlock as a, normalizeClass as T, createVNode as u, createCommentVNode as p, createElementVNode as X, unref as i, withCtx as x, createBlock as m, Fragment as L, renderList as S, mergeProps as C, renderSlot as b } from "vue";
2
+ import { Position as A, CurveType as B } from "@unovis/ts";
3
+ import { createMarkers as Y, getFirstPropertyValue as z } from "../../utils.js";
4
+ import I from "../Tooltip.js";
5
+ import { VisXYContainer as H, VisTooltip as K, VisArea as q, VisLine as J, VisAxis as D, VisCrosshair as Q, VisBulletLegend as Z } from "@unovis/vue";
6
+ import { LegendPosition as _ } from "../../types.js";
7
+ const ee = {
8
8
  ref: "slotWrapper",
9
9
  class: "hidden"
10
- }, m = 24, A = 4, Q = 0.5, F = "#3b82f6", ae = /* @__PURE__ */ E({
10
+ }, y = 24, V = 4, te = 0.5, F = "#3b82f6", se = /* @__PURE__ */ U({
11
11
  __name: "AreaChart",
12
12
  props: {
13
13
  data: {},
@@ -16,13 +16,16 @@ const J = {
16
16
  yLabel: {},
17
17
  padding: { default: () => ({ top: 5, right: 5, bottom: 5, left: 5 }) },
18
18
  categories: {},
19
+ markerConfig: {},
19
20
  xFormatter: {},
20
21
  yFormatter: {},
21
22
  curveType: {},
22
- xNumTicks: { default: (n) => n.data.length > m ? m / A : n.data.length - 1 },
23
+ lineWidth: { default: 2 },
24
+ lineDashArray: {},
25
+ xNumTicks: { default: (n) => n.data.length > y ? y / V : n.data.length - 1 },
23
26
  xExplicitTicks: {},
24
27
  minMaxTicksOnly: { type: Boolean },
25
- yNumTicks: { default: (n) => n.data.length > m ? m / A : n.data.length - 1 },
28
+ yNumTicks: { default: (n) => n.data.length > y ? y / V : n.data.length - 1 },
26
29
  hideLegend: { type: Boolean },
27
30
  hideTooltip: { type: Boolean },
28
31
  legendPosition: {},
@@ -33,72 +36,78 @@ const J = {
33
36
  xGridLine: { type: Boolean },
34
37
  yGridLine: { type: Boolean },
35
38
  hideXAxis: { type: Boolean },
36
- hideYAxis: { type: Boolean }
39
+ hideYAxis: { type: Boolean },
40
+ crosshairConfig: { default: () => ({
41
+ color: "#666"
42
+ }) }
37
43
  },
38
- setup(n) {
39
- const l = n, $ = x(), v = P("slotWrapper"), s = U(), y = k(
40
- () => Object.values(l.categories).map((e) => e.color)
41
- ), T = k(() => l.legendPosition === q.Top), D = k(() => {
44
+ emits: ["click"],
45
+ setup(n, { emit: $ }) {
46
+ const G = $, r = n, O = j(), h = w("slotWrapper"), s = R(), f = d(
47
+ () => Object.values(r.categories).map((e) => e.color)
48
+ ), N = d(() => r.markerConfig ? Y(r.markerConfig) : ""), g = d(() => r.legendPosition === _.Top), E = d(() => {
42
49
  const e = (t, o) => `
43
50
  <linearGradient id="gradient${t}-${o}" gradientTransform="rotate(90)">
44
51
  <stop offset="0%" stop-color="${o}" stop-opacity="1" />
45
52
  <stop offset="100%" stop-color="${o}" stop-opacity="0" />
46
53
  </linearGradient>
47
- `, p = (t, o) => `
54
+ `, l = (t, o) => `
48
55
  <linearGradient id="gradient${t}-${o}" gradientTransform="rotate(90)">
49
56
  <stop offset="0%" style="stop-color:var(--vis-color0);stop-opacity:1" />
50
57
  <stop offset="100%" style="stop-color:var(--vis-color0);stop-opacity:0" />
51
58
  </linearGradient>
52
59
  `;
53
- return y.value.map(
54
- (t, o) => t != null && t.includes("#") ? e(o, t) : p(o, t ?? F)
60
+ return f.value.map(
61
+ (t, o) => t != null && t.includes("#") ? e(o, t) : l(o, t ?? F)
55
62
  ).join("");
56
63
  });
57
- function G(e) {
58
- var p;
64
+ function P(e) {
65
+ var l;
59
66
  return {
60
67
  y: (t) => Number(t[e]),
61
- color: ((p = l.categories[e]) == null ? void 0 : p.color) ?? F
68
+ color: ((l = r.categories[e]) == null ? void 0 : l.color) ?? F
62
69
  };
63
70
  }
64
- function O(e) {
65
- return typeof window > "u" ? "" : v.value ? v.value.innerHTML : "";
71
+ function W(e) {
72
+ return typeof window > "u" ? "" : h.value ? h.value.innerHTML : "";
66
73
  }
67
- function N(e) {
68
- return s.value = e, O();
74
+ function M(e) {
75
+ return s.value = e, W();
69
76
  }
70
- return (e, p) => (a(), d("div", {
71
- class: h(["flex flex-col space-y-4", { "flex-col-reverse": T.value }])
77
+ return (e, l) => (a(), c("div", {
78
+ class: T(["flex flex-col", { "flex-col-reverse": g.value, markers: !!r.markerConfig }]),
79
+ onClick: l[0] || (l[0] = (t) => G("click", t, s.value))
72
80
  }, [
73
- c(i(w), {
81
+ u(i(H), {
74
82
  data: e.data,
75
83
  height: e.height,
76
84
  padding: e.padding,
77
- "svg-defs": D.value
85
+ "svg-defs": E.value + N.value
78
86
  }, {
79
- default: M(() => [
80
- e.hideTooltip ? r("", !0) : (a(), u(i(z), {
87
+ default: x(() => [
88
+ e.hideTooltip ? p("", !0) : (a(), m(i(K), {
81
89
  key: 0,
82
- "horizontal-placement": i(C).Right,
83
- "vertical-placement": i(C).Top
90
+ "horizontal-placement": i(A).Right,
91
+ "vertical-placement": i(A).Top
84
92
  }, null, 8, ["horizontal-placement", "vertical-placement"])),
85
- (a(!0), d(L, null, R(Object.keys(l.categories), (t, o) => (a(), d(L, { key: t }, [
86
- c(i(I), W({
87
- x: (f, g) => g,
88
- ref_for: !0
89
- }, G(t), {
90
- color: `url(#gradient${o}-${y.value[o]})`,
91
- opacity: Q,
93
+ (a(!0), c(L, null, S(Object.keys(r.categories), (t, o) => (a(), c(L, { key: t }, [
94
+ u(i(q), C({
95
+ x: (k, v) => v
96
+ }, { ref_for: !0 }, P(t), {
97
+ color: `url(#gradient${o}-${f.value[o]})`,
98
+ opacity: te,
92
99
  "curve-type": e.curveType ?? i(B).MonotoneX
93
100
  }), null, 16, ["x", "color", "curve-type"]),
94
- c(i(S), {
95
- x: (f, g) => g,
96
- y: (f) => f[t],
97
- color: y.value[o],
98
- "curve-type": e.curveType ?? i(B).MonotoneX
99
- }, null, 8, ["x", "y", "color", "curve-type"])
101
+ u(i(J), {
102
+ x: (k, v) => v,
103
+ y: (k) => k[t],
104
+ color: f.value[o],
105
+ "curve-type": e.curveType ?? i(B).MonotoneX,
106
+ "line-width": e.lineWidth,
107
+ lineDashArray: e.lineDashArray
108
+ }, null, 8, ["x", "y", "color", "curve-type", "line-width", "lineDashArray"])
100
109
  ], 64))), 128)),
101
- e.hideXAxis ? r("", !0) : (a(), u(i(V), {
110
+ e.hideXAxis ? p("", !0) : (a(), m(i(D), {
102
111
  key: 1,
103
112
  type: "x",
104
113
  label: e.xLabel,
@@ -111,7 +120,7 @@ const J = {
111
120
  "tick-line": e.xTickLine,
112
121
  "min-max-ticks-only": e.minMaxTicksOnly
113
122
  }, null, 8, ["label", "num-ticks", "tick-format", "tick-values", "grid-line", "domain-line", "tick-line", "min-max-ticks-only"])),
114
- e.hideYAxis ? r("", !0) : (a(), u(i(V), {
123
+ e.hideYAxis ? p("", !0) : (a(), m(i(D), {
115
124
  key: 2,
116
125
  type: "y",
117
126
  label: e.yLabel,
@@ -121,38 +130,34 @@ const J = {
121
130
  "domain-line": e.yDomainLine,
122
131
  "tick-line": e.yTickLine
123
132
  }, null, 8, ["label", "num-ticks", "tick-format", "grid-line", "domain-line", "tick-line"])),
124
- e.hideTooltip ? r("", !0) : (a(), u(i(H), {
125
- key: 3,
126
- color: "#666",
127
- template: N
128
- }))
133
+ e.hideTooltip ? p("", !0) : (a(), m(i(Q), C({ key: 3 }, e.crosshairConfig, { template: M }), null, 16))
129
134
  ]),
130
135
  _: 1
131
136
  }, 8, ["data", "height", "padding", "svg-defs"]),
132
- e.hideLegend ? r("", !0) : (a(), d("div", {
137
+ e.hideLegend ? p("", !0) : (a(), c("div", {
133
138
  key: 0,
134
- class: h(["flex items-center justify-end", { "pb-4": T.value }])
139
+ class: T(["flex items-center justify-end", { "pb-4": g.value, "pt-4": !g.value }])
135
140
  }, [
136
- c(i(K), {
141
+ u(i(Z), {
137
142
  items: Object.values(e.categories)
138
143
  }, null, 8, ["items"])
139
144
  ], 2)),
140
- j("div", J, [
141
- i($).tooltip ? b(e.$slots, "tooltip", {
145
+ X("div", ee, [
146
+ i(O).tooltip ? b(e.$slots, "tooltip", {
142
147
  key: 0,
143
148
  values: s.value
144
149
  }) : s.value ? b(e.$slots, "fallback", { key: 1 }, () => [
145
- c(Y, {
150
+ u(I, {
146
151
  data: s.value,
147
152
  categories: e.categories,
148
- toolTipTitle: i(X)(s.value) ?? "",
149
- yFormatter: l.yFormatter
153
+ toolTipTitle: i(z)(s.value) ?? "",
154
+ yFormatter: r.yFormatter
150
155
  }, null, 8, ["data", "categories", "toolTipTitle", "yFormatter"])
151
- ]) : r("", !0)
156
+ ]) : p("", !0)
152
157
  ], 512)
153
158
  ], 2));
154
159
  }
155
160
  });
156
161
  export {
157
- ae as default
162
+ se as default
158
163
  };
@@ -1,6 +1,8 @@
1
1
  import { AreaChartProps } from './types';
2
2
  declare const _default: <T>(__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<{} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, never> & AreaChartProps<T> & Partial<{}>> & import('vue').PublicProps;
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"> & AreaChartProps<T> & Partial<{}>> & import('vue').PublicProps;
4
6
  expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
5
7
  attrs: any;
6
8
  slots: {
@@ -9,7 +11,7 @@ declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>
9
11
  }): any;
10
12
  fallback?(_: {}): any;
11
13
  };
12
- emit: {};
14
+ emit: (e: "click", event: MouseEvent, values?: T) => void;
13
15
  }>) => import('vue').VNode & {
14
16
  __ctx?: Awaited<typeof __VLS_setup>;
15
17
  };
@@ -1,4 +1,4 @@
1
- import { axisFormatter, LegendPosition } from '../../types';
1
+ import { axisFormatter, LegendPosition, MarkerConfig } from '../../types';
2
2
  import { BulletLegendItemInterface, CurveType } from '@unovis/ts';
3
3
  export interface AreaChartProps<T> {
4
4
  /**
@@ -34,25 +34,37 @@ export interface AreaChartProps<T> {
34
34
  * This defines the visual representation and labels for each category in the chart's legend.
35
35
  */
36
36
  categories: Record<string, BulletLegendItemInterface>;
37
+ /**
38
+ * A record mapping marker keys to show custom patterns.
39
+ */
40
+ markerConfig?: Record<string, MarkerConfig>;
37
41
  /**
38
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.
39
43
  * @param {number} i - The index of the tick in the `ticks` array.
40
44
  * @param {(number[]|Date[])} ticks - An array of all tick values for the x-axis.
41
45
  * @returns {string} The formatted string representation of the tick.
42
46
  */
43
- xFormatter?: axisFormatter<T>;
47
+ xFormatter?: axisFormatter;
44
48
  /**
45
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.
46
50
  * @param {number} i - The index of the tick in the `ticks` array.
47
51
  * @param {(number[]|Date[])} ticks - An array of all tick values for the y-axis.
48
52
  * @returns {string} The formatted string representation of the tick.
49
53
  */
50
- yFormatter?: axisFormatter<T>;
54
+ yFormatter?: axisFormatter;
51
55
  /**
52
56
  * The type of curve to use for the area chart lines.
53
57
  * See `CurveType` for available options.
54
58
  */
55
59
  curveType?: CurveType;
60
+ /**
61
+ * The width of the line in pixels. Default is 2px.
62
+ */
63
+ lineWidth?: number;
64
+ /**
65
+ * Line dash array, see SVG's stroke-dasharray. Default: `undefined`
66
+ */
67
+ lineDashArray?: number[];
56
68
  /**
57
69
  * The desired number of ticks on the x-axis.
58
70
  */
@@ -114,4 +126,22 @@ export interface AreaChartProps<T> {
114
126
  * If `true`, hide the y-axis.
115
127
  */
116
128
  hideYAxis?: boolean;
129
+ /**
130
+ * Crosshair configuration object for customizing the appearance of the crosshair line.
131
+ */
132
+ crosshairConfig?: {
133
+ /**
134
+ * The color of the crosshair line. Accepts any valid CSS color string.
135
+ * Example: '#f00', 'rgba(0,0,0,0.5)', 'blue'
136
+ */
137
+ color?: string;
138
+ /**
139
+ * The stroke color of the crosshair line. Accepts any valid CSS color string.
140
+ */
141
+ strokeColor?: string;
142
+ /**
143
+ * The stroke width of the crosshair line in pixels.
144
+ */
145
+ strokeWidth?: number;
146
+ };
117
147
  }
@@ -1,8 +1,8 @@
1
- import { defineComponent as y, computed as f, createApp as h, createElementBlock as g, openBlock as r, createVNode as n, createElementVNode as B, unref as t, withCtx as L, createBlock as v, createCommentVNode as k } from "vue";
2
- import { VisXYContainer as x, VisArea as T, VisAxis as c, VisCrosshair as b, VisBulletLegend as V } from "@unovis/vue";
1
+ import { defineComponent as y, computed as f, createApp as h, createElementBlock as g, openBlock as a, createVNode as n, createElementVNode as B, unref as t, withCtx as L, createBlock as v, createCommentVNode as C, mergeProps as k } from "vue";
2
+ import { VisXYContainer as b, VisArea as x, VisAxis as s, VisCrosshair as T, VisBulletLegend as V } from "@unovis/vue";
3
3
  import { CurveType as _ } from "@unovis/ts";
4
- import C from "../Tooltip.js";
5
- const N = { class: "flex flex-col space-y-4" }, A = { class: "flex items center justify-end" }, G = /* @__PURE__ */ y({
4
+ import N from "../Tooltip.js";
5
+ const A = { class: "flex flex-col space-y-4" }, j = { class: "flex items center justify-end" }, O = /* @__PURE__ */ y({
6
6
  __name: "AreaStackedChart",
7
7
  props: {
8
8
  data: {},
@@ -18,56 +18,53 @@ const N = { class: "flex flex-col space-y-4" }, A = { class: "flex items center
18
18
  yGridLine: { type: Boolean },
19
19
  yDomainLine: { type: Boolean },
20
20
  xTickLine: { type: Boolean },
21
- yTickLine: { type: Boolean }
21
+ yTickLine: { type: Boolean },
22
+ crosshairConfig: {}
22
23
  },
23
- setup(l) {
24
- const i = l, s = f(() => (e, m) => {
24
+ setup(c) {
25
+ const i = c, l = f(() => (e, m) => {
25
26
  if (typeof window > "u" || typeof document > "u")
26
27
  return "";
27
28
  try {
28
- const o = h(C, {
29
+ const o = h(N, {
29
30
  data: e,
30
31
  categories: i.categories
31
- }), a = document.createElement("div");
32
- o.mount(a);
33
- const u = a.innerHTML;
32
+ }), r = document.createElement("div");
33
+ o.mount(r);
34
+ const u = r.innerHTML;
34
35
  return o.unmount(), u;
35
36
  } catch {
36
37
  return "";
37
38
  }
38
39
  }), p = (e) => Number.parseInt(e.time), d = [(e) => e.firstTime, (e) => e.returning];
39
- return (e, m) => (r(), g("div", N, [
40
- n(t(x), {
40
+ return (e, m) => (a(), g("div", A, [
41
+ n(t(b), {
41
42
  data: e.data,
42
43
  padding: e.padding,
43
44
  height: e.height
44
45
  }, {
45
46
  default: L(() => [
46
- n(t(T), {
47
+ n(t(x), {
47
48
  x: p,
48
49
  y: d,
49
50
  color: Object.values(i.categories).map((o) => o.color),
50
51
  "curve-type": t(_).Linear
51
52
  }, null, 8, ["color", "curve-type"]),
52
- n(t(c), {
53
+ n(t(s), {
53
54
  type: "x",
54
55
  label: "Time",
55
56
  "num-ticks": 12
56
57
  }),
57
- n(t(c), {
58
+ n(t(s), {
58
59
  type: "y",
59
60
  label: "Number of visitors",
60
61
  "num-ticks": 3
61
62
  }),
62
- e.hideTooltip ? k("", !0) : (r(), v(t(b), {
63
- key: 0,
64
- color: "#666",
65
- template: s.value
66
- }, null, 8, ["template"]))
63
+ e.hideTooltip ? C("", !0) : (a(), v(t(T), k({ key: 0 }, e.crosshairConfig, { template: l.value }), null, 16, ["template"]))
67
64
  ]),
68
65
  _: 1
69
66
  }, 8, ["data", "padding", "height"]),
70
- B("div", A, [
67
+ B("div", j, [
71
68
  n(t(V), {
72
69
  items: Object.values(e.categories)
73
70
  }, null, 8, ["items"])
@@ -76,5 +73,5 @@ const N = { class: "flex flex-col space-y-4" }, A = { class: "flex items center
76
73
  }
77
74
  });
78
75
  export {
79
- G as default
76
+ O as default
80
77
  };
@@ -65,4 +65,22 @@ export interface AreaStackedChartProps<T> {
65
65
  * If `true`, displays tick lines on the y-axis.
66
66
  */
67
67
  yTickLine?: boolean;
68
+ /**
69
+ * Crosshair configuration object for customizing the appearance of the crosshair line.
70
+ */
71
+ crosshairConfig?: {
72
+ /**
73
+ * The color of the crosshair line. Accepts any valid CSS color string.
74
+ * Example: '#f00', 'rgba(0,0,0,0.5)', 'blue'
75
+ */
76
+ color?: string;
77
+ /**
78
+ * The stroke color of the crosshair line. Accepts any valid CSS color string.
79
+ */
80
+ strokeColor?: string;
81
+ /**
82
+ * The stroke width of the crosshair line in pixels.
83
+ */
84
+ strokeWidth?: number;
85
+ };
68
86
  }