vue-chrts 0.2.2-test.0 → 0.2.2-test.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,4 +1,4 @@
1
- import { defineComponent as C, useSlots as D, useTemplateRef as N, ref as O, computed as T, createElementBlock as y, openBlock as n, normalizeStyle as v, createVNode as g, createCommentVNode as m, createElementVNode as S, unref as i, withCtx as w, createBlock as u, Fragment as E, renderList as M, renderSlot as B } from "vue";
1
+ import { defineComponent as C, useSlots as S, useTemplateRef as D, ref as N, computed as c, createElementBlock as y, openBlock as n, normalizeStyle as T, createVNode as g, createCommentVNode as m, createElementVNode as O, unref as i, withCtx as w, createBlock as u, Fragment as E, renderList as M, renderSlot as B } from "vue";
2
2
  import { Orientation as l, StackedBar as j, GroupedBar as z } from "@unovis/ts";
3
3
  import { getFirstPropertyValue as H } from "../../utils.js";
4
4
  import { useStackedGrouped as W } from "./stackedGroupedUtils.js";
@@ -8,7 +8,7 @@ import { LegendPosition as I } from "../../types.js";
8
8
  const U = {
9
9
  ref: "slotWrapper",
10
10
  style: { display: "none" }
11
- }, oe = /* @__PURE__ */ C({
11
+ }, ae = /* @__PURE__ */ C({
12
12
  __name: "BarChart",
13
13
  props: {
14
14
  data: {},
@@ -45,38 +45,42 @@ const U = {
45
45
  yGridLine: { type: Boolean, default: !0 },
46
46
  hideXAxis: { type: Boolean },
47
47
  hideYAxis: { type: Boolean },
48
+ stackedGroupedSpacing: { default: 0.1 },
48
49
  stackAndGrouped: { type: Boolean },
49
50
  xAxis: {}
50
51
  },
51
52
  emits: ["click"],
52
53
  setup(t, { emit: V }) {
53
- const x = V, o = t, P = D(), c = N("slotWrapper"), r = O();
54
- if (!o.yAxis || o.yAxis.length === 0)
54
+ const x = V, a = t, G = S(), k = D("slotWrapper"), r = N();
55
+ if (!a.yAxis || a.yAxis.length === 0)
55
56
  throw new Error("yAxis is required");
56
- const k = T(() => o.yAxis.map((e) => (d) => d[e])), f = (e, d) => {
57
- var a;
58
- return (a = Object.values(o.categories)[d]) == null ? void 0 : a.color;
59
- }, s = W({
60
- data: o.data,
61
- categories: o.categories,
62
- stackAndGrouped: o.stackAndGrouped,
63
- xAxis: o.xAxis
64
- }), h = T(
65
- () => o.legendPosition === I.Top
57
+ const f = c(() => a.yAxis.map((e) => (d) => d[e])), v = (e, d) => {
58
+ var o;
59
+ return (o = Object.values(a.categories)[d]) == null ? void 0 : o.color;
60
+ }, s = c(
61
+ () => W({
62
+ data: a.data,
63
+ categories: a.categories,
64
+ stackAndGrouped: a.stackAndGrouped,
65
+ xAxis: a.xAxis,
66
+ spacing: a.stackedGroupedSpacing
67
+ }).value
68
+ ), h = c(
69
+ () => a.legendPosition === I.Top
66
70
  );
67
71
  function b(e) {
68
- return r.value = e, G();
72
+ return r.value = e, P();
69
73
  }
70
- function G(e) {
71
- return typeof window > "u" ? "" : c.value ? c.value.innerHTML : "";
74
+ function P(e) {
75
+ return typeof window > "u" ? "" : k.value ? k.value.innerHTML : "";
72
76
  }
73
77
  return (e, d) => (n(), y("div", {
74
- style: v({
78
+ style: T({
75
79
  display: "flex",
76
80
  flexDirection: h.value ? "column-reverse" : "column",
77
81
  gap: "1rem"
78
82
  }),
79
- onClick: d[0] || (d[0] = (a) => x("click", a, r.value))
83
+ onClick: d[0] || (d[0] = (o) => x("click", o, r.value))
80
84
  }, [
81
85
  g(i(X), {
82
86
  padding: e.padding,
@@ -89,22 +93,22 @@ const U = {
89
93
  [i(j).selectors.bar]: b
90
94
  }
91
95
  }, null, 8, ["triggers"]),
92
- e.stackAndGrouped ? (n(!0), y(E, { key: 0 }, M(i(s).states, (a) => (n(), u(i(L), {
93
- key: a,
94
- data: i(s).chartData,
95
- x: (p, F) => F + i(s).positions[a],
96
- y: i(s).bars[a],
97
- color: i(s).colorFunctions[a],
96
+ e.stackAndGrouped ? (n(!0), y(E, { key: 0 }, M(s.value.states, (o) => (n(), u(i(L), {
97
+ key: o,
98
+ data: s.value.chartData,
99
+ x: (p, F) => F + s.value.positions[o],
100
+ y: s.value.bars[o],
101
+ color: s.value.colorFunctions[o],
98
102
  "rounded-corners": e.radius ?? 0,
99
103
  "group-padding": e.groupPadding ?? 0,
100
- "bar-padding": e.barPadding ?? 0.2,
104
+ "bar-padding": e.barPadding,
101
105
  orientation: e.orientation ?? i(l).Vertical
102
106
  }, null, 8, ["data", "x", "y", "color", "rounded-corners", "group-padding", "bar-padding", "orientation"]))), 128)) : e.stacked ? (n(), u(i(L), {
103
107
  key: 2,
104
108
  data: e.data,
105
- x: (a, p) => p,
106
- y: k.value,
107
- color: f,
109
+ x: (o, p) => p,
110
+ y: f.value,
111
+ color: v,
108
112
  "rounded-corners": e.radius ?? 0,
109
113
  "group-padding": e.groupPadding ?? 0,
110
114
  "bar-padding": e.barPadding ?? 0.2,
@@ -112,9 +116,9 @@ const U = {
112
116
  }, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])) : (n(), u(i($), {
113
117
  key: 1,
114
118
  data: e.data,
115
- x: (a, p) => p,
116
- y: k.value,
117
- color: f,
119
+ x: (o, p) => p,
120
+ y: f.value,
121
+ color: v,
118
122
  "rounded-corners": e.radius ?? 0,
119
123
  "group-padding": e.groupPadding ?? 0,
120
124
  "bar-padding": e.barPadding ?? 0.2,
@@ -147,7 +151,7 @@ const U = {
147
151
  }, 8, ["padding", "height"]),
148
152
  e.hideLegend ? m("", !0) : (n(), y("div", {
149
153
  key: 0,
150
- style: v({
154
+ style: T({
151
155
  display: "flex",
152
156
  alignItems: "center",
153
157
  justifyContent: "flex-end",
@@ -155,19 +159,19 @@ const U = {
155
159
  })
156
160
  }, [
157
161
  g(i(R), {
158
- items: Object.values(o.categories)
162
+ items: Object.values(a.categories)
159
163
  }, null, 8, ["items"])
160
164
  ], 4)),
161
- S("div", U, [
162
- i(P).tooltip ? B(e.$slots, "tooltip", {
165
+ O("div", U, [
166
+ i(G).tooltip ? B(e.$slots, "tooltip", {
163
167
  key: 0,
164
168
  values: r.value
165
169
  }) : r.value ? B(e.$slots, "fallback", { key: 1 }, () => [
166
170
  g(q, {
167
171
  data: r.value,
168
- categories: o.categories,
172
+ categories: a.categories,
169
173
  toolTipTitle: i(H)(r.value) ?? "",
170
- yFormatter: o.orientation === i(l).Horizontal ? o.xFormatter : o.yFormatter
174
+ yFormatter: a.orientation === i(l).Horizontal ? a.xFormatter : a.yFormatter
171
175
  }, null, 8, ["data", "categories", "toolTipTitle", "yFormatter"])
172
176
  ]) : m("", !0)
173
177
  ], 512)
@@ -175,5 +179,5 @@ const U = {
175
179
  }
176
180
  });
177
181
  export {
178
- oe as default
182
+ ae as default
179
183
  };
@@ -6,6 +6,7 @@ export interface StackedGroupedConfig<T> {
6
6
  }>;
7
7
  stackAndGrouped: boolean;
8
8
  xAxis?: keyof T;
9
+ spacing?: number;
9
10
  }
10
11
  export interface StackedGroupedResult<T> {
11
12
  states: string[];
@@ -1,13 +1,11 @@
1
1
  import { computed as u } from "vue";
2
2
  import { flattenData as i } from "../../utils.js";
3
- function b(t) {
3
+ function g(t) {
4
4
  return u(() => {
5
- const o = f(t.categories), e = l(t.categories, o), r = p(e, t.categories), c = d(e), n = m(r), s = h(o);
6
- console.log(t, "config");
7
- const a = t.stackAndGrouped ? i(t.data, t.xAxis) : t.data;
5
+ const e = p(t.categories), o = f(t.categories, e), r = d(o, t.categories), c = l(o), n = m(r), s = h(e, t.spacing), a = t.stackAndGrouped ? i(t.data, t.xAxis) : t.data;
8
6
  return {
9
- states: o,
10
- groupedByState: e,
7
+ states: e,
8
+ groupedByState: o,
11
9
  colors: r,
12
10
  bars: c,
13
11
  colorFunctions: n,
@@ -16,52 +14,52 @@ function b(t) {
16
14
  };
17
15
  });
18
16
  }
19
- function f(t) {
20
- const o = /* @__PURE__ */ new Set();
17
+ function p(t) {
18
+ const e = /* @__PURE__ */ new Set();
21
19
  return Object.keys(t).forEach((r) => {
22
20
  const c = r.match(/([A-Z][a-z]+)$/);
23
- c && o.add(c[1]);
24
- }), Array.from(o);
21
+ c && e.add(c[1]);
22
+ }), Array.from(e);
25
23
  }
26
- function l(t, o) {
27
- const e = {};
28
- return o.forEach((r) => {
29
- e[r] = Object.keys(t).filter(
24
+ function f(t, e) {
25
+ const o = {};
26
+ return e.forEach((r) => {
27
+ o[r] = Object.keys(t).filter(
30
28
  (c) => c.endsWith(r)
31
29
  );
32
- }), e;
30
+ }), o;
33
31
  }
34
- function p(t, o) {
35
- const e = {};
32
+ function d(t, e) {
33
+ const o = {};
36
34
  return Object.entries(t).forEach(([r, c]) => {
37
- e[r] = c.map((n) => {
35
+ o[r] = c.map((n) => {
38
36
  var s;
39
- return ((s = o[n]) == null ? void 0 : s.color) ?? "#ccc";
37
+ return ((s = e[n]) == null ? void 0 : s.color) ?? "#ccc";
40
38
  });
41
- }), e;
39
+ }), o;
42
40
  }
43
- function d(t) {
44
- const o = {};
45
- return Object.entries(t).forEach(([e, r]) => {
46
- o[e] = r.map((c) => {
47
- const n = c.replace(e, "").toLowerCase();
48
- return (s) => s[n + e];
41
+ function l(t) {
42
+ const e = {};
43
+ return Object.entries(t).forEach(([o, r]) => {
44
+ e[o] = r.map((c) => {
45
+ const n = c.replace(o, "").toLowerCase();
46
+ return (s) => s[n + o];
49
47
  });
50
- }), o;
48
+ }), e;
51
49
  }
52
50
  function m(t) {
53
- const o = {};
54
- return Object.entries(t).forEach(([e, r]) => {
55
- o[e] = (c, n) => r[n] ?? "#ccc";
56
- }), o;
51
+ const e = {};
52
+ return Object.entries(t).forEach(([o, r]) => {
53
+ e[o] = (c, n) => r[n] ?? "#ccc";
54
+ }), e;
57
55
  }
58
- function h(t) {
59
- const o = t.length, e = 0.4, r = {};
56
+ function h(t, e = 0.4) {
57
+ const o = t.length, r = {};
60
58
  return t.forEach((c, n) => {
61
59
  const s = (n - (o - 1) / 2) * e;
62
60
  r[c] = s;
63
61
  }), r;
64
62
  }
65
63
  export {
66
- b as useStackedGrouped
64
+ g as useStackedGrouped
67
65
  };
@@ -133,6 +133,7 @@ type BarChartPropsBase<T> = {
133
133
  * If `true`, hide the y-axis.
134
134
  */
135
135
  hideYAxis?: boolean;
136
+ stackedGroupedSpacing?: number;
136
137
  };
137
138
  type BarChartPropsStackAndGrouped<T> = BarChartPropsBase<T> & {
138
139
  stackAndGrouped: true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-chrts",
3
- "version": "0.2.2-test.0",
3
+ "version": "0.2.2-test.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"