@katlux/block-charts 0.1.0-beta.1 → 0.1.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.
- package/dist/module.d.mts +6 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +19 -14
- package/dist/runtime/components/KAreaChart/KAreaChart.d.vue.ts +53 -0
- package/dist/runtime/components/KAreaChart/KAreaChart.vue +382 -0
- package/dist/runtime/components/KAreaChart/KAreaChart.vue.d.ts +53 -0
- package/dist/runtime/components/KBarChart/KBarChart.d.vue.ts +55 -0
- package/dist/runtime/components/KBarChart/KBarChart.vue +398 -0
- package/dist/runtime/components/KBarChart/KBarChart.vue.d.ts +55 -0
- package/dist/runtime/components/KHeatMap/KHeatMap.d.vue.ts +36 -0
- package/dist/runtime/components/KHeatMap/KHeatMap.vue +263 -0
- package/dist/runtime/components/KHeatMap/KHeatMap.vue.d.ts +36 -0
- package/dist/runtime/components/KLineChart/KLineChart.d.vue.ts +51 -0
- package/dist/runtime/components/KLineChart/KLineChart.vue +407 -0
- package/dist/runtime/components/KLineChart/KLineChart.vue.d.ts +51 -0
- package/dist/runtime/components/KPieChart/KPieChart.d.vue.ts +32 -0
- package/dist/runtime/components/KPieChart/KPieChart.vue +273 -0
- package/dist/runtime/components/KPieChart/KPieChart.vue.d.ts +32 -0
- package/dist/runtime/components/KScatterChart/KScatterChart.d.vue.ts +55 -0
- package/dist/runtime/components/KScatterChart/KScatterChart.vue +356 -0
- package/dist/runtime/components/KScatterChart/KScatterChart.vue.d.ts +55 -0
- package/dist/runtime/composables/useChartAnimation.d.ts +9 -0
- package/dist/runtime/composables/useChartAnimation.js +32 -0
- package/dist/runtime/composables/useChartAxes.d.ts +40 -0
- package/dist/runtime/composables/useChartAxes.js +58 -0
- package/dist/runtime/composables/useChartCanvas.d.ts +11 -0
- package/dist/runtime/composables/useChartCanvas.js +47 -0
- package/dist/runtime/composables/useChartData.d.ts +14 -0
- package/dist/runtime/composables/useChartData.js +45 -0
- package/dist/runtime/composables/useChartExport.d.ts +5 -0
- package/dist/runtime/composables/useChartExport.js +32 -0
- package/dist/runtime/composables/useChartHitTest.d.ts +11 -0
- package/dist/runtime/composables/useChartHitTest.js +39 -0
- package/dist/runtime/composables/useChartSvg.d.ts +17 -0
- package/dist/runtime/composables/useChartSvg.js +22 -0
- package/dist/runtime/composables/useChartViewport.d.ts +25 -0
- package/dist/runtime/composables/useChartViewport.js +92 -0
- package/dist/types.d.mts +2 -12
- package/package.json +3 -2
- package/dist/module.d.cts +0 -2
package/dist/module.d.mts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface ModuleOptions {
|
|
2
|
+
}
|
|
3
|
+
declare const _default: any;
|
|
4
|
+
|
|
5
|
+
export { _default as default };
|
|
6
|
+
export type { ModuleOptions };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineNuxtModule, createResolver, addComponentsDir } from '@nuxt/kit';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"babel": {
|
|
10
|
-
"plugins": []
|
|
3
|
+
const module$1 = defineNuxtModule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "@katlux/block-charts",
|
|
6
|
+
configKey: "katluxCharts",
|
|
7
|
+
compatibility: {
|
|
8
|
+
nuxt: "^3.0.0"
|
|
11
9
|
}
|
|
10
|
+
},
|
|
11
|
+
defaults: {},
|
|
12
|
+
async setup(options, nuxt) {
|
|
13
|
+
const resolver = createResolver(import.meta.url);
|
|
14
|
+
addComponentsDir({
|
|
15
|
+
path: resolver.resolve("./runtime/components"),
|
|
16
|
+
pathPrefix: false,
|
|
17
|
+
prefix: "",
|
|
18
|
+
global: true
|
|
19
|
+
});
|
|
12
20
|
}
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
/** @type {import("/home/cagatay/Desktop/projects/KatluxShowcase/packages/katlux-block-charts/src/module")} */
|
|
16
|
-
const _module = await jiti.import("/home/cagatay/Desktop/projects/KatluxShowcase/packages/katlux-block-charts/src/module.ts");
|
|
21
|
+
});
|
|
17
22
|
|
|
18
|
-
export
|
|
23
|
+
export { module$1 as default };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
dataProvider?: any;
|
|
3
|
+
xField?: string;
|
|
4
|
+
yField?: string;
|
|
5
|
+
seriesField?: string;
|
|
6
|
+
animated?: boolean;
|
|
7
|
+
zoomable?: boolean;
|
|
8
|
+
maxZoom?: number;
|
|
9
|
+
stacked?: boolean;
|
|
10
|
+
colors?: string[];
|
|
11
|
+
backgroundColor?: string;
|
|
12
|
+
showLegend?: boolean;
|
|
13
|
+
xAxisTitle?: string;
|
|
14
|
+
yAxisTitle?: string;
|
|
15
|
+
};
|
|
16
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
17
|
+
zoomIn: () => void;
|
|
18
|
+
zoomOut: () => void;
|
|
19
|
+
resetZoom: () => void;
|
|
20
|
+
exportPng: () => void | null;
|
|
21
|
+
exportSvg: () => void | null;
|
|
22
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
23
|
+
"click-point": (item: any, index: number) => any;
|
|
24
|
+
"hover-point": (item: any, index: number) => any;
|
|
25
|
+
"zoom-change": (scale: number) => any;
|
|
26
|
+
"pan-change": (offset: {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
}) => any;
|
|
30
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
31
|
+
"onClick-point"?: ((item: any, index: number) => any) | undefined;
|
|
32
|
+
"onHover-point"?: ((item: any, index: number) => any) | undefined;
|
|
33
|
+
"onZoom-change"?: ((scale: number) => any) | undefined;
|
|
34
|
+
"onPan-change"?: ((offset: {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
}) => any) | undefined;
|
|
38
|
+
}>, {
|
|
39
|
+
xField: string;
|
|
40
|
+
yField: string;
|
|
41
|
+
seriesField: string;
|
|
42
|
+
animated: boolean;
|
|
43
|
+
zoomable: boolean;
|
|
44
|
+
maxZoom: number;
|
|
45
|
+
stacked: boolean;
|
|
46
|
+
colors: string[];
|
|
47
|
+
backgroundColor: string;
|
|
48
|
+
showLegend: boolean;
|
|
49
|
+
xAxisTitle: string;
|
|
50
|
+
yAxisTitle: string;
|
|
51
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
52
|
+
declare const _default: typeof __VLS_export;
|
|
53
|
+
export default _default;
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
<template lang="pug">
|
|
2
|
+
.k-chart-wrapper(
|
|
3
|
+
:class="{ 'k-chart--grabbing': isDragging, 'k-chart--pannable': canPan }"
|
|
4
|
+
:style="{ cursor: isDragging ? 'grabbing' : canPan ? 'grab' : 'default' }"
|
|
5
|
+
@wheel.prevent="onWheel"
|
|
6
|
+
@mousedown="onMouseDown"
|
|
7
|
+
@mousemove="onMouseMove"
|
|
8
|
+
@mouseup="onMouseUp"
|
|
9
|
+
@mouseleave="onMouseLeave"
|
|
10
|
+
)
|
|
11
|
+
.k-chart-controls(v-if="zoomable")
|
|
12
|
+
KButton(size="small" @click="zoomIn" title="Zoom In") +
|
|
13
|
+
KButton(size="small" @click="zoomOut" title="Zoom Out") −
|
|
14
|
+
KButton(size="small" @click="resetZoom" title="Reset Zoom") ↺
|
|
15
|
+
.k-chart-inner(ref="containerRef")
|
|
16
|
+
KLoader(:loading="isLoading" overlay)
|
|
17
|
+
canvas(ref="canvasRef" v-show="!isLoading")
|
|
18
|
+
svg.k-chart-svg(
|
|
19
|
+
v-show="!isLoading"
|
|
20
|
+
ref="svgRef"
|
|
21
|
+
:width="width"
|
|
22
|
+
:height="height"
|
|
23
|
+
)
|
|
24
|
+
defs
|
|
25
|
+
clipPath(id="plot-clip")
|
|
26
|
+
rect(
|
|
27
|
+
:x="axes.plotLeft"
|
|
28
|
+
:y="axes.plotTop"
|
|
29
|
+
:width="axes.plotWidth.value"
|
|
30
|
+
:height="axes.plotHeight.value"
|
|
31
|
+
)
|
|
32
|
+
g.k-chart-hits
|
|
33
|
+
// No more rect v-for here.
|
|
34
|
+
|
|
35
|
+
// Dynamic Interaction Layer
|
|
36
|
+
g.k-chart-interaction(v-if="hoveredIndex !== -1" clip-path="url(#plot-clip)")
|
|
37
|
+
circle.k-chart-hit-proxy(
|
|
38
|
+
v-for="(pt, i) in hoveredPoints"
|
|
39
|
+
:key="i"
|
|
40
|
+
:cx="pt.x"
|
|
41
|
+
:cy="pt.y"
|
|
42
|
+
:r="10"
|
|
43
|
+
fill="transparent"
|
|
44
|
+
style="cursor: pointer"
|
|
45
|
+
@click="emit('click-point', pt.item, pt.index)"
|
|
46
|
+
)
|
|
47
|
+
circle(
|
|
48
|
+
v-for="(pt, i) in hoveredPoints"
|
|
49
|
+
:key="'v' + i"
|
|
50
|
+
:cx="pt.x"
|
|
51
|
+
:cy="pt.y"
|
|
52
|
+
:r="5"
|
|
53
|
+
:fill="pt.color"
|
|
54
|
+
stroke="#fff"
|
|
55
|
+
stroke-width="2"
|
|
56
|
+
pointer-events="none"
|
|
57
|
+
)
|
|
58
|
+
.k-chart-tooltip(
|
|
59
|
+
v-if="tooltipState.visible && !isLoading"
|
|
60
|
+
:style="{ left: tooltipState.x + 'px', top: tooltipState.y + 'px' }"
|
|
61
|
+
)
|
|
62
|
+
slot(name="tooltip" :item="tooltipState.item" :index="tooltipState.index")
|
|
63
|
+
span {{ tooltipState.content }}
|
|
64
|
+
</template>
|
|
65
|
+
|
|
66
|
+
<script setup>
|
|
67
|
+
import { ref, watch, computed, onMounted, nextTick } from "vue";
|
|
68
|
+
import { useChartCanvas } from "../../composables/useChartCanvas";
|
|
69
|
+
import { useChartSvg } from "../../composables/useChartSvg";
|
|
70
|
+
import { useChartData } from "../../composables/useChartData";
|
|
71
|
+
import { useChartAxes, parseValue } from "../../composables/useChartAxes";
|
|
72
|
+
import { useChartViewport } from "../../composables/useChartViewport";
|
|
73
|
+
import { useChartAnimation, easeOut } from "../../composables/useChartAnimation";
|
|
74
|
+
import { useChartExport } from "../../composables/useChartExport";
|
|
75
|
+
import { useChartHitTest } from "../../composables/useChartHitTest";
|
|
76
|
+
const props = defineProps({
|
|
77
|
+
dataProvider: { type: null, required: false },
|
|
78
|
+
xField: { type: String, required: false, default: "x" },
|
|
79
|
+
yField: { type: String, required: false, default: "y" },
|
|
80
|
+
seriesField: { type: String, required: false, default: "series" },
|
|
81
|
+
animated: { type: Boolean, required: false, default: true },
|
|
82
|
+
zoomable: { type: Boolean, required: false, default: true },
|
|
83
|
+
maxZoom: { type: Number, required: false, default: 10 },
|
|
84
|
+
stacked: { type: Boolean, required: false, default: false },
|
|
85
|
+
colors: { type: Array, required: false, default: () => ["#6366f1", "#22d3ee", "#f59e0b", "#10b981", "#f43f5e", "#a855f7"] },
|
|
86
|
+
backgroundColor: { type: String, required: false, default: "#ffffff" },
|
|
87
|
+
showLegend: { type: Boolean, required: false, default: true },
|
|
88
|
+
xAxisTitle: { type: String, required: false, default: "" },
|
|
89
|
+
yAxisTitle: { type: String, required: false, default: "" }
|
|
90
|
+
});
|
|
91
|
+
const emit = defineEmits(["click-point", "hover-point", "zoom-change", "pan-change"]);
|
|
92
|
+
const containerRef = ref(null);
|
|
93
|
+
const canvasRef = ref(null);
|
|
94
|
+
const svgRef = ref(null);
|
|
95
|
+
const { ctx, width, height, clear, setupCanvas } = useChartCanvas();
|
|
96
|
+
const { hoveredIndex, tooltipState, showTooltip, hideTooltip, setHovered } = useChartSvg();
|
|
97
|
+
const dataRef = computed(() => props.dataProvider);
|
|
98
|
+
const { items } = useChartData(dataRef);
|
|
99
|
+
const { progress, animate } = useChartAnimation();
|
|
100
|
+
const { exportPng, exportSvg: exportSvgFile } = useChartExport();
|
|
101
|
+
const isLoading = computed(() => {
|
|
102
|
+
return props.dataProvider?.loading?.value || props.dataProvider?.initialLoad?.value || false;
|
|
103
|
+
});
|
|
104
|
+
const maxZoomRef = computed(() => props.maxZoom);
|
|
105
|
+
const plotWidthRef = computed(() => Math.max(0, width.value - 75));
|
|
106
|
+
const plotLeftRef = computed(() => 55);
|
|
107
|
+
const viewport = useChartViewport({ maxZoom: maxZoomRef, plotWidth: plotWidthRef, plotLeft: plotLeftRef });
|
|
108
|
+
const { findNearestX } = useChartHitTest();
|
|
109
|
+
const {
|
|
110
|
+
scale,
|
|
111
|
+
panOffset,
|
|
112
|
+
isDragging,
|
|
113
|
+
canPan,
|
|
114
|
+
zoomIn,
|
|
115
|
+
zoomOut,
|
|
116
|
+
resetZoom,
|
|
117
|
+
onWheel,
|
|
118
|
+
onMouseDown,
|
|
119
|
+
onMouseMove: onViewportMouseMove,
|
|
120
|
+
onMouseUp,
|
|
121
|
+
onMouseLeave: onViewportMouseLeave
|
|
122
|
+
} = viewport;
|
|
123
|
+
const xFieldRef = computed(() => props.xField);
|
|
124
|
+
const yFieldRef = computed(() => props.yField);
|
|
125
|
+
const seriesMap = computed(() => {
|
|
126
|
+
const map = /* @__PURE__ */ new Map();
|
|
127
|
+
for (const item of items.value) {
|
|
128
|
+
const key = String(item[props.seriesField] ?? "default");
|
|
129
|
+
if (!map.has(key)) map.set(key, []);
|
|
130
|
+
map.get(key).push(item);
|
|
131
|
+
}
|
|
132
|
+
return map;
|
|
133
|
+
});
|
|
134
|
+
const axes = useChartAxes({ items, xField: xFieldRef, yField: yFieldRef, width, height, scale, panOffset, padding: { top: 20, right: 20, bottom: 40, left: 55 } });
|
|
135
|
+
const draw = () => {
|
|
136
|
+
if (!ctx.value) return;
|
|
137
|
+
clear(props.backgroundColor);
|
|
138
|
+
const c = ctx.value;
|
|
139
|
+
const p = easeOut(progress.value);
|
|
140
|
+
c.save();
|
|
141
|
+
c.strokeStyle = "rgba(100,100,120,0.1)";
|
|
142
|
+
c.lineWidth = 1;
|
|
143
|
+
for (let i = 0; i <= 6; i++) {
|
|
144
|
+
const y = axes.plotTop + axes.plotHeight.value / 6 * i;
|
|
145
|
+
c.beginPath();
|
|
146
|
+
c.moveTo(axes.plotLeft, y);
|
|
147
|
+
c.lineTo(axes.plotLeft + axes.plotWidth.value, y);
|
|
148
|
+
c.stroke();
|
|
149
|
+
}
|
|
150
|
+
for (let i = 0; i <= 6; i++) {
|
|
151
|
+
const x = axes.plotLeft + axes.plotWidth.value / 6 * i;
|
|
152
|
+
c.beginPath();
|
|
153
|
+
c.moveTo(x, axes.plotTop);
|
|
154
|
+
c.lineTo(x, axes.plotTop + axes.plotHeight.value);
|
|
155
|
+
c.stroke();
|
|
156
|
+
}
|
|
157
|
+
c.restore();
|
|
158
|
+
c.save();
|
|
159
|
+
c.fillStyle = "rgba(150,150,170,0.8)";
|
|
160
|
+
c.font = "11px system-ui, sans-serif";
|
|
161
|
+
c.textAlign = "right";
|
|
162
|
+
for (let i = 0; i <= 5; i++) {
|
|
163
|
+
const val = axes.yMin.value + (axes.yMax.value - axes.yMin.value) * (i / 5);
|
|
164
|
+
c.fillText(val.toFixed(1), axes.plotLeft - 8, axes.toY(val) + 4);
|
|
165
|
+
}
|
|
166
|
+
c.textAlign = "center";
|
|
167
|
+
for (let i = 0; i <= 5; i++) {
|
|
168
|
+
const val = axes.xMin.value + (axes.xMax.value - axes.xMin.value) * (i / 5);
|
|
169
|
+
const x = axes.toX(val);
|
|
170
|
+
let label = val.toFixed(1);
|
|
171
|
+
if (val > 1e12) label = new Date(val).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
172
|
+
c.fillText(label, x, axes.plotTop + axes.plotHeight.value + 16);
|
|
173
|
+
}
|
|
174
|
+
c.beginPath();
|
|
175
|
+
c.moveTo(axes.plotLeft, axes.plotTop);
|
|
176
|
+
c.lineTo(axes.plotLeft, axes.plotTop + axes.plotHeight.value);
|
|
177
|
+
c.stroke();
|
|
178
|
+
if (props.xAxisTitle) {
|
|
179
|
+
c.fillStyle = "rgba(120,120,140,0.8)";
|
|
180
|
+
c.textAlign = "center";
|
|
181
|
+
c.fillText(props.xAxisTitle, axes.plotLeft + axes.plotWidth.value / 2, axes.plotTop + axes.plotHeight.value + 34);
|
|
182
|
+
}
|
|
183
|
+
if (props.yAxisTitle) {
|
|
184
|
+
c.save();
|
|
185
|
+
c.fillStyle = "rgba(120,120,140,0.8)";
|
|
186
|
+
c.translate(axes.plotLeft - 40, axes.plotTop + axes.plotHeight.value / 2);
|
|
187
|
+
c.rotate(-Math.PI / 2);
|
|
188
|
+
c.textAlign = "center";
|
|
189
|
+
c.fillText(props.yAxisTitle, 0, 0);
|
|
190
|
+
c.restore();
|
|
191
|
+
}
|
|
192
|
+
c.restore();
|
|
193
|
+
c.save();
|
|
194
|
+
c.beginPath();
|
|
195
|
+
c.rect(axes.plotLeft, axes.plotTop, axes.plotWidth.value, axes.plotHeight.value);
|
|
196
|
+
c.clip();
|
|
197
|
+
let seriesIdx = 0;
|
|
198
|
+
for (const [key, seriesItems] of seriesMap.value) {
|
|
199
|
+
const color = props.colors[seriesIdx % props.colors.length];
|
|
200
|
+
const sorted = [...seriesItems].sort((a, b) => parseValue(a[props.xField]) - parseValue(b[props.xField]));
|
|
201
|
+
const drawCount = Math.max(1, Math.floor(sorted.length * p));
|
|
202
|
+
const pts = sorted.slice(0, drawCount);
|
|
203
|
+
c.save();
|
|
204
|
+
c.beginPath();
|
|
205
|
+
pts.forEach((item, i) => {
|
|
206
|
+
const x = axes.toX(parseValue(item[props.xField]));
|
|
207
|
+
const y = axes.toY(parseValue(item[props.yField]));
|
|
208
|
+
if (i === 0) c.moveTo(x, y);
|
|
209
|
+
else c.lineTo(x, y);
|
|
210
|
+
});
|
|
211
|
+
if (pts.length > 0) {
|
|
212
|
+
const lastX = axes.toX(parseValue(pts[pts.length - 1][props.xField]));
|
|
213
|
+
const firstX = axes.toX(parseValue(pts[0][props.xField]));
|
|
214
|
+
const baselineY = axes.plotTop + axes.plotHeight.value;
|
|
215
|
+
c.lineTo(lastX, baselineY);
|
|
216
|
+
c.lineTo(firstX, baselineY);
|
|
217
|
+
c.closePath();
|
|
218
|
+
}
|
|
219
|
+
c.fillStyle = color + "33";
|
|
220
|
+
c.fill();
|
|
221
|
+
c.beginPath();
|
|
222
|
+
pts.forEach((item, i) => {
|
|
223
|
+
const x = axes.toX(parseValue(item[props.xField]));
|
|
224
|
+
const y = axes.toY(parseValue(item[props.yField]));
|
|
225
|
+
if (i === 0) c.moveTo(x, y);
|
|
226
|
+
else c.lineTo(x, y);
|
|
227
|
+
});
|
|
228
|
+
c.strokeStyle = color;
|
|
229
|
+
c.lineWidth = 2;
|
|
230
|
+
c.lineJoin = "round";
|
|
231
|
+
c.stroke();
|
|
232
|
+
c.restore();
|
|
233
|
+
seriesIdx++;
|
|
234
|
+
}
|
|
235
|
+
c.restore();
|
|
236
|
+
if (props.showLegend) {
|
|
237
|
+
drawLegend(c);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
const drawLegend = (c) => {
|
|
241
|
+
c.save();
|
|
242
|
+
c.font = "11px system-ui, sans-serif";
|
|
243
|
+
c.textAlign = "left";
|
|
244
|
+
c.textBaseline = "middle";
|
|
245
|
+
const keys = Array.from(seriesMap.value.keys());
|
|
246
|
+
let xOffset = axes.plotLeft;
|
|
247
|
+
const yPos = axes.plotTop + axes.plotHeight.value + 28;
|
|
248
|
+
keys.forEach((key, i) => {
|
|
249
|
+
const color = props.colors[i % props.colors.length];
|
|
250
|
+
c.fillStyle = color;
|
|
251
|
+
c.fillRect(xOffset, yPos - 4, 10, 8);
|
|
252
|
+
c.fillStyle = "rgba(150,150,170,0.9)";
|
|
253
|
+
const label = key === "default" ? "Series" : key;
|
|
254
|
+
c.fillText(label, xOffset + 15, yPos);
|
|
255
|
+
xOffset += c.measureText(label).width + 35;
|
|
256
|
+
});
|
|
257
|
+
c.restore();
|
|
258
|
+
};
|
|
259
|
+
watch([items, scale, panOffset, hoveredIndex, progress], draw, { deep: true });
|
|
260
|
+
watch(items, () => {
|
|
261
|
+
if (props.animated) animate();
|
|
262
|
+
}, { deep: true });
|
|
263
|
+
watch(scale, (v) => emit("zoom-change", v));
|
|
264
|
+
watch(panOffset, (v) => emit("pan-change", v), { deep: true });
|
|
265
|
+
const hoveredPoints = computed(() => {
|
|
266
|
+
if (hoveredIndex.value === -1) return [];
|
|
267
|
+
const item = items.value[hoveredIndex.value];
|
|
268
|
+
const xVal = parseValue(item[props.xField]);
|
|
269
|
+
const xPx = axes.toX(xVal);
|
|
270
|
+
const pts = [];
|
|
271
|
+
let seriesIdx = 0;
|
|
272
|
+
for (const [key, seriesItems] of seriesMap.value) {
|
|
273
|
+
const seriesItem = seriesItems.find((it) => parseValue(it[props.xField]) === xVal);
|
|
274
|
+
if (seriesItem) {
|
|
275
|
+
pts.push({
|
|
276
|
+
x: xPx,
|
|
277
|
+
y: axes.toY(parseValue(seriesItem[props.yField])),
|
|
278
|
+
color: props.colors[seriesIdx % props.colors.length],
|
|
279
|
+
item: seriesItem,
|
|
280
|
+
index: items.value.indexOf(seriesItem)
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
seriesIdx++;
|
|
284
|
+
}
|
|
285
|
+
return pts;
|
|
286
|
+
});
|
|
287
|
+
onMounted(async () => {
|
|
288
|
+
await nextTick();
|
|
289
|
+
if (containerRef.value && canvasRef.value) {
|
|
290
|
+
setupCanvas(canvasRef.value);
|
|
291
|
+
if (props.animated) animate();
|
|
292
|
+
else draw();
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
const onMouseMove = (e) => {
|
|
296
|
+
viewport.onMouseMove(e);
|
|
297
|
+
if (isDragging.value) {
|
|
298
|
+
setHovered(-1);
|
|
299
|
+
hideTooltip();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const rect = containerRef.value?.getBoundingClientRect();
|
|
303
|
+
if (!rect) return;
|
|
304
|
+
const mouseX = e.clientX - rect.left;
|
|
305
|
+
const mouseY = e.clientY - rect.top;
|
|
306
|
+
const nearest = findNearestX(items.value, mouseX, props.xField, axes);
|
|
307
|
+
if (nearest) {
|
|
308
|
+
setHovered(nearest.index);
|
|
309
|
+
showTooltip(mouseX + 10, mouseY - 20, `${nearest.item[props.xField]}: ${nearest.item[props.yField]}`, nearest.item, nearest.index);
|
|
310
|
+
emit("hover-point", nearest.item, nearest.index);
|
|
311
|
+
} else {
|
|
312
|
+
setHovered(-1);
|
|
313
|
+
hideTooltip();
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const onMouseLeave = (e) => {
|
|
317
|
+
onViewportMouseLeave(e);
|
|
318
|
+
setHovered(-1);
|
|
319
|
+
hideTooltip();
|
|
320
|
+
};
|
|
321
|
+
defineExpose({
|
|
322
|
+
zoomIn: viewport.zoomIn,
|
|
323
|
+
zoomOut: viewport.zoomOut,
|
|
324
|
+
resetZoom: viewport.resetZoom,
|
|
325
|
+
exportPng: () => canvasRef.value && exportPng(canvasRef.value, "area-chart.png"),
|
|
326
|
+
exportSvg: () => svgRef.value && exportSvgFile(svgRef.value, "area-chart.svg")
|
|
327
|
+
});
|
|
328
|
+
</script>
|
|
329
|
+
|
|
330
|
+
<style scoped>
|
|
331
|
+
.k-chart-wrapper {
|
|
332
|
+
position: relative;
|
|
333
|
+
user-select: none;
|
|
334
|
+
}
|
|
335
|
+
.k-chart-wrapper .k-chart-controls {
|
|
336
|
+
position: absolute;
|
|
337
|
+
top: 8px;
|
|
338
|
+
right: 8px;
|
|
339
|
+
z-index: 10;
|
|
340
|
+
display: flex;
|
|
341
|
+
gap: 4px;
|
|
342
|
+
}
|
|
343
|
+
.k-chart-wrapper .k-chart-btn {
|
|
344
|
+
display: none;
|
|
345
|
+
}
|
|
346
|
+
.k-chart-wrapper .k-chart-inner {
|
|
347
|
+
width: 100%;
|
|
348
|
+
height: 400px;
|
|
349
|
+
position: relative;
|
|
350
|
+
}
|
|
351
|
+
.k-chart-wrapper .k-chart-inner canvas, .k-chart-wrapper .k-chart-inner .k-chart-svg {
|
|
352
|
+
position: absolute;
|
|
353
|
+
top: 0;
|
|
354
|
+
left: 0;
|
|
355
|
+
width: 100%;
|
|
356
|
+
height: 100%;
|
|
357
|
+
display: block;
|
|
358
|
+
}
|
|
359
|
+
.k-chart-wrapper .k-chart-inner .k-chart-svg {
|
|
360
|
+
overflow: visible;
|
|
361
|
+
}
|
|
362
|
+
.k-chart-wrapper .k-chart-svg {
|
|
363
|
+
pointer-events: none;
|
|
364
|
+
}
|
|
365
|
+
.k-chart-wrapper .k-chart-svg .k-chart-hit-proxy {
|
|
366
|
+
pointer-events: all;
|
|
367
|
+
cursor: pointer;
|
|
368
|
+
}
|
|
369
|
+
.k-chart-wrapper .k-chart-tooltip {
|
|
370
|
+
position: absolute;
|
|
371
|
+
background: var(--bg-color-elevated, #1e1e2e);
|
|
372
|
+
color: var(--text-color-primary, #cdd6f4);
|
|
373
|
+
border: 1px solid var(--border-color-medium, #45475a);
|
|
374
|
+
border-radius: 8px;
|
|
375
|
+
padding: 6px 10px;
|
|
376
|
+
font-size: 12px;
|
|
377
|
+
pointer-events: none;
|
|
378
|
+
z-index: 20;
|
|
379
|
+
white-space: nowrap;
|
|
380
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
381
|
+
}
|
|
382
|
+
</style>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
dataProvider?: any;
|
|
3
|
+
xField?: string;
|
|
4
|
+
yField?: string;
|
|
5
|
+
seriesField?: string;
|
|
6
|
+
animated?: boolean;
|
|
7
|
+
zoomable?: boolean;
|
|
8
|
+
maxZoom?: number;
|
|
9
|
+
stacked?: boolean;
|
|
10
|
+
colors?: string[];
|
|
11
|
+
backgroundColor?: string;
|
|
12
|
+
showLegend?: boolean;
|
|
13
|
+
xAxisTitle?: string;
|
|
14
|
+
yAxisTitle?: string;
|
|
15
|
+
};
|
|
16
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
17
|
+
zoomIn: () => void;
|
|
18
|
+
zoomOut: () => void;
|
|
19
|
+
resetZoom: () => void;
|
|
20
|
+
exportPng: () => void | null;
|
|
21
|
+
exportSvg: () => void | null;
|
|
22
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
23
|
+
"click-point": (item: any, index: number) => any;
|
|
24
|
+
"hover-point": (item: any, index: number) => any;
|
|
25
|
+
"zoom-change": (scale: number) => any;
|
|
26
|
+
"pan-change": (offset: {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
}) => any;
|
|
30
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
31
|
+
"onClick-point"?: ((item: any, index: number) => any) | undefined;
|
|
32
|
+
"onHover-point"?: ((item: any, index: number) => any) | undefined;
|
|
33
|
+
"onZoom-change"?: ((scale: number) => any) | undefined;
|
|
34
|
+
"onPan-change"?: ((offset: {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
}) => any) | undefined;
|
|
38
|
+
}>, {
|
|
39
|
+
xField: string;
|
|
40
|
+
yField: string;
|
|
41
|
+
seriesField: string;
|
|
42
|
+
animated: boolean;
|
|
43
|
+
zoomable: boolean;
|
|
44
|
+
maxZoom: number;
|
|
45
|
+
stacked: boolean;
|
|
46
|
+
colors: string[];
|
|
47
|
+
backgroundColor: string;
|
|
48
|
+
showLegend: boolean;
|
|
49
|
+
xAxisTitle: string;
|
|
50
|
+
yAxisTitle: string;
|
|
51
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
52
|
+
declare const _default: typeof __VLS_export;
|
|
53
|
+
export default _default;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
dataProvider?: any;
|
|
3
|
+
categoryField?: string;
|
|
4
|
+
valueField?: string;
|
|
5
|
+
groupField?: string;
|
|
6
|
+
orientation?: 'vertical' | 'horizontal';
|
|
7
|
+
mode?: 'simple' | 'clustered' | 'stacked';
|
|
8
|
+
animated?: boolean;
|
|
9
|
+
zoomable?: boolean;
|
|
10
|
+
maxZoom?: number;
|
|
11
|
+
colors?: string[];
|
|
12
|
+
backgroundColor?: string;
|
|
13
|
+
showLegend?: boolean;
|
|
14
|
+
xAxisTitle?: string;
|
|
15
|
+
yAxisTitle?: string;
|
|
16
|
+
};
|
|
17
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
18
|
+
zoomIn: () => void;
|
|
19
|
+
zoomOut: () => void;
|
|
20
|
+
resetZoom: () => void;
|
|
21
|
+
exportPng: () => void | null;
|
|
22
|
+
exportSvg: () => void | null;
|
|
23
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
24
|
+
"click-point": (item: any, index: number) => any;
|
|
25
|
+
"hover-point": (item: any, index: number) => any;
|
|
26
|
+
"zoom-change": (scale: number) => any;
|
|
27
|
+
"pan-change": (offset: {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
}) => any;
|
|
31
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
32
|
+
"onClick-point"?: ((item: any, index: number) => any) | undefined;
|
|
33
|
+
"onHover-point"?: ((item: any, index: number) => any) | undefined;
|
|
34
|
+
"onZoom-change"?: ((scale: number) => any) | undefined;
|
|
35
|
+
"onPan-change"?: ((offset: {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
}) => any) | undefined;
|
|
39
|
+
}>, {
|
|
40
|
+
animated: boolean;
|
|
41
|
+
zoomable: boolean;
|
|
42
|
+
maxZoom: number;
|
|
43
|
+
colors: string[];
|
|
44
|
+
backgroundColor: string;
|
|
45
|
+
showLegend: boolean;
|
|
46
|
+
xAxisTitle: string;
|
|
47
|
+
yAxisTitle: string;
|
|
48
|
+
categoryField: string;
|
|
49
|
+
valueField: string;
|
|
50
|
+
groupField: string;
|
|
51
|
+
orientation: "vertical" | "horizontal";
|
|
52
|
+
mode: "simple" | "clustered" | "stacked";
|
|
53
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
54
|
+
declare const _default: typeof __VLS_export;
|
|
55
|
+
export default _default;
|