vue-chrts 0.1.12-test.2 → 0.2.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,10 +1,13 @@
1
- import { defineComponent as b, computed as y, createApp as B, createElementBlock as d, openBlock as n, normalizeClass as g, createVNode as p, createCommentVNode as s, unref as i, withCtx as x, createBlock as m, Fragment as C, renderList as V } from "vue";
2
- import { Position as k, CurveType as F } from "@unovis/ts";
3
- import { VisXYContainer as O, VisTooltip as A, VisLine as M, VisAxis as f, VisCrosshair as N, VisBulletLegend as P } from "@unovis/vue";
4
- import j from "../Tooltip.js";
5
- import { LegendPosition as D } from "../../types.js";
6
- import { getFirstPropertyValue as E } from "../../utils.js";
7
- const H = /* @__PURE__ */ b({
1
+ import { defineComponent as P, computed as k, useSlots as x, useTemplateRef as O, ref as j, createElementBlock as u, openBlock as n, normalizeClass as g, createVNode as s, createCommentVNode as a, createElementVNode as w, unref as i, withCtx as M, createBlock as m, Fragment as W, renderList as E, mergeProps as G, renderSlot as h } from "vue";
2
+ import { Position as v, CurveType as X } from "@unovis/ts";
3
+ import { createMarkers as $, getFirstPropertyValue as z } from "../../utils.js";
4
+ import R from "../Tooltip.js";
5
+ import { VisXYContainer as Y, VisTooltip as S, VisLine as H, VisAxis as T, VisCrosshair as U, VisBulletLegend as q } from "@unovis/vue";
6
+ import { LegendPosition as I } from "../../types.js";
7
+ const J = {
8
+ ref: "slotWrapper",
9
+ class: "hidden"
10
+ }, te = /* @__PURE__ */ P({
8
11
  __name: "LineChart",
9
12
  props: {
10
13
  data: {},
@@ -18,13 +21,16 @@ const H = /* @__PURE__ */ b({
18
21
  left: 5
19
22
  }) },
20
23
  categories: {},
24
+ markerConfig: {},
21
25
  xFormatter: {},
22
26
  yFormatter: {},
23
27
  curveType: {},
24
- xNumTicks: { default: (t) => t.data.length > 24 ? 24 / 4 : t.data.length - 1 },
28
+ lineWidth: { default: 2 },
29
+ lineDashArray: {},
30
+ xNumTicks: { default: (o) => o.data.length > 24 ? 24 / 4 : o.data.length - 1 },
25
31
  xExplicitTicks: {},
26
32
  minMaxTicksOnly: { type: Boolean },
27
- yNumTicks: { default: (t) => t.data.length > 24 ? 24 / 4 : t.data.length - 1 },
33
+ yNumTicks: { default: (o) => o.data.length > 24 ? 24 / 4 : o.data.length - 1 },
28
34
  hideTooltip: { type: Boolean },
29
35
  hideLegend: { type: Boolean },
30
36
  legendPosition: {},
@@ -35,49 +41,53 @@ const H = /* @__PURE__ */ b({
35
41
  xTickLine: { type: Boolean },
36
42
  yTickLine: { type: Boolean },
37
43
  hideXAxis: { type: Boolean },
38
- hideYAxis: { type: Boolean }
44
+ hideYAxis: { type: Boolean },
45
+ crosshairConfig: { default: () => ({
46
+ color: "#666"
47
+ }) }
39
48
  },
40
- setup(t) {
41
- const o = t, h = Object.values(o.categories).map((e, c) => `var(--vis-color${c})`), T = (e) => Object.values(o.categories)[e].color ?? h[e], L = y(() => (e, c) => {
42
- if (typeof window > "u" || typeof document > "u")
43
- return "";
44
- try {
45
- const a = B(j, {
46
- data: e,
47
- categories: o.categories,
48
- toolTipTitle: E(e),
49
- yFormatter: o.yFormatter
50
- }), l = document.createElement("div");
51
- a.mount(l);
52
- const r = l.innerHTML;
53
- return a.unmount(), r;
54
- } catch {
55
- return "";
56
- }
57
- }), u = y(
58
- () => o.legendPosition === D.Top
59
- );
60
- return (e, c) => (n(), d("div", {
61
- class: g(["flex flex-col space-y-4", { "flex-col-reverse": u.value }])
49
+ emits: ["click"],
50
+ setup(o, { emit: L }) {
51
+ const C = L, t = o, b = k(() => t.markerConfig ? $(t.markerConfig) : ""), B = x(), c = O("slotWrapper"), l = j();
52
+ function D(e) {
53
+ return typeof window > "u" ? "" : c.value ? c.value.innerHTML : "";
54
+ }
55
+ function V(e) {
56
+ return l.value = e, D();
57
+ }
58
+ const p = k(
59
+ () => t.legendPosition === I.Top
60
+ ), A = Object.values(t.categories).map(
61
+ (e, r) => `var(--vis-color${r})`
62
+ ), F = (e) => Object.values(t.categories)[e].color ?? A[e];
63
+ return (e, r) => (n(), u("div", {
64
+ class: g(["flex flex-col space-y-4", {
65
+ "flex-col-reverse": p.value,
66
+ markers: !!t.markerConfig
67
+ }]),
68
+ onClick: r[0] || (r[0] = (d) => C("click", d, l.value))
62
69
  }, [
63
- p(i(O), {
70
+ s(i(Y), {
64
71
  data: e.data,
65
72
  padding: e.padding,
66
- height: e.height
73
+ height: e.height,
74
+ svgDefs: b.value
67
75
  }, {
68
- default: x(() => [
69
- p(i(A), {
70
- "horizontal-placement": i(k).Right,
71
- "vertical-placement": i(k).Top
76
+ default: M(() => [
77
+ s(i(S), {
78
+ "horizontal-placement": i(v).Right,
79
+ "vertical-placement": i(v).Top
72
80
  }, null, 8, ["horizontal-placement", "vertical-placement"]),
73
- (n(!0), d(C, null, V(Object.keys(o.categories), (a, l) => (n(), m(i(M), {
74
- key: l,
75
- x: (r, v) => v,
76
- y: (r) => r[a],
77
- color: T(l),
78
- "curve-type": e.curveType ?? i(F).MonotoneX
79
- }, null, 8, ["x", "y", "color", "curve-type"]))), 128)),
80
- e.hideXAxis ? s("", !0) : (n(), m(i(f), {
81
+ (n(!0), u(W, null, E(Object.keys(t.categories), (d, y) => (n(), m(i(H), {
82
+ key: y,
83
+ x: (f, N) => N,
84
+ y: (f) => f[d],
85
+ color: F(y),
86
+ "curve-type": e.curveType ?? i(X).MonotoneX,
87
+ "line-width": e.lineWidth,
88
+ lineDashArray: e.lineDashArray
89
+ }, null, 8, ["x", "y", "color", "curve-type", "line-width", "lineDashArray"]))), 128)),
90
+ e.hideXAxis ? a("", !0) : (n(), m(i(T), {
81
91
  key: 0,
82
92
  type: "x",
83
93
  "tick-format": e.xFormatter,
@@ -88,9 +98,9 @@ const H = /* @__PURE__ */ b({
88
98
  "tick-line": e.xTickLine,
89
99
  "num-ticks": e.xNumTicks,
90
100
  "tick-values": e.xExplicitTicks,
91
- minMaxTicksOnly: e.minMaxTicksOnly
92
- }, null, 8, ["tick-format", "label", "domain-line", "grid-line", "tick-line", "num-ticks", "tick-values", "minMaxTicksOnly"])),
93
- e.hideYAxis ? s("", !0) : (n(), m(i(f), {
101
+ "min-max-ticks-only": e.minMaxTicksOnly
102
+ }, null, 8, ["tick-format", "label", "domain-line", "grid-line", "tick-line", "num-ticks", "tick-values", "min-max-ticks-only"])),
103
+ e.hideYAxis ? a("", !0) : (n(), m(i(T), {
94
104
  key: 1,
95
105
  type: "y",
96
106
  "tick-format": e.yFormatter,
@@ -100,25 +110,34 @@ const H = /* @__PURE__ */ b({
100
110
  "grid-line": e.yGridLine,
101
111
  "tick-line": e.yTickLine
102
112
  }, null, 8, ["tick-format", "label", "num-ticks", "domain-line", "grid-line", "tick-line"])),
103
- e.hideTooltip ? s("", !0) : (n(), m(i(N), {
104
- key: 2,
105
- color: "#666",
106
- template: L.value
107
- }, null, 8, ["template"]))
113
+ e.hideTooltip ? a("", !0) : (n(), m(i(U), G({ key: 2 }, e.crosshairConfig, { template: V }), null, 16))
108
114
  ]),
109
115
  _: 1
110
- }, 8, ["data", "padding", "height"]),
111
- e.hideLegend ? s("", !0) : (n(), d("div", {
116
+ }, 8, ["data", "padding", "height", "svgDefs"]),
117
+ e.hideLegend ? a("", !0) : (n(), u("div", {
112
118
  key: 0,
113
- class: g(["flex items center justify-end", { "pb-4": u.value }])
119
+ class: g(["flex items center justify-end", { "pb-4": p.value }])
114
120
  }, [
115
- p(i(P), {
121
+ s(i(q), {
116
122
  items: Object.values(e.categories)
117
123
  }, null, 8, ["items"])
118
- ], 2))
124
+ ], 2)),
125
+ w("div", J, [
126
+ i(B).tooltip ? h(e.$slots, "tooltip", {
127
+ key: 0,
128
+ values: l.value
129
+ }) : l.value ? h(e.$slots, "fallback", { key: 1 }, () => [
130
+ s(R, {
131
+ data: l.value,
132
+ categories: e.categories,
133
+ toolTipTitle: i(z)(l.value) ?? "",
134
+ yFormatter: t.yFormatter
135
+ }, null, 8, ["data", "categories", "toolTipTitle", "yFormatter"])
136
+ ]) : a("", !0)
137
+ ], 512)
119
138
  ], 2));
120
139
  }
121
140
  });
122
141
  export {
123
- H as default
142
+ te as default
124
143
  };
@@ -1,10 +1,17 @@
1
1
  import { LineChartProps } 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> & LineChartProps<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"> & LineChartProps<T> & Partial<{}>> & import('vue').PublicProps;
4
6
  expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
5
7
  attrs: any;
6
- slots: {};
7
- emit: {};
8
+ slots: {
9
+ tooltip?(_: {
10
+ values: T | undefined;
11
+ }): any;
12
+ fallback?(_: {}): any;
13
+ };
14
+ emit: (e: "click", event: MouseEvent, values?: T) => void;
8
15
  }>) => import('vue').VNode & {
9
16
  __ctx?: Awaited<typeof __VLS_setup>;
10
17
  };
@@ -1,4 +1,4 @@
1
- import { BulletLegendItemInterface, CurveType, LegendPosition } from '../../types';
1
+ import { axisFormatter, BulletLegendItemInterface, CurveType, LegendPosition, MarkerConfig } from '../../types';
2
2
  export interface LineChartProps<T> {
3
3
  /**
4
4
  * The data to be displayed in the line chart.
@@ -19,9 +19,9 @@ export interface LineChartProps<T> {
19
19
  */
20
20
  yLabel?: string;
21
21
  /**
22
- * Optional padding applied to the chart.
23
- * Allows specifying individual padding values for the top, right, bottom, and left sides.
24
- */
22
+ * Optional padding applied to the chart.
23
+ * Allows specifying individual padding values for the top, right, bottom, and left sides.
24
+ */
25
25
  padding?: {
26
26
  top: number;
27
27
  right: number;
@@ -34,24 +34,36 @@ export interface LineChartProps<T> {
34
34
  */
35
35
  categories: Record<string, BulletLegendItemInterface>;
36
36
  /**
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);
37
+ * A record mapping marker keys to show custom patterns.
38
+ */
39
+ markerConfig?: Record<string, MarkerConfig>;
40
+ /**
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?: axisFormatter;
43
47
  /**
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);
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?: axisFormatter;
50
54
  /**
51
55
  * The type of curve to use for the line chart.
52
56
  * See `CurveType` for available options.
53
57
  */
54
58
  curveType?: CurveType;
59
+ /**
60
+ * The width of the line in pixels. Default is 2px.
61
+ */
62
+ lineWidth?: number;
63
+ /**
64
+ * Line dash array, see SVG's stroke-dasharray. Default: `undefined`
65
+ */
66
+ lineDashArray?: number[];
55
67
  /**
56
68
  * The desired number of ticks on the x-axis.
57
69
  */
@@ -113,4 +125,22 @@ export interface LineChartProps<T> {
113
125
  * If `true`, hide the y-axis.
114
126
  */
115
127
  hideYAxis?: boolean;
128
+ /**
129
+ * Crosshair configuration object for customizing the appearance of the crosshair line.
130
+ */
131
+ crosshairConfig?: {
132
+ /**
133
+ * The color of the crosshair line. Accepts any valid CSS color string.
134
+ * Example: '#f00', 'rgba(0,0,0,0.5)', 'blue'
135
+ */
136
+ color?: string;
137
+ /**
138
+ * The stroke color of the crosshair line. Accepts any valid CSS color string.
139
+ */
140
+ strokeColor?: string;
141
+ /**
142
+ * The stroke width of the crosshair line in pixels.
143
+ */
144
+ strokeWidth?: number;
145
+ };
116
146
  }
@@ -1,10 +1,10 @@
1
- import { BulletLegendItemInterface } from '../types';
1
+ import { axisFormatter, BulletLegendItemInterface } 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
3
  props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, never> & {
4
4
  data: T;
5
5
  categories: Record<string, BulletLegendItemInterface>;
6
6
  toolTipTitle: string | number;
7
- yFormatter?: (value: T) => any;
7
+ yFormatter?: axisFormatter;
8
8
  } & Partial<{}>> & import('vue').PublicProps;
9
9
  expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
10
10
  attrs: any;
package/dist/types.d.ts CHANGED
@@ -40,3 +40,11 @@ declare enum Orientation {
40
40
  Vertical = "vertical"
41
41
  }
42
42
  export { LegendPosition, CurveType, Orientation, type AreaChartProps, type BarChartProps, type LineChartProps, type DonutChartProps, type BulletLegendItemInterface, };
43
+ export type axisFormatter = ((tick: number, i?: number, ticks?: number[]) => string) | ((tick: Date, i?: number, ticks?: Date[]) => string);
44
+ export interface MarkerConfig {
45
+ type?: "circle" | "square" | "triangle" | "diamond";
46
+ size?: number;
47
+ strokeWidth?: number;
48
+ color?: string;
49
+ strokeColor?: string;
50
+ }
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,8 @@
1
+ import { MarkerConfig } from './types';
1
2
  export declare function getDistributedIndices(length: number, numTicks: number): number[];
2
3
  export declare function getFirstPropertyValue(obj: unknown): undefined;
4
+ export declare const markerShape: (type: string, size: number, strokeWidth: number, color: string, strokeColor: string) => string;
5
+ export declare function createMarkers(markerConfig: Record<string, MarkerConfig>): string;
6
+ export declare const flattenData: (data: any[], xAxis: string) => {
7
+ month: any;
8
+ }[];
package/dist/utils.js CHANGED
@@ -1,9 +1,49 @@
1
- function r(e) {
2
- if (e && Object.keys(e).length > 0) {
3
- const t = Object.keys(e)[0];
4
- return e[t];
1
+ function o(n) {
2
+ if (n && Object.keys(n).length > 0) {
3
+ const e = Object.keys(n)[0];
4
+ return n[e];
5
5
  }
6
6
  }
7
+ const u = (n, e, r, t, $) => {
8
+ switch (n) {
9
+ case "circle":
10
+ return `<circle cx="${e / 2}" cy="${e / 2}" r="${(e - r) / 2}" stroke-width="${r}" stroke="${$}" fill="${t}" />`;
11
+ case "square":
12
+ return `<rect x="${r / 2}" y="${r / 2}" width="${e - r}" height="${e - r}" stroke-width="${r}" stroke="${$}" fill="${t}" />`;
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="${t}" />`;
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="${t}" />`;
17
+ default:
18
+ return "";
19
+ }
20
+ };
21
+ function m(n) {
22
+ return Object.entries(n).map(([e, r]) => {
23
+ const t = r.type || "circle", $ = r.size || 10, c = r.strokeWidth || 2, a = r.color || "#000", l = r.strokeColor || r.color || "#000";
24
+ return `<marker id="circle-marker-${e}" viewBox="0 0 ${$} ${$}" refX="${$ / 2}" refY="${$ / 2}" markerWidth="${$ / 2}" markerHeight="${$ / 2}">
25
+ ${u(t, $, c, a, l)}
26
+ </marker>`;
27
+ }).join(`
28
+ `);
29
+ }
30
+ function p(n) {
31
+ return n.charAt(0).toUpperCase() + n.slice(1);
32
+ }
33
+ const y = (n, e) => {
34
+ const r = Object.keys(n[0]).filter(($) => $ !== e), t = Object.keys(n[0][r[0]]);
35
+ return n.map(($) => ({
36
+ month: $.month,
37
+ ...r.flatMap(
38
+ (c) => t.map((a) => ({
39
+ [`${c}${p(a)}`]: $[c][a]
40
+ }))
41
+ ).reduce((c, a) => ({ ...c, ...a }), {})
42
+ }));
43
+ };
7
44
  export {
8
- r as getFirstPropertyValue
45
+ m as createMarkers,
46
+ y as flattenData,
47
+ o as getFirstPropertyValue,
48
+ u as markerShape
9
49
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-chrts",
3
- "version": "0.1.12-test.2",
3
+ "version": "0.2.0-beta.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -20,9 +20,6 @@
20
20
  "preview": "vite preview",
21
21
  "release": "commit-and-tag-version"
22
22
  },
23
- "dependencies": {
24
- "@unovis/ts": "^1.5.1"
25
- },
26
23
  "peerDependencies": {
27
24
  "vue": "^3.5.13"
28
25
  },
@@ -30,7 +27,8 @@
30
27
  "@tailwindcss/vite": "^4.0.15",
31
28
  "@tanstack/vue-table": "^8.21.2",
32
29
  "@types/node": "^22.13.11",
33
- "@unovis/vue": "^1.5.1",
30
+ "@unovis/ts": "^1.5.2",
31
+ "@unovis/vue": "^1.5.2",
34
32
  "@vitejs/plugin-vue": "^5.2.1",
35
33
  "@vue/tsconfig": "^0.7.0",
36
34
  "@vueuse/core": "^13.0.0",