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

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 x, useSlots as F, useTemplateRef as O, ref as N, computed as M, createElementBlock as d, openBlock as o, normalizeClass as k, createVNode as r, createCommentVNode as a, createElementVNode as P, unref as i, withCtx as j, createBlock as s, Fragment as A, renderList as D, renderSlot as f } from "vue";
2
- import { Position as g, CurveType as E } from "@unovis/ts";
3
- import { getFirstPropertyValue as G } from "../../utils.js";
4
- import X from "../Tooltip.js";
5
- import { VisXYContainer as $, VisTooltip as w, VisLine as z, VisAxis as h, VisCrosshair as R, VisBulletLegend as W } from "@unovis/vue";
6
- import { LegendPosition as Y } from "../../types.js";
7
- const S = {
1
+ import { defineComponent as D, computed as f, useSlots as O, useTemplateRef as M, ref as N, createElementBlock as m, openBlock as n, normalizeClass as k, createVNode as r, createCommentVNode as l, createElementVNode as P, unref as i, withCtx as j, createBlock as s, Fragment as A, renderList as E, renderSlot as v } from "vue";
2
+ import { Position as h, CurveType as G } from "@unovis/ts";
3
+ import { createMarkers as X, getFirstPropertyValue as $ } from "../../utils.js";
4
+ import w from "../Tooltip.js";
5
+ import { VisXYContainer as z, VisTooltip as R, VisLine as W, VisAxis as T, VisCrosshair as Y, VisBulletLegend as S } from "@unovis/vue";
6
+ import { LegendPosition as H } from "../../types.js";
7
+ const U = {
8
8
  ref: "slotWrapper",
9
9
  class: "hidden"
10
- }, Z = /* @__PURE__ */ x({
10
+ }, _ = /* @__PURE__ */ D({
11
11
  __name: "LineChart",
12
12
  props: {
13
13
  data: {},
@@ -21,6 +21,7 @@ const S = {
21
21
  left: 5
22
22
  }) },
23
23
  categories: {},
24
+ markerConfig: {},
24
25
  xFormatter: {},
25
26
  yFormatter: {},
26
27
  curveType: {},
@@ -41,39 +42,42 @@ const S = {
41
42
  hideYAxis: { type: Boolean }
42
43
  },
43
44
  setup(t) {
44
- const n = t, T = F(), u = O("slotWrapper"), l = N(), v = Object.values(n.categories).map(
45
- (e, c) => `var(--vis-color${c})`
46
- ), L = (e) => Object.values(n.categories)[e].color ?? v[e];
47
- function b(e) {
45
+ const o = t, d = f(() => o.markerConfig ? X(o.markerConfig) : "");
46
+ console.log(d, "svgDefs");
47
+ const L = O(), u = M("slotWrapper"), a = N();
48
+ function C(e) {
48
49
  return typeof window > "u" ? "" : u.value ? u.value.innerHTML : "";
49
50
  }
50
- function B(e) {
51
- return l.value = e, b();
51
+ function b(e) {
52
+ return a.value = e, C();
52
53
  }
53
- const m = M(
54
- () => n.legendPosition === Y.Top
55
- );
56
- return (e, c) => (o(), d("div", {
57
- class: k(["flex flex-col space-y-4", { "flex-col-reverse": m.value }])
54
+ const c = f(
55
+ () => o.legendPosition === H.Top
56
+ ), B = Object.values(o.categories).map(
57
+ (e, p) => `var(--vis-color${p})`
58
+ ), V = (e) => Object.values(o.categories)[e].color ?? B[e];
59
+ return console.log(o.markerConfig, "props.markerConfig"), (e, p) => (n(), m("div", {
60
+ class: k(["flex flex-col space-y-4", { "flex-col-reverse": c.value, markers: !!o.markerConfig }])
58
61
  }, [
59
- r(i($), {
62
+ r(i(z), {
60
63
  data: e.data,
61
64
  padding: e.padding,
62
- height: e.height
65
+ height: e.height,
66
+ svgDefs: d.value
63
67
  }, {
64
68
  default: j(() => [
65
- r(i(w), {
66
- "horizontal-placement": i(g).Right,
67
- "vertical-placement": i(g).Top
69
+ r(i(R), {
70
+ "horizontal-placement": i(h).Right,
71
+ "vertical-placement": i(h).Top
68
72
  }, null, 8, ["horizontal-placement", "vertical-placement"]),
69
- (o(!0), d(A, null, D(Object.keys(n.categories), (C, p) => (o(), s(i(z), {
70
- key: p,
71
- x: (y, V) => V,
72
- y: (y) => y[C],
73
- color: L(p),
74
- "curve-type": e.curveType ?? i(E).MonotoneX
73
+ (n(!0), m(A, null, E(Object.keys(o.categories), (x, y) => (n(), s(i(W), {
74
+ key: y,
75
+ x: (g, F) => F,
76
+ y: (g) => g[x],
77
+ color: V(y),
78
+ "curve-type": e.curveType ?? i(G).MonotoneX
75
79
  }, null, 8, ["x", "y", "color", "curve-type"]))), 128)),
76
- e.hideXAxis ? a("", !0) : (o(), s(i(h), {
80
+ e.hideXAxis ? l("", !0) : (n(), s(i(T), {
77
81
  key: 0,
78
82
  type: "x",
79
83
  "tick-format": e.xFormatter,
@@ -86,7 +90,7 @@ const S = {
86
90
  "tick-values": e.xExplicitTicks,
87
91
  minMaxTicksOnly: e.minMaxTicksOnly
88
92
  }, null, 8, ["tick-format", "label", "domain-line", "grid-line", "tick-line", "num-ticks", "tick-values", "minMaxTicksOnly"])),
89
- e.hideYAxis ? a("", !0) : (o(), s(i(h), {
93
+ e.hideYAxis ? l("", !0) : (n(), s(i(T), {
90
94
  key: 1,
91
95
  type: "y",
92
96
  "tick-format": e.yFormatter,
@@ -96,38 +100,38 @@ const S = {
96
100
  "grid-line": e.yGridLine,
97
101
  "tick-line": e.yTickLine
98
102
  }, null, 8, ["tick-format", "label", "num-ticks", "domain-line", "grid-line", "tick-line"])),
99
- e.hideTooltip ? a("", !0) : (o(), s(i(R), {
103
+ e.hideTooltip ? l("", !0) : (n(), s(i(Y), {
100
104
  key: 2,
101
105
  color: "#666",
102
- template: B
106
+ template: b
103
107
  }))
104
108
  ]),
105
109
  _: 1
106
- }, 8, ["data", "padding", "height"]),
107
- e.hideLegend ? a("", !0) : (o(), d("div", {
110
+ }, 8, ["data", "padding", "height", "svgDefs"]),
111
+ e.hideLegend ? l("", !0) : (n(), m("div", {
108
112
  key: 0,
109
- class: k(["flex items center justify-end", { "pb-4": m.value }])
113
+ class: k(["flex items center justify-end", { "pb-4": c.value }])
110
114
  }, [
111
- r(i(W), {
115
+ r(i(S), {
112
116
  items: Object.values(e.categories)
113
117
  }, null, 8, ["items"])
114
118
  ], 2)),
115
- P("div", S, [
116
- i(T).tooltip ? f(e.$slots, "tooltip", {
119
+ P("div", U, [
120
+ i(L).tooltip ? v(e.$slots, "tooltip", {
117
121
  key: 0,
118
- values: l.value
119
- }) : l.value ? f(e.$slots, "fallback", { key: 1 }, () => [
120
- r(X, {
121
- data: l.value,
122
+ values: a.value
123
+ }) : a.value ? v(e.$slots, "fallback", { key: 1 }, () => [
124
+ r(w, {
125
+ data: a.value,
122
126
  categories: e.categories,
123
- toolTipTitle: i(G)(l.value) ?? "",
124
- yFormatter: n.yFormatter
127
+ toolTipTitle: i($)(a.value) ?? "",
128
+ yFormatter: o.yFormatter
125
129
  }, null, 8, ["data", "categories", "toolTipTitle", "yFormatter"])
126
- ]) : a("", !0)
130
+ ]) : l("", !0)
127
131
  ], 512)
128
132
  ], 2));
129
133
  }
130
134
  });
131
135
  export {
132
- Z as default
136
+ _ as default
133
137
  };
@@ -1,4 +1,10 @@
1
1
  import { axisFormatter, BulletLegendItemInterface, CurveType, LegendPosition } from '../../types';
2
+ export type MarkerConfig = {
3
+ type: 'circle' | 'square' | 'triangle' | 'diamond';
4
+ size?: number;
5
+ strokeWidth?: number;
6
+ color?: string;
7
+ };
2
8
  export interface LineChartProps<T> {
3
9
  /**
4
10
  * The data to be displayed in the line chart.
@@ -33,6 +39,7 @@ export interface LineChartProps<T> {
33
39
  * This defines the visual representation and labels for each category in the chart's legend.
34
40
  */
35
41
  categories: Record<string, BulletLegendItemInterface>;
42
+ markerConfig?: Record<string, MarkerConfig>;
36
43
  /**
37
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 x-axis.
38
45
  * @param {number} i - The index of the tick in the `ticks` array.
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,5 @@
1
+ import { MarkerConfig } from './components/LineChart/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) => string;
5
+ export declare function createMarkers(markerConfig: Record<string, MarkerConfig>): string;
package/dist/utils.js CHANGED
@@ -1,9 +1,34 @@
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 u($) {
2
+ if ($ && Object.keys($).length > 0) {
3
+ const n = Object.keys($)[0];
4
+ return $[n];
5
5
  }
6
6
  }
7
+ const l = ($, n, r, c) => {
8
+ switch ($) {
9
+ case "circle":
10
+ return `<circle cx="${n / 2}" cy="${n / 2}" r="${(n - r) / 2}" stroke-width="${r}" stroke="${c}" fill="none" />`;
11
+ case "square":
12
+ return `<rect x="${r / 2}" y="${r / 2}" width="${n - r}" height="${n - r}" stroke-width="${r}" stroke="${c}" fill="none" />`;
13
+ case "triangle":
14
+ return `<polygon points="${n / 2},${r / 2} ${n - r / 2},${n - r / 2} ${r / 2},${n - r / 2}" stroke-width="${r}" stroke="${c}" fill="none" />`;
15
+ case "diamond":
16
+ return `<polygon points="${n / 2},${r / 2} ${n - r / 2},${n / 2} ${n / 2},${n - r / 2} ${r / 2},${n / 2}" stroke-width="${r}" stroke="${c}" fill="none" />`;
17
+ default:
18
+ return "";
19
+ }
20
+ };
21
+ function o($) {
22
+ return Object.entries($).map(([n, r]) => {
23
+ const c = r.type || "circle", e = r.size || 10, t = r.strokeWidth || 2, a = r.color || "#000";
24
+ return `<marker id="circle-marker-${n}" viewBox="0 0 ${e} ${e}" refX="${e / 2}" refY="${e / 2}" markerWidth="${e / 2}" markerHeight="${e / 2}">
25
+ ${l(c, e, t, a)}
26
+ </marker>`;
27
+ }).join(`
28
+ `);
29
+ }
7
30
  export {
8
- r as getFirstPropertyValue
31
+ o as createMarkers,
32
+ u as getFirstPropertyValue,
33
+ l as markerShape
9
34
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-chrts",
3
- "version": "0.2.0-test.1",
3
+ "version": "0.2.0-test.3",
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.2"
25
- },
26
23
  "peerDependencies": {
27
24
  "vue": "^3.5.13"
28
25
  },
@@ -30,6 +27,7 @@
30
27
  "@tailwindcss/vite": "^4.0.15",
31
28
  "@tanstack/vue-table": "^8.21.2",
32
29
  "@types/node": "^22.13.11",
30
+ "@unovis/ts": "^1.5.2",
33
31
  "@unovis/vue": "^1.5.2",
34
32
  "@vitejs/plugin-vue": "^5.2.1",
35
33
  "@vue/tsconfig": "^0.7.0",