vue-chrts 0.1.0-beta.2 → 0.1.0-beta.4
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.
- package/README.md +84 -3
- package/dist/components/AreaChart/AreaChart.js +133 -0
- package/dist/components/AreaChart/AreaChart.vue.d.ts +14 -0
- package/dist/components/AreaChart/AreaChart2.js +4 -0
- package/dist/components/AreaChart/types.d.ts +91 -0
- package/dist/components/AreaStackedChart/AreaStackedChart.js +69 -0
- package/dist/components/AreaStackedChart/AreaStackedChart.vue.d.ts +20 -0
- package/dist/components/AreaStackedChart/AreaStackedChart2.js +4 -0
- package/dist/components/AreaStackedChart/types.d.ts +58 -0
- package/dist/components/BarChart/BarChart.js +121 -0
- package/dist/components/BarChart/BarChart.vue.d.ts +14 -0
- package/dist/components/BarChart/BarChart2.js +4 -0
- package/dist/components/BarChart/types.d.ts +114 -0
- package/dist/components/DonutChart/DonutChart.js +58 -0
- package/dist/components/DonutChart/DonutChart.vue.d.ts +18 -0
- package/dist/components/DonutChart/DonutChart2.js +4 -0
- package/dist/components/DonutChart/types.d.ts +36 -0
- package/dist/components/DonutChart/types.js +4 -0
- package/dist/components/LineChart/LineChart.js +110 -0
- package/dist/components/LineChart/LineChart.vue.d.ts +14 -0
- package/dist/components/LineChart/LineChart2.js +4 -0
- package/dist/components/LineChart/types.d.ts +98 -0
- package/dist/components/Tooltip.js +37 -0
- package/dist/components/Tooltip.vue.d.ts +17 -0
- package/dist/components/Tooltip2.js +4 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +16 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.js +6 -0
- package/dist/utils.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,86 @@
|
|
|
1
|
-
# Vue
|
|
1
|
+
# Vue-Chrts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Vue 3 charts package inspired by [Tremor](https://tremor.so/), built on top of [Unovis](https://unovis.dev). Vue-Chrts provides beautiful, responsive charts for your Vue applications with minimal setup.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
[Check the docs and examples](https://nuxtcharts.com/docs)
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 📊 Multiple chart types: Line, Bar, Area, Stacked Area, Donut
|
|
12
|
+
- 🎨 Customizable appearance
|
|
13
|
+
- 📱 Responsive design
|
|
14
|
+
- 💡 Simple, intuitive API
|
|
15
|
+
- 🚀 Built with Vue 3 and TypeScript
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# npm
|
|
21
|
+
npm install vue-chrts
|
|
22
|
+
|
|
23
|
+
# yarn
|
|
24
|
+
yarn add vue-chrts
|
|
25
|
+
|
|
26
|
+
# pnpm
|
|
27
|
+
pnpm add vue-chrts
|
|
28
|
+
```
|
|
29
|
+
[Check the docs and examples](https://nuxtcharts.com/docs)
|
|
30
|
+
|
|
31
|
+
## Usage Example
|
|
32
|
+
|
|
33
|
+
```vue
|
|
34
|
+
<script setup>
|
|
35
|
+
import { LineChart } from 'vue-chrts';
|
|
36
|
+
|
|
37
|
+
const data = [
|
|
38
|
+
{ month: 'Jan', sales: 100, profit: 50 },
|
|
39
|
+
{ month: 'Feb', sales: 120, profit: 55 },
|
|
40
|
+
{ month: 'Mar', sales: 180, profit: 80 },
|
|
41
|
+
{ month: 'Apr', sales: 110, profit: 40 },
|
|
42
|
+
{ month: 'May', sales: 90, profit: 30 },
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
const categories = {
|
|
46
|
+
sales: {
|
|
47
|
+
name: 'Sales',
|
|
48
|
+
color: '#3b82f6'
|
|
49
|
+
},
|
|
50
|
+
profit: {
|
|
51
|
+
name: 'Profit',
|
|
52
|
+
color: '#10b981'
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const xFormatter = (i) => data[i].month;
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<template>
|
|
60
|
+
<LineChart
|
|
61
|
+
:data="data"
|
|
62
|
+
:categories="categories"
|
|
63
|
+
:height="300"
|
|
64
|
+
:xFormatter="xFormatter"
|
|
65
|
+
xLabel="Month"
|
|
66
|
+
yLabel="Amount"
|
|
67
|
+
/>
|
|
68
|
+
</template>
|
|
69
|
+
```
|
|
70
|
+
[Check the docs and examples](https://nuxtcharts.com/docs)
|
|
71
|
+
|
|
72
|
+
## Available Charts
|
|
73
|
+
|
|
74
|
+
- `LineChart`
|
|
75
|
+
- `BarChart`
|
|
76
|
+
- `AreaChart`
|
|
77
|
+
- `AreaStackedChart`
|
|
78
|
+
- `DonutChart`
|
|
79
|
+
|
|
80
|
+
## Credits
|
|
81
|
+
|
|
82
|
+
This library is inspired by [Tremor](https://tremor.so/) and built on top of [Unovis](https://unovis.dev).
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { defineComponent as V, computed as f, createApp as C, createElementBlock as c, openBlock as a, normalizeClass as g, createVNode as l, createCommentVNode as d, unref as t, withCtx as G, createBlock as k, Fragment as h, renderList as N, mergeProps as $ } from "vue";
|
|
2
|
+
import { Position as v, CurveType as T } from "@unovis/ts";
|
|
3
|
+
import { VisXYContainer as P, VisTooltip as j, VisArea as D, VisLine as F, VisAxis as L, VisCrosshair as M, VisBulletLegend as O } from "@unovis/vue";
|
|
4
|
+
import A from "../Tooltip.js";
|
|
5
|
+
import { LegendPosition as E } from "../../types.js";
|
|
6
|
+
const Y = /* @__PURE__ */ V({
|
|
7
|
+
__name: "AreaChart",
|
|
8
|
+
props: {
|
|
9
|
+
data: {},
|
|
10
|
+
height: {},
|
|
11
|
+
xLabel: {},
|
|
12
|
+
yLabel: {},
|
|
13
|
+
categories: {},
|
|
14
|
+
xFormatter: {},
|
|
15
|
+
yFormatter: {},
|
|
16
|
+
curveType: {},
|
|
17
|
+
xNumTicks: { default: (i) => i.data.length > 24 ? 24 / 4 : i.data.length - 1 },
|
|
18
|
+
xExplicitTicks: {},
|
|
19
|
+
minMaxTicksOnly: {},
|
|
20
|
+
yNumTicks: { default: (i) => i.data.length > 24 ? 24 / 4 : i.data.length - 1 },
|
|
21
|
+
hideLegend: { type: Boolean },
|
|
22
|
+
hideTooltip: { type: Boolean },
|
|
23
|
+
xGridLine: { type: Boolean },
|
|
24
|
+
xDomainLine: { type: Boolean },
|
|
25
|
+
yGridLine: { type: Boolean },
|
|
26
|
+
yDomainLine: { type: Boolean },
|
|
27
|
+
legendPosition: {}
|
|
28
|
+
},
|
|
29
|
+
setup(i) {
|
|
30
|
+
const s = i, m = Object.values(s.categories).map((e) => e.color), b = f(() => (e) => {
|
|
31
|
+
if (typeof window > "u" || typeof document > "u")
|
|
32
|
+
return "";
|
|
33
|
+
try {
|
|
34
|
+
const o = C(A, {
|
|
35
|
+
data: e,
|
|
36
|
+
categories: s.categories
|
|
37
|
+
}), n = document.createElement("div");
|
|
38
|
+
o.mount(n);
|
|
39
|
+
const r = n.innerHTML;
|
|
40
|
+
return o.unmount(), r;
|
|
41
|
+
} catch {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
function x(e) {
|
|
46
|
+
var o;
|
|
47
|
+
return {
|
|
48
|
+
y: (n) => Number(n[e]),
|
|
49
|
+
color: ((o = s.categories[e]) == null ? void 0 : o.color) ?? "#3b82f6"
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const B = m.map(
|
|
53
|
+
(e, o) => `
|
|
54
|
+
<linearGradient id="gradient${o}-${e}" gradientTransform="rotate(90)">
|
|
55
|
+
<stop offset="0%" stop-color="${e}" stop-opacity="1" />
|
|
56
|
+
<stop offset="100%" stop-color="${e}" stop-opacity="0" />
|
|
57
|
+
</linearGradient>
|
|
58
|
+
`
|
|
59
|
+
).join(""), y = f(
|
|
60
|
+
() => s.legendPosition === E.Top
|
|
61
|
+
);
|
|
62
|
+
return (e, o) => (a(), c("div", {
|
|
63
|
+
class: g(["flex flex-col space-y-4", { "flex-col-reverse": y.value }])
|
|
64
|
+
}, [
|
|
65
|
+
l(t(P), {
|
|
66
|
+
data: e.data,
|
|
67
|
+
height: e.height,
|
|
68
|
+
"svg-defs": t(B)
|
|
69
|
+
}, {
|
|
70
|
+
default: G(() => [
|
|
71
|
+
e.hideTooltip ? d("", !0) : (a(), k(t(j), {
|
|
72
|
+
key: 0,
|
|
73
|
+
"horizontal-placement": t(v).Right,
|
|
74
|
+
"vertical-placement": t(v).Top
|
|
75
|
+
}, null, 8, ["horizontal-placement", "vertical-placement"])),
|
|
76
|
+
(a(!0), c(h, null, N(Object.keys(s.categories), (n, r) => (a(), c(h, { key: r }, [
|
|
77
|
+
l(t(D), $({
|
|
78
|
+
x: (p, u) => u,
|
|
79
|
+
ref_for: !0
|
|
80
|
+
}, x(n), {
|
|
81
|
+
color: `url(#gradient${r}-${t(m)[r]})`,
|
|
82
|
+
opacity: 0.5,
|
|
83
|
+
"curve-type": e.curveType ?? t(T).MonotoneX
|
|
84
|
+
}), null, 16, ["x", "color", "curve-type"]),
|
|
85
|
+
l(t(F), {
|
|
86
|
+
x: (p, u) => u,
|
|
87
|
+
y: (p) => p[n],
|
|
88
|
+
color: t(m)[r],
|
|
89
|
+
"curve-type": e.curveType ?? t(T).MonotoneX
|
|
90
|
+
}, null, 8, ["x", "y", "color", "curve-type"])
|
|
91
|
+
], 64))), 128)),
|
|
92
|
+
l(t(L), {
|
|
93
|
+
type: "x",
|
|
94
|
+
"tick-format": e.xFormatter,
|
|
95
|
+
label: e.xLabel,
|
|
96
|
+
"label-margin": 8,
|
|
97
|
+
"domain-line": e.xDomainLine,
|
|
98
|
+
"grid-line": e.xGridLine,
|
|
99
|
+
"num-ticks": e.xNumTicks,
|
|
100
|
+
"tick-values": e.xExplicitTicks,
|
|
101
|
+
"min-max-ticks-only": e.minMaxTicksOnly
|
|
102
|
+
}, null, 8, ["tick-format", "label", "domain-line", "grid-line", "num-ticks", "tick-values", "min-max-ticks-only"]),
|
|
103
|
+
l(t(L), {
|
|
104
|
+
type: "y",
|
|
105
|
+
"num-ticks": e.yNumTicks,
|
|
106
|
+
"tick-format": e.yFormatter,
|
|
107
|
+
label: e.yLabel,
|
|
108
|
+
"grid-line": e.yGridLine,
|
|
109
|
+
"domain-line": e.yDomainLine,
|
|
110
|
+
"tick-line": !!e.yGridLine
|
|
111
|
+
}, null, 8, ["num-ticks", "tick-format", "label", "grid-line", "domain-line", "tick-line"]),
|
|
112
|
+
e.hideTooltip ? d("", !0) : (a(), k(t(M), {
|
|
113
|
+
key: 1,
|
|
114
|
+
color: "#666",
|
|
115
|
+
template: b.value
|
|
116
|
+
}, null, 8, ["template"]))
|
|
117
|
+
]),
|
|
118
|
+
_: 1
|
|
119
|
+
}, 8, ["data", "height", "svg-defs"]),
|
|
120
|
+
e.hideLegend ? d("", !0) : (a(), c("div", {
|
|
121
|
+
key: 0,
|
|
122
|
+
class: g(["flex items center justify-end", { "pb-4": y.value }])
|
|
123
|
+
}, [
|
|
124
|
+
l(t(O), {
|
|
125
|
+
items: Object.values(e.categories)
|
|
126
|
+
}, null, 8, ["items"])
|
|
127
|
+
], 2))
|
|
128
|
+
], 2));
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
export {
|
|
132
|
+
Y as default
|
|
133
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AreaChartProps } from './types';
|
|
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;
|
|
4
|
+
expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
|
|
5
|
+
attrs: any;
|
|
6
|
+
slots: {};
|
|
7
|
+
emit: {};
|
|
8
|
+
}>) => import('vue').VNode & {
|
|
9
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
12
|
+
type __VLS_PrettifyLocal<T> = {
|
|
13
|
+
[K in keyof T]: T[K];
|
|
14
|
+
} & {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { LegendPosition } from '../../types';
|
|
2
|
+
import { BulletLegendItemInterface, CurveType } from '@unovis/ts';
|
|
3
|
+
export interface AreaChartProps<T> {
|
|
4
|
+
/**
|
|
5
|
+
* The data to be displayed in the area chart.
|
|
6
|
+
* Each element of the array represents a data point.
|
|
7
|
+
* The structure of 'T' should be compatible with the chart's rendering logic.
|
|
8
|
+
*/
|
|
9
|
+
data: T[];
|
|
10
|
+
/**
|
|
11
|
+
* The height of the chart in pixels.
|
|
12
|
+
*/
|
|
13
|
+
height: number;
|
|
14
|
+
/**
|
|
15
|
+
* Optional label for the x-axis.
|
|
16
|
+
*/
|
|
17
|
+
xLabel?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Optional label for the y-axis.
|
|
20
|
+
*/
|
|
21
|
+
yLabel?: string;
|
|
22
|
+
/**
|
|
23
|
+
* A record mapping category keys to `BulletLegendItemInterface` objects.
|
|
24
|
+
* This defines the visual representation and labels for each category in the chart's legend.
|
|
25
|
+
*/
|
|
26
|
+
categories: Record<string, BulletLegendItemInterface>;
|
|
27
|
+
/**
|
|
28
|
+
* A function that formats the x-axis tick labels.
|
|
29
|
+
* @param i The x-axis key of the item to be formatted.
|
|
30
|
+
* @param idx The index of the data point.
|
|
31
|
+
* @returns The formatted x-axis label.
|
|
32
|
+
*/
|
|
33
|
+
xFormatter: (i: number, idx: number) => string | number;
|
|
34
|
+
/**
|
|
35
|
+
* An optional function that formats the y-axis tick labels.
|
|
36
|
+
* @param i The y-axis key of the item to be formatted.
|
|
37
|
+
* @param idx The index of the data point (optional).
|
|
38
|
+
* @returns The formatted y-axis label or value.
|
|
39
|
+
*/
|
|
40
|
+
yFormatter?: (i: number, idx?: number) => string | number;
|
|
41
|
+
/**
|
|
42
|
+
* The type of curve to use for the area chart lines.
|
|
43
|
+
* See `CurveType` for available options.
|
|
44
|
+
*/
|
|
45
|
+
curveType?: CurveType;
|
|
46
|
+
/**
|
|
47
|
+
* The desired number of ticks on the x-axis.
|
|
48
|
+
*/
|
|
49
|
+
xNumTicks?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Force specific ticks on the x-axis.
|
|
52
|
+
*/
|
|
53
|
+
xExplicitTicks?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Force only first and last ticks on the x-axis.
|
|
56
|
+
*/
|
|
57
|
+
minMaxTicksOnly?: number;
|
|
58
|
+
/**
|
|
59
|
+
* The desired number of ticks on the y-axis.
|
|
60
|
+
*/
|
|
61
|
+
yNumTicks?: number;
|
|
62
|
+
/**
|
|
63
|
+
* If `true`, hides the chart legend.
|
|
64
|
+
*/
|
|
65
|
+
hideLegend?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* If `true`, hides the chart tooltip.
|
|
68
|
+
*/
|
|
69
|
+
hideTooltip?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* If `true`, displays grid lines along the x-axis.
|
|
72
|
+
*/
|
|
73
|
+
xGridLine?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* If `true`, displays a domain line (axis line) along the x-axis.
|
|
76
|
+
*/
|
|
77
|
+
xDomainLine?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* If `true`, displays grid lines along the y-axis.
|
|
80
|
+
*/
|
|
81
|
+
yGridLine?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* If `true`, displays a domain line (axis line) along the y-axis.
|
|
84
|
+
*/
|
|
85
|
+
yDomainLine?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Optional position for the legend, if applicable.
|
|
88
|
+
* See `LegendPosition` for available options.
|
|
89
|
+
*/
|
|
90
|
+
legendPosition?: LegendPosition;
|
|
91
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { defineComponent as d, computed as f, createApp as h, createElementBlock as y, openBlock as a, createVNode as o, createElementVNode as g, unref as t, withCtx as v, createBlock as _, createCommentVNode as V } from "vue";
|
|
2
|
+
import { VisXYContainer as k, VisArea as C, VisAxis as c, VisCrosshair as T, VisBulletLegend as b } from "@unovis/vue";
|
|
3
|
+
import { CurveType as x } from "@unovis/ts";
|
|
4
|
+
import B from "../Tooltip.js";
|
|
5
|
+
const N = { class: "flex flex-col space-y-4" }, A = { class: "flex items center justify-end" }, O = /* @__PURE__ */ d({
|
|
6
|
+
__name: "AreaStackedChart",
|
|
7
|
+
props: {
|
|
8
|
+
data: {},
|
|
9
|
+
height: {},
|
|
10
|
+
categories: {},
|
|
11
|
+
hideTooltip: { type: Boolean }
|
|
12
|
+
},
|
|
13
|
+
setup(s) {
|
|
14
|
+
const i = s, l = f(() => (e) => {
|
|
15
|
+
if (typeof window > "u" || typeof document > "u")
|
|
16
|
+
return "";
|
|
17
|
+
try {
|
|
18
|
+
const r = h(B, {
|
|
19
|
+
data: e,
|
|
20
|
+
categories: i.categories
|
|
21
|
+
}), n = document.createElement("div");
|
|
22
|
+
r.mount(n);
|
|
23
|
+
const p = n.innerHTML;
|
|
24
|
+
return r.unmount(), p;
|
|
25
|
+
} catch {
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
}), m = (e) => Number.parseInt(e.time), u = [(e) => e.firstTime, (e) => e.returning];
|
|
29
|
+
return (e, r) => (a(), y("div", N, [
|
|
30
|
+
o(t(k), {
|
|
31
|
+
data: e.data,
|
|
32
|
+
height: e.height
|
|
33
|
+
}, {
|
|
34
|
+
default: v(() => [
|
|
35
|
+
o(t(C), {
|
|
36
|
+
x: m,
|
|
37
|
+
y: u,
|
|
38
|
+
color: Object.values(i.categories).map((n) => n.color),
|
|
39
|
+
"curve-type": t(x).Linear
|
|
40
|
+
}, null, 8, ["color", "curve-type"]),
|
|
41
|
+
o(t(c), {
|
|
42
|
+
type: "x",
|
|
43
|
+
label: "Time",
|
|
44
|
+
"num-ticks": 12
|
|
45
|
+
}),
|
|
46
|
+
o(t(c), {
|
|
47
|
+
type: "y",
|
|
48
|
+
label: "Number of visitors",
|
|
49
|
+
"num-ticks": 3
|
|
50
|
+
}),
|
|
51
|
+
e.hideTooltip ? V("", !0) : (a(), _(t(T), {
|
|
52
|
+
key: 0,
|
|
53
|
+
color: "#666",
|
|
54
|
+
template: l.value
|
|
55
|
+
}, null, 8, ["template"]))
|
|
56
|
+
]),
|
|
57
|
+
_: 1
|
|
58
|
+
}, 8, ["data", "height"]),
|
|
59
|
+
g("div", A, [
|
|
60
|
+
o(t(b), {
|
|
61
|
+
items: Object.values(e.categories)
|
|
62
|
+
}, null, 8, ["items"])
|
|
63
|
+
])
|
|
64
|
+
]));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
export {
|
|
68
|
+
O as default
|
|
69
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BulletLegendItemInterface } from '@unovis/ts';
|
|
2
|
+
export type AreaStackedChartProps<T> = {
|
|
3
|
+
data: T[];
|
|
4
|
+
height: number;
|
|
5
|
+
categories: Record<string, BulletLegendItemInterface>;
|
|
6
|
+
hideTooltip?: boolean;
|
|
7
|
+
};
|
|
8
|
+
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<{
|
|
9
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, never> & AreaStackedChartProps<T> & Partial<{}>> & import('vue').PublicProps;
|
|
10
|
+
expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
|
|
11
|
+
attrs: any;
|
|
12
|
+
slots: {};
|
|
13
|
+
emit: {};
|
|
14
|
+
}>) => import('vue').VNode & {
|
|
15
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
18
|
+
type __VLS_PrettifyLocal<T> = {
|
|
19
|
+
[K in keyof T]: T[K];
|
|
20
|
+
} & {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { BulletLegendItemInterface } from '@unovis/ts';
|
|
2
|
+
export interface AreaStackedChartProps<T> {
|
|
3
|
+
/**
|
|
4
|
+
* The data to be displayed in the stacked area chart.
|
|
5
|
+
* Each element of the array represents a data point.
|
|
6
|
+
* The structure of 'T' should be compatible with the chart's rendering logic.
|
|
7
|
+
*/
|
|
8
|
+
data: T[];
|
|
9
|
+
/**
|
|
10
|
+
* The height of the chart in pixels.
|
|
11
|
+
*/
|
|
12
|
+
height: number;
|
|
13
|
+
/**
|
|
14
|
+
* A record mapping category keys to `BulletLegendItemInterface` objects.
|
|
15
|
+
* This defines the visual representation and labels for each category in the chart's legend.
|
|
16
|
+
*/
|
|
17
|
+
categories: Record<string, BulletLegendItemInterface>;
|
|
18
|
+
/**
|
|
19
|
+
* If `true`, hides the chart tooltip.
|
|
20
|
+
*/
|
|
21
|
+
hideTooltip?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Optional label for the x-axis.
|
|
24
|
+
*/
|
|
25
|
+
xLabel?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Optional label for the y-axis.
|
|
28
|
+
*/
|
|
29
|
+
yLabel?: string;
|
|
30
|
+
/**
|
|
31
|
+
* If `true`, hides the chart legend.
|
|
32
|
+
*/
|
|
33
|
+
hideLegend?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* If `true`, displays grid lines along the x-axis.
|
|
36
|
+
*/
|
|
37
|
+
xGridLine?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* If `true`, displays a domain line (axis line) along the x-axis.
|
|
40
|
+
*/
|
|
41
|
+
xDomainLine?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* If `true`, displays grid lines along the y-axis.
|
|
44
|
+
*/
|
|
45
|
+
yGridLine?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* If `true`, displays a domain line (axis line) along the y-axis.
|
|
48
|
+
*/
|
|
49
|
+
yDomainLine?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* If `true`, displays tick lines on the x-axis.
|
|
52
|
+
*/
|
|
53
|
+
xTickLine?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* If `true`, displays tick lines on the y-axis.
|
|
56
|
+
*/
|
|
57
|
+
yTickLine?: boolean;
|
|
58
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { defineComponent as b, computed as u, createApp as h, createElementBlock as y, openBlock as d, normalizeClass as k, createVNode as t, createCommentVNode as B, unref as i, withCtx as T, createBlock as f } from "vue";
|
|
2
|
+
import { Orientation as s, StackedBar as v, GroupedBar as V } from "@unovis/ts";
|
|
3
|
+
import { VisXYContainer as P, VisTooltip as x, VisGroupedBar as C, VisStackedBar as G, VisAxis as L, VisBulletLegend as N } from "@unovis/vue";
|
|
4
|
+
import A from "../Tooltip.js";
|
|
5
|
+
import { LegendPosition as O } from "../../types.js";
|
|
6
|
+
const M = /* @__PURE__ */ b({
|
|
7
|
+
__name: "BarChart",
|
|
8
|
+
props: {
|
|
9
|
+
data: {},
|
|
10
|
+
stacked: { type: Boolean },
|
|
11
|
+
height: {},
|
|
12
|
+
xLabel: {},
|
|
13
|
+
yLabel: {},
|
|
14
|
+
categories: {},
|
|
15
|
+
xFormatter: {},
|
|
16
|
+
yFormatter: {},
|
|
17
|
+
yNumTicks: { default: (a) => a.data.length > 24 ? 24 / 4 : a.data.length - 1 },
|
|
18
|
+
minMaxTicksOnly: {},
|
|
19
|
+
xNumTicks: { default: (a) => a.data.length > 24 ? 24 / 4 : a.data.length - 1 },
|
|
20
|
+
xExplicitTicks: {},
|
|
21
|
+
yAxis: {},
|
|
22
|
+
groupPadding: {},
|
|
23
|
+
barPadding: {},
|
|
24
|
+
radius: {},
|
|
25
|
+
hideLegend: { type: Boolean },
|
|
26
|
+
orientation: { default: s.Vertical },
|
|
27
|
+
legendPosition: {},
|
|
28
|
+
xDomainLine: { type: Boolean },
|
|
29
|
+
yDomainLine: { type: Boolean },
|
|
30
|
+
xTickLine: { type: Boolean },
|
|
31
|
+
yTickLine: { type: Boolean },
|
|
32
|
+
xGridLine: { type: Boolean },
|
|
33
|
+
yGridLine: { type: Boolean, default: !0 }
|
|
34
|
+
},
|
|
35
|
+
setup(a) {
|
|
36
|
+
const r = a, m = u(() => r.yAxis.map((e) => (n) => n[e])), c = (e, n) => Object.values(r.categories)[n].color, p = u(
|
|
37
|
+
() => r.legendPosition === O.Top
|
|
38
|
+
), g = u(() => (e) => {
|
|
39
|
+
if (typeof window > "u" || typeof document > "u")
|
|
40
|
+
return "";
|
|
41
|
+
try {
|
|
42
|
+
const n = h(A, {
|
|
43
|
+
data: e,
|
|
44
|
+
categories: r.categories
|
|
45
|
+
}), l = document.createElement("div");
|
|
46
|
+
n.mount(l);
|
|
47
|
+
const o = l.innerHTML;
|
|
48
|
+
return n.unmount(), o;
|
|
49
|
+
} catch {
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return (e, n) => (d(), y("div", {
|
|
54
|
+
class: k(["flex flex-col space-y-4", { "flex-col-reverse": p.value }])
|
|
55
|
+
}, [
|
|
56
|
+
t(i(P), { height: e.height }, {
|
|
57
|
+
default: T(() => [
|
|
58
|
+
t(i(x), {
|
|
59
|
+
triggers: {
|
|
60
|
+
[i(V).selectors.bar]: g.value,
|
|
61
|
+
[i(v).selectors.bar]: g.value
|
|
62
|
+
}
|
|
63
|
+
}, null, 8, ["triggers"]),
|
|
64
|
+
e.stacked ? (d(), f(i(G), {
|
|
65
|
+
key: 1,
|
|
66
|
+
data: e.data,
|
|
67
|
+
x: (l, o) => o,
|
|
68
|
+
y: m.value,
|
|
69
|
+
color: c,
|
|
70
|
+
"rounded-corners": e.radius ?? 0,
|
|
71
|
+
"group-padding": e.groupPadding ?? 0,
|
|
72
|
+
"bar-padding": e.barPadding ?? 0.2,
|
|
73
|
+
orientation: e.orientation ?? i(s).Vertical
|
|
74
|
+
}, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])) : (d(), f(i(C), {
|
|
75
|
+
key: 0,
|
|
76
|
+
data: e.data,
|
|
77
|
+
x: (l, o) => o,
|
|
78
|
+
y: m.value,
|
|
79
|
+
color: c,
|
|
80
|
+
"rounded-corners": e.radius ?? 0,
|
|
81
|
+
"group-padding": e.groupPadding ?? 0,
|
|
82
|
+
"bar-padding": e.barPadding ?? 0.2,
|
|
83
|
+
orientation: e.orientation ?? i(s).Vertical
|
|
84
|
+
}, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])),
|
|
85
|
+
t(i(L), {
|
|
86
|
+
type: "x",
|
|
87
|
+
"tick-format": e.xFormatter,
|
|
88
|
+
label: e.xLabel,
|
|
89
|
+
"grid-line": e.xGridLine,
|
|
90
|
+
"domain-line": e.xDomainLine,
|
|
91
|
+
"tick-line": e.xTickLine,
|
|
92
|
+
"num-ticks": e.xNumTicks,
|
|
93
|
+
"tick-values": e.xExplicitTicks,
|
|
94
|
+
"min-max-ticks-only": e.minMaxTicksOnly
|
|
95
|
+
}, null, 8, ["tick-format", "label", "grid-line", "domain-line", "tick-line", "num-ticks", "tick-values", "min-max-ticks-only"]),
|
|
96
|
+
t(i(L), {
|
|
97
|
+
type: "y",
|
|
98
|
+
label: e.yLabel,
|
|
99
|
+
"grid-line": e.orientation !== i(s).Horizontal && e.yGridLine,
|
|
100
|
+
"domain-line": e.yDomainLine,
|
|
101
|
+
"tick-format": e.yFormatter,
|
|
102
|
+
"num-ticks": e.yNumTicks,
|
|
103
|
+
"tick-line": e.yTickLine
|
|
104
|
+
}, null, 8, ["label", "grid-line", "domain-line", "tick-format", "num-ticks", "tick-line"])
|
|
105
|
+
]),
|
|
106
|
+
_: 1
|
|
107
|
+
}, 8, ["height"]),
|
|
108
|
+
e.hideLegend ? B("", !0) : (d(), y("div", {
|
|
109
|
+
key: 0,
|
|
110
|
+
class: k(["flex items center justify-end", { "pb-4": p.value }])
|
|
111
|
+
}, [
|
|
112
|
+
t(i(N), {
|
|
113
|
+
items: Object.values(e.categories)
|
|
114
|
+
}, null, 8, ["items"])
|
|
115
|
+
], 2))
|
|
116
|
+
], 2));
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
export {
|
|
120
|
+
M as default
|
|
121
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BarChartProps } from './types';
|
|
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> & BarChartProps<T> & Partial<{}>> & import('vue').PublicProps;
|
|
4
|
+
expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
|
|
5
|
+
attrs: any;
|
|
6
|
+
slots: {};
|
|
7
|
+
emit: {};
|
|
8
|
+
}>) => import('vue').VNode & {
|
|
9
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
12
|
+
type __VLS_PrettifyLocal<T> = {
|
|
13
|
+
[K in keyof T]: T[K];
|
|
14
|
+
} & {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { BulletLegendItemInterface, Orientation, LegendPosition } from '../../types';
|
|
2
|
+
export interface BarChartProps<T> {
|
|
3
|
+
/**
|
|
4
|
+
* The data to be displayed in the bar chart.
|
|
5
|
+
* Each element of the array represents a data point.
|
|
6
|
+
* The structure of 'T' should be compatible with the chart's rendering logic.
|
|
7
|
+
*/
|
|
8
|
+
data: T[];
|
|
9
|
+
/**
|
|
10
|
+
* If `true`, creates a stacked bar chart instead of grouped bars.
|
|
11
|
+
*/
|
|
12
|
+
stacked?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The height of the chart in pixels.
|
|
15
|
+
*/
|
|
16
|
+
height: number;
|
|
17
|
+
/**
|
|
18
|
+
* Optional label for the x-axis.
|
|
19
|
+
*/
|
|
20
|
+
xLabel?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Optional label for the y-axis.
|
|
23
|
+
*/
|
|
24
|
+
yLabel?: string;
|
|
25
|
+
/**
|
|
26
|
+
* A record mapping category keys to `BulletLegendItemInterface` objects.
|
|
27
|
+
* This defines the visual representation and labels for each category in the chart's legend.
|
|
28
|
+
*/
|
|
29
|
+
categories: Record<string, BulletLegendItemInterface>;
|
|
30
|
+
/**
|
|
31
|
+
* A function that formats the x-axis tick labels.
|
|
32
|
+
* @param i The x-axis key of the item to be formatted.
|
|
33
|
+
* @param idx The index of the data point.
|
|
34
|
+
* @returns The formatted x-axis label.
|
|
35
|
+
*/
|
|
36
|
+
xFormatter: (i: number, idx: number) => string | number;
|
|
37
|
+
/**
|
|
38
|
+
* An optional function that formats the y-axis tick labels.
|
|
39
|
+
* @param i The y-axis key of the item to be formatted.
|
|
40
|
+
* @param idx The index of the data point (optional).
|
|
41
|
+
* @returns The formatted y-axis label or value.
|
|
42
|
+
*/
|
|
43
|
+
yFormatter?: (i: number, idx?: number) => string | number;
|
|
44
|
+
/**
|
|
45
|
+
* The desired number of ticks on the y-axis.
|
|
46
|
+
*/
|
|
47
|
+
yNumTicks?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Force only first and last ticks on the x-axis.
|
|
50
|
+
*/
|
|
51
|
+
minMaxTicksOnly?: number;
|
|
52
|
+
/**
|
|
53
|
+
* The desired number of ticks on the x-axis.
|
|
54
|
+
*/
|
|
55
|
+
xNumTicks?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Force specific ticks on the x-axis.
|
|
58
|
+
*/
|
|
59
|
+
xExplicitTicks?: number;
|
|
60
|
+
/**
|
|
61
|
+
* An array of property keys from the data object type 'T' to be used for the y-axis values.
|
|
62
|
+
*/
|
|
63
|
+
yAxis: (keyof T)[];
|
|
64
|
+
/**
|
|
65
|
+
* The padding between groups of bars in pixels.
|
|
66
|
+
*/
|
|
67
|
+
groupPadding?: number;
|
|
68
|
+
/**
|
|
69
|
+
* The padding between bars within the same group in pixels.
|
|
70
|
+
*/
|
|
71
|
+
barPadding?: number;
|
|
72
|
+
/**
|
|
73
|
+
* The corner radius of the bars in pixels.
|
|
74
|
+
*/
|
|
75
|
+
radius?: number;
|
|
76
|
+
/**
|
|
77
|
+
* If `true`, hides the chart legend.
|
|
78
|
+
*/
|
|
79
|
+
hideLegend?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* The orientation of the bars (vertical or horizontal).
|
|
82
|
+
* See `Orientation` for available options.
|
|
83
|
+
*/
|
|
84
|
+
orientation?: Orientation;
|
|
85
|
+
/**
|
|
86
|
+
* Optional position for the legend, if applicable.
|
|
87
|
+
* See `LegendPosition` for available options.
|
|
88
|
+
*/
|
|
89
|
+
legendPosition?: LegendPosition;
|
|
90
|
+
/**
|
|
91
|
+
* If `true`, displays a domain line (axis line) along the x-axis.
|
|
92
|
+
*/
|
|
93
|
+
xDomainLine?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* If `true`, displays a domain line (axis line) along the y-axis.
|
|
96
|
+
*/
|
|
97
|
+
yDomainLine?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* If `true`, displays tick lines on the x-axis.
|
|
100
|
+
*/
|
|
101
|
+
xTickLine?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* If `true`, displays tick lines on the y-axis.
|
|
104
|
+
*/
|
|
105
|
+
yTickLine?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* If `true`, displays grid lines along the x-axis.
|
|
108
|
+
*/
|
|
109
|
+
xGridLine?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* If `true`, displays grid lines along the y-axis.
|
|
112
|
+
*/
|
|
113
|
+
yGridLine?: boolean;
|
|
114
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { defineComponent as u, createElementBlock as n, openBlock as i, Fragment as m, createElementVNode as f, createCommentVNode as p, createVNode as t, renderSlot as g, unref as o, withCtx as h } from "vue";
|
|
2
|
+
import { Donut as v } from "@unovis/ts";
|
|
3
|
+
import { VisSingleContainer as y, VisTooltip as V, VisDonut as b, VisBulletLegend as C } from "@unovis/vue";
|
|
4
|
+
import { DonutType as _ } from "./types.js";
|
|
5
|
+
const k = { class: "flex items-center justify-center" }, B = {
|
|
6
|
+
key: 0,
|
|
7
|
+
class: "flex items-center justify-center mt-4"
|
|
8
|
+
}, w = /* @__PURE__ */ u({
|
|
9
|
+
__name: "DonutChart",
|
|
10
|
+
props: {
|
|
11
|
+
type: {},
|
|
12
|
+
data: {},
|
|
13
|
+
height: {},
|
|
14
|
+
radius: {},
|
|
15
|
+
hideLegend: { type: Boolean },
|
|
16
|
+
labels: {}
|
|
17
|
+
},
|
|
18
|
+
setup(l) {
|
|
19
|
+
const r = l, s = (e) => e, a = r.type === _.Half, d = {
|
|
20
|
+
[v.selectors.segment]: (e) => `<div class='flex items-center'><div class='w-2 h-2 rounded-full mr-2' style='background-color: ${r.labels[e.index].color} ;'></div>
|
|
21
|
+
<div>${e.data}</div>
|
|
22
|
+
</vistooltip>
|
|
23
|
+
</vissinglecontainer>
|
|
24
|
+
</div>`
|
|
25
|
+
};
|
|
26
|
+
return (e, D) => (i(), n(m, null, [
|
|
27
|
+
f("div", k, [
|
|
28
|
+
t(o(y), {
|
|
29
|
+
data: e.data,
|
|
30
|
+
height: e.height,
|
|
31
|
+
margin: {}
|
|
32
|
+
}, {
|
|
33
|
+
default: h(() => [
|
|
34
|
+
t(o(V), {
|
|
35
|
+
"horizontal-shift": 20,
|
|
36
|
+
"vertical-shift": 20,
|
|
37
|
+
triggers: d
|
|
38
|
+
}),
|
|
39
|
+
t(o(b), {
|
|
40
|
+
value: s,
|
|
41
|
+
"corner-radius": e.radius,
|
|
42
|
+
color: r.labels.map((c) => c.color),
|
|
43
|
+
"angle-range": a ? [-1.5707963267948966, 1.5707963267948966] : []
|
|
44
|
+
}, null, 8, ["corner-radius", "color", "angle-range"])
|
|
45
|
+
]),
|
|
46
|
+
_: 1
|
|
47
|
+
}, 8, ["data", "height"]),
|
|
48
|
+
g(e.$slots, "default")
|
|
49
|
+
]),
|
|
50
|
+
e.hideLegend ? p("", !0) : (i(), n("div", B, [
|
|
51
|
+
t(o(C), { items: e.labels }, null, 8, ["items"])
|
|
52
|
+
]))
|
|
53
|
+
], 64));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
export {
|
|
57
|
+
w as default
|
|
58
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DonutChartProps } from './types';
|
|
2
|
+
declare function __VLS_template(): {
|
|
3
|
+
attrs: Partial<{}>;
|
|
4
|
+
slots: {
|
|
5
|
+
default?(_: {}): any;
|
|
6
|
+
};
|
|
7
|
+
refs: {};
|
|
8
|
+
rootEl: any;
|
|
9
|
+
};
|
|
10
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
11
|
+
declare const __VLS_component: import('vue').DefineComponent<DonutChartProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<DonutChartProps> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
12
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
13
|
+
export default _default;
|
|
14
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
15
|
+
new (): {
|
|
16
|
+
$slots: S;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
interface DonutChartProps {
|
|
2
|
+
/**
|
|
3
|
+
* The type of donut chart to render.
|
|
4
|
+
* See `DonutType` for available options.
|
|
5
|
+
*/
|
|
6
|
+
type?: string;
|
|
7
|
+
/**
|
|
8
|
+
* The data to be displayed in the donut chart.
|
|
9
|
+
* Each number in the array represents a segment value.
|
|
10
|
+
*/
|
|
11
|
+
data: number[];
|
|
12
|
+
/**
|
|
13
|
+
* The height of the chart in pixels.
|
|
14
|
+
*/
|
|
15
|
+
height: number;
|
|
16
|
+
/**
|
|
17
|
+
* The radius of the donut in pixels.
|
|
18
|
+
*/
|
|
19
|
+
radius: number;
|
|
20
|
+
/**
|
|
21
|
+
* If `true`, hides the chart legend.
|
|
22
|
+
*/
|
|
23
|
+
hideLegend?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* An array of label objects defining the name and color for each segment.
|
|
26
|
+
*/
|
|
27
|
+
labels: {
|
|
28
|
+
name: string;
|
|
29
|
+
color: string;
|
|
30
|
+
}[];
|
|
31
|
+
}
|
|
32
|
+
declare enum DonutType {
|
|
33
|
+
Half = "half",
|
|
34
|
+
Full = "full"
|
|
35
|
+
}
|
|
36
|
+
export { type DonutChartProps, DonutType };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { defineComponent as v, computed as u, createApp as b, createElementBlock as m, openBlock as n, normalizeClass as p, createVNode as o, createCommentVNode as y, unref as i, withCtx as B, createBlock as k, Fragment as x, renderList as C } from "vue";
|
|
2
|
+
import { Position as g, CurveType as V } from "@unovis/ts";
|
|
3
|
+
import { VisXYContainer as N, VisTooltip as F, VisLine as O, VisAxis as f, VisCrosshair as P, VisBulletLegend as j } from "@unovis/vue";
|
|
4
|
+
import D from "../Tooltip.js";
|
|
5
|
+
import { LegendPosition as E } from "../../types.js";
|
|
6
|
+
const X = /* @__PURE__ */ v({
|
|
7
|
+
__name: "LineChart",
|
|
8
|
+
props: {
|
|
9
|
+
data: {},
|
|
10
|
+
height: {},
|
|
11
|
+
xLabel: {},
|
|
12
|
+
yLabel: {},
|
|
13
|
+
categories: {},
|
|
14
|
+
xFormatter: {},
|
|
15
|
+
yFormatter: {},
|
|
16
|
+
curveType: {},
|
|
17
|
+
xNumTicks: { default: (t) => t.data.length > 24 ? 24 / 4 : t.data.length - 1 },
|
|
18
|
+
xExplicitTicks: {},
|
|
19
|
+
minMaxTicksOnly: {},
|
|
20
|
+
yNumTicks: { default: (t) => t.data.length > 24 ? 24 / 4 : t.data.length - 1 },
|
|
21
|
+
hideTooltip: { type: Boolean },
|
|
22
|
+
hideLegend: { type: Boolean },
|
|
23
|
+
legendPosition: {},
|
|
24
|
+
xGridLine: { type: Boolean },
|
|
25
|
+
xDomainLine: { type: Boolean },
|
|
26
|
+
yGridLine: { type: Boolean },
|
|
27
|
+
yDomainLine: { type: Boolean },
|
|
28
|
+
xTickLine: { type: Boolean },
|
|
29
|
+
yTickLine: { type: Boolean }
|
|
30
|
+
},
|
|
31
|
+
setup(t) {
|
|
32
|
+
const l = t, h = (e) => Object.values(l.categories)[e].color, L = u(() => (e) => {
|
|
33
|
+
if (typeof window > "u" || typeof document > "u")
|
|
34
|
+
return "";
|
|
35
|
+
try {
|
|
36
|
+
const a = b(D, {
|
|
37
|
+
data: e,
|
|
38
|
+
categories: l.categories
|
|
39
|
+
}), r = document.createElement("div");
|
|
40
|
+
a.mount(r);
|
|
41
|
+
const c = r.innerHTML;
|
|
42
|
+
return a.unmount(), c;
|
|
43
|
+
} catch {
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
}), s = u(
|
|
47
|
+
() => l.legendPosition === E.Top
|
|
48
|
+
);
|
|
49
|
+
return (e, a) => (n(), m("div", {
|
|
50
|
+
class: p(["flex flex-col space-y-4", { "flex-col-reverse": s.value }])
|
|
51
|
+
}, [
|
|
52
|
+
o(i(N), {
|
|
53
|
+
data: e.data,
|
|
54
|
+
height: e.height
|
|
55
|
+
}, {
|
|
56
|
+
default: B(() => [
|
|
57
|
+
o(i(F), {
|
|
58
|
+
"horizontal-placement": i(g).Right,
|
|
59
|
+
"vertical-placement": i(g).Top
|
|
60
|
+
}, null, 8, ["horizontal-placement", "vertical-placement"]),
|
|
61
|
+
(n(!0), m(x, null, C(Object.keys(l.categories), (r, c) => (n(), k(i(O), {
|
|
62
|
+
key: c,
|
|
63
|
+
x: (d, T) => T,
|
|
64
|
+
y: (d) => d[r],
|
|
65
|
+
color: h(c),
|
|
66
|
+
"curve-type": e.curveType ?? i(V).MonotoneX
|
|
67
|
+
}, null, 8, ["x", "y", "color", "curve-type"]))), 128)),
|
|
68
|
+
o(i(f), {
|
|
69
|
+
type: "x",
|
|
70
|
+
"tick-format": e.xFormatter,
|
|
71
|
+
label: e.xLabel,
|
|
72
|
+
"label-margin": 8,
|
|
73
|
+
"domain-line": e.xDomainLine,
|
|
74
|
+
"grid-line": e.xGridLine,
|
|
75
|
+
"tick-line": e.xTickLine,
|
|
76
|
+
"num-ticks": e.xNumTicks,
|
|
77
|
+
"tick-values": e.xExplicitTicks,
|
|
78
|
+
"min-max-ticks-only": e.minMaxTicksOnly
|
|
79
|
+
}, null, 8, ["tick-format", "label", "domain-line", "grid-line", "tick-line", "num-ticks", "tick-values", "min-max-ticks-only"]),
|
|
80
|
+
o(i(f), {
|
|
81
|
+
type: "y",
|
|
82
|
+
"tick-format": e.yFormatter,
|
|
83
|
+
label: e.yLabel,
|
|
84
|
+
"num-ticks": e.yNumTicks,
|
|
85
|
+
"domain-line": e.yDomainLine,
|
|
86
|
+
"grid-line": e.yGridLine,
|
|
87
|
+
"tick-line": e.yTickLine
|
|
88
|
+
}, null, 8, ["tick-format", "label", "num-ticks", "domain-line", "grid-line", "tick-line"]),
|
|
89
|
+
e.hideTooltip ? y("", !0) : (n(), k(i(P), {
|
|
90
|
+
key: 0,
|
|
91
|
+
color: "#666",
|
|
92
|
+
template: L.value
|
|
93
|
+
}, null, 8, ["template"]))
|
|
94
|
+
]),
|
|
95
|
+
_: 1
|
|
96
|
+
}, 8, ["data", "height"]),
|
|
97
|
+
e.hideLegend ? y("", !0) : (n(), m("div", {
|
|
98
|
+
key: 0,
|
|
99
|
+
class: p(["flex items center justify-end", { "pb-4": s.value }])
|
|
100
|
+
}, [
|
|
101
|
+
o(i(j), {
|
|
102
|
+
items: Object.values(e.categories)
|
|
103
|
+
}, null, 8, ["items"])
|
|
104
|
+
], 2))
|
|
105
|
+
], 2));
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
export {
|
|
109
|
+
X as default
|
|
110
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LineChartProps } from './types';
|
|
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;
|
|
4
|
+
expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
|
|
5
|
+
attrs: any;
|
|
6
|
+
slots: {};
|
|
7
|
+
emit: {};
|
|
8
|
+
}>) => import('vue').VNode & {
|
|
9
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
12
|
+
type __VLS_PrettifyLocal<T> = {
|
|
13
|
+
[K in keyof T]: T[K];
|
|
14
|
+
} & {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { BulletLegendItemInterface, CurveType, LegendPosition } from '../../types';
|
|
2
|
+
export interface LineChartProps<T> {
|
|
3
|
+
/**
|
|
4
|
+
* The data to be displayed in the line chart.
|
|
5
|
+
* Each element of the array represents a data point.
|
|
6
|
+
* The structure of 'T' should be compatible with the chart's rendering logic.
|
|
7
|
+
*/
|
|
8
|
+
data: T[];
|
|
9
|
+
/**
|
|
10
|
+
* The height of the chart in pixels.
|
|
11
|
+
*/
|
|
12
|
+
height: number;
|
|
13
|
+
/**
|
|
14
|
+
* Optional label for the x-axis.
|
|
15
|
+
*/
|
|
16
|
+
xLabel?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Optional label for the y-axis.
|
|
19
|
+
*/
|
|
20
|
+
yLabel?: string;
|
|
21
|
+
/**
|
|
22
|
+
* A record mapping category keys to `BulletLegendItemInterface` objects.
|
|
23
|
+
* This defines the visual representation and labels for each category in the chart's legend.
|
|
24
|
+
*/
|
|
25
|
+
categories: Record<string, BulletLegendItemInterface>;
|
|
26
|
+
/**
|
|
27
|
+
* A function that formats the x-axis tick labels.
|
|
28
|
+
* @param i The x-axis key of the item to be formatted.
|
|
29
|
+
* @param idx The index of the data point.
|
|
30
|
+
* @returns The formatted x-axis label.
|
|
31
|
+
*/
|
|
32
|
+
xFormatter: (i: number, idx: number) => string | number;
|
|
33
|
+
/**
|
|
34
|
+
* An optional function that formats the y-axis tick labels.
|
|
35
|
+
* @param i The y-axis key of the item to be formatted.
|
|
36
|
+
* @param idx The index of the data point.
|
|
37
|
+
* @returns The formatted y-axis label.
|
|
38
|
+
*/
|
|
39
|
+
yFormatter?: (i: number, idx: number) => string;
|
|
40
|
+
/**
|
|
41
|
+
* The type of curve to use for the line chart.
|
|
42
|
+
* See `CurveType` for available options.
|
|
43
|
+
*/
|
|
44
|
+
curveType?: CurveType;
|
|
45
|
+
/**
|
|
46
|
+
* The desired number of ticks on the x-axis.
|
|
47
|
+
*/
|
|
48
|
+
xNumTicks?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Force specific ticks on the x-axis.
|
|
51
|
+
*/
|
|
52
|
+
xExplicitTicks?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Force only first and last ticks on the x-axis.
|
|
55
|
+
*/
|
|
56
|
+
minMaxTicksOnly?: number;
|
|
57
|
+
/**
|
|
58
|
+
* The desired number of ticks on the y-axis.
|
|
59
|
+
*/
|
|
60
|
+
yNumTicks?: number;
|
|
61
|
+
/**
|
|
62
|
+
* If `true`, hides the chart tooltip.
|
|
63
|
+
*/
|
|
64
|
+
hideTooltip?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* If `true`, hides the chart legend.
|
|
67
|
+
*/
|
|
68
|
+
hideLegend?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Optional position for the legend, if applicable.
|
|
71
|
+
* See `LegendPosition` for available options.
|
|
72
|
+
*/
|
|
73
|
+
legendPosition?: LegendPosition;
|
|
74
|
+
/**
|
|
75
|
+
* If `true`, displays grid lines along the x-axis.
|
|
76
|
+
*/
|
|
77
|
+
xGridLine?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* If `true`, displays a domain line (axis line) along the x-axis.
|
|
80
|
+
*/
|
|
81
|
+
xDomainLine?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* If `true`, displays grid lines along the y-axis.
|
|
84
|
+
*/
|
|
85
|
+
yGridLine?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* If `true`, displays a domain line (axis line) along the y-axis.
|
|
88
|
+
*/
|
|
89
|
+
yDomainLine?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* If `true`, displays tick lines on the x-axis.
|
|
92
|
+
*/
|
|
93
|
+
xTickLine?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* If `true`, displays tick lines on the y-axis.
|
|
96
|
+
*/
|
|
97
|
+
yTickLine?: boolean;
|
|
98
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineComponent as g, computed as m, createElementBlock as r, openBlock as l, Fragment as x, renderList as _, createElementVNode as o, normalizeStyle as n, toDisplayString as a } from "vue";
|
|
2
|
+
const h = /* @__PURE__ */ g({
|
|
3
|
+
__name: "Tooltip",
|
|
4
|
+
props: {
|
|
5
|
+
data: {},
|
|
6
|
+
categories: {}
|
|
7
|
+
},
|
|
8
|
+
setup(s) {
|
|
9
|
+
const i = s, c = ["_index", "_stacked", "_ending"], p = m(() => Object.entries(i.data ?? []).filter(
|
|
10
|
+
([t, d]) => {
|
|
11
|
+
var e;
|
|
12
|
+
return !c.includes(t) && ((e = i.categories[t]) == null ? void 0 : e.color);
|
|
13
|
+
}
|
|
14
|
+
));
|
|
15
|
+
return (t, d) => (l(), r("div", null, [
|
|
16
|
+
(l(!0), r(x, null, _(p.value, ([e, u]) => (l(), r("div", {
|
|
17
|
+
key: e,
|
|
18
|
+
style: { display: "flex", "align-items": "center", "margin-bottom": "4px" }
|
|
19
|
+
}, [
|
|
20
|
+
o("span", {
|
|
21
|
+
style: n([{ width: "8px", height: "8px", "border-radius": "4px", "margin-right": "8px" }, { backgroundColor: t.categories[e].color }])
|
|
22
|
+
}, null, 4),
|
|
23
|
+
o("div", null, [
|
|
24
|
+
o("span", {
|
|
25
|
+
style: n([{ "font-weight": "600", "margin-right": "8px" }, { color: "var(--tooltip-label-color)" }])
|
|
26
|
+
}, a(e) + ":", 1),
|
|
27
|
+
o("span", {
|
|
28
|
+
style: n([{ "font-weight": "400" }, { color: "var(--tooltip-value-color)" }])
|
|
29
|
+
}, a(u), 1)
|
|
30
|
+
])
|
|
31
|
+
]))), 128))
|
|
32
|
+
]));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
export {
|
|
36
|
+
h as default
|
|
37
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BulletLegendItemInterface } from '@unovis/ts';
|
|
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> & {
|
|
4
|
+
data: T;
|
|
5
|
+
categories: Record<string, BulletLegendItemInterface>;
|
|
6
|
+
} & Partial<{}>> & import('vue').PublicProps;
|
|
7
|
+
expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
|
|
8
|
+
attrs: any;
|
|
9
|
+
slots: {};
|
|
10
|
+
emit: {};
|
|
11
|
+
}>) => import('vue').VNode & {
|
|
12
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
|
15
|
+
type __VLS_PrettifyLocal<T> = {
|
|
16
|
+
[K in keyof T]: T[K];
|
|
17
|
+
} & {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as AreaChart } from './components/AreaChart/AreaChart.vue';
|
|
2
|
+
import { default as AreaStackedChart } from './components/AreaStackedChart/AreaStackedChart.vue';
|
|
3
|
+
import { default as LineChart } from './components/LineChart/LineChart.vue';
|
|
4
|
+
import { default as BarChart } from './components/BarChart/BarChart.vue';
|
|
5
|
+
import { default as DonutChart } from './components/DonutChart/DonutChart.vue';
|
|
6
|
+
import { LegendPosition, CurveType, Orientation, BulletLegendItemInterface } from './types';
|
|
7
|
+
export { AreaChart, AreaStackedChart, LineChart, BarChart, DonutChart, Orientation, CurveType, LegendPosition };
|
|
8
|
+
export type { BulletLegendItemInterface, };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { default as a } from "./components/AreaChart/AreaChart.js";
|
|
2
|
+
import { default as o } from "./components/AreaStackedChart/AreaStackedChart.js";
|
|
3
|
+
import { default as d } from "./components/LineChart/LineChart.js";
|
|
4
|
+
import { default as u } from "./components/BarChart/BarChart.js";
|
|
5
|
+
import { default as n } from "./components/DonutChart/DonutChart.js";
|
|
6
|
+
import { CurveType as x, LegendPosition as C, Orientation as h } from "./types.js";
|
|
7
|
+
export {
|
|
8
|
+
a as AreaChart,
|
|
9
|
+
o as AreaStackedChart,
|
|
10
|
+
u as BarChart,
|
|
11
|
+
x as CurveType,
|
|
12
|
+
n as DonutChart,
|
|
13
|
+
C as LegendPosition,
|
|
14
|
+
d as LineChart,
|
|
15
|
+
h as Orientation
|
|
16
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AreaChartProps } from './components/AreaChart/types';
|
|
2
|
+
import { BarChartProps } from './components/BarChart/types';
|
|
3
|
+
import { LineChartProps } from './components/LineChart/types';
|
|
4
|
+
import { DonutChartProps } from './components/DonutChart/types';
|
|
5
|
+
declare enum LegendPosition {
|
|
6
|
+
Top = "top",
|
|
7
|
+
Bottom = "bottom"
|
|
8
|
+
}
|
|
9
|
+
declare enum CurveType {
|
|
10
|
+
Basis = "basis",
|
|
11
|
+
BasisClosed = "basisClosed",
|
|
12
|
+
BasisOpen = "basisOpen",
|
|
13
|
+
Bundle = "bundle",
|
|
14
|
+
Cardinal = "cardinal",
|
|
15
|
+
CardinalClosed = "cardinalClosed",
|
|
16
|
+
CardinalOpen = "cardinalOpen",
|
|
17
|
+
CatmullRom = "catmullRom",
|
|
18
|
+
CatmullRomClosed = "catmullRomClosed",
|
|
19
|
+
CatmullRomOpen = "catmullRomOpen",
|
|
20
|
+
Linear = "linear",
|
|
21
|
+
LinearClosed = "linearClosed",
|
|
22
|
+
MonotoneX = "monotoneX",
|
|
23
|
+
MonotoneY = "monotoneY",
|
|
24
|
+
Natural = "natural",
|
|
25
|
+
Step = "step",
|
|
26
|
+
StepAfter = "stepAfter",
|
|
27
|
+
StepBefore = "stepBefore"
|
|
28
|
+
}
|
|
29
|
+
interface BulletLegendItemInterface {
|
|
30
|
+
name: string | number;
|
|
31
|
+
color?: string;
|
|
32
|
+
className?: string;
|
|
33
|
+
shape?: any;
|
|
34
|
+
inactive?: boolean;
|
|
35
|
+
hidden?: boolean;
|
|
36
|
+
pointer?: boolean;
|
|
37
|
+
}
|
|
38
|
+
declare enum Orientation {
|
|
39
|
+
Horizontal = "horizontal",
|
|
40
|
+
Vertical = "vertical"
|
|
41
|
+
}
|
|
42
|
+
export { LegendPosition, CurveType, Orientation, type AreaChartProps, type BarChartProps, type LineChartProps, type DonutChartProps, type BulletLegendItemInterface, };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
var l = /* @__PURE__ */ ((a) => (a.Top = "top", a.Bottom = "bottom", a))(l || {}), o = /* @__PURE__ */ ((a) => (a.Basis = "basis", a.BasisClosed = "basisClosed", a.BasisOpen = "basisOpen", a.Bundle = "bundle", a.Cardinal = "cardinal", a.CardinalClosed = "cardinalClosed", a.CardinalOpen = "cardinalOpen", a.CatmullRom = "catmullRom", a.CatmullRomClosed = "catmullRomClosed", a.CatmullRomOpen = "catmullRomOpen", a.Linear = "linear", a.LinearClosed = "linearClosed", a.MonotoneX = "monotoneX", a.MonotoneY = "monotoneY", a.Natural = "natural", a.Step = "step", a.StepAfter = "stepAfter", a.StepBefore = "stepBefore", a))(o || {}), t = /* @__PURE__ */ ((a) => (a.Horizontal = "horizontal", a.Vertical = "vertical", a))(t || {});
|
|
2
|
+
export {
|
|
3
|
+
o as CurveType,
|
|
4
|
+
l as LegendPosition,
|
|
5
|
+
t as Orientation
|
|
6
|
+
};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDistributedIndices(length: number, numTicks: number): number[];
|