@katlux/block-charts 0.1.1-alpha.119 → 0.1.1-alpha.121
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 +44 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/KAreaChart/KAreaChart.d.vue.ts +2 -2
- package/dist/runtime/components/KAreaChart/KAreaChart.vue +44 -246
- package/dist/runtime/components/KAreaChart/KAreaChart.vue.d.ts +2 -2
- package/dist/runtime/components/KBarChart/KBarChart.d.vue.ts +4 -4
- package/dist/runtime/components/KBarChart/KBarChart.vue +25 -294
- package/dist/runtime/components/KBarChart/KBarChart.vue.d.ts +4 -4
- package/dist/runtime/components/KHeatMap/KHeatMap.d.vue.ts +3 -3
- package/dist/runtime/components/KHeatMap/KHeatMap.vue.d.ts +3 -3
- package/dist/runtime/components/KLineChart/KLineChart.d.vue.ts +2 -2
- package/dist/runtime/components/KLineChart/KLineChart.vue +44 -228
- package/dist/runtime/components/KLineChart/KLineChart.vue.d.ts +2 -2
- package/dist/runtime/components/KScatterChart/KScatterChart.d.vue.ts +2 -2
- package/dist/runtime/components/KScatterChart/KScatterChart.vue.d.ts +2 -2
- package/dist/runtime/composables/useChartData.d.ts +15 -1
- package/dist/runtime/composables/useChartData.js +40 -3
- package/dist/runtime/utils/barChartCanvas.d.ts +31 -0
- package/dist/runtime/utils/barChartCanvas.js +297 -0
- package/dist/runtime/utils/canvasDrawHelpers.d.ts +27 -0
- package/dist/runtime/utils/canvasDrawHelpers.js +131 -0
- package/dist/runtime/utils/xySeriesHelpers.d.ts +30 -0
- package/dist/runtime/utils/xySeriesHelpers.js +196 -0
- package/package.json +3 -3
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
</template>
|
|
63
63
|
|
|
64
64
|
<script setup>
|
|
65
|
-
import { ref, watch, computed, onMounted,
|
|
65
|
+
import { ref, watch, computed, onMounted, nextTick, useId } from "vue";
|
|
66
66
|
import { useChartCanvas } from "../../composables/useChartCanvas";
|
|
67
67
|
import { useChartSvg } from "../../composables/useChartSvg";
|
|
68
68
|
import { useChartData } from "../../composables/useChartData";
|
|
@@ -71,7 +71,13 @@ import { useChartViewport } from "../../composables/useChartViewport";
|
|
|
71
71
|
import { useChartAnimation, easeOut } from "../../composables/useChartAnimation";
|
|
72
72
|
import { useChartExport } from "../../composables/useChartExport";
|
|
73
73
|
import { useChartHitTest } from "../../composables/useChartHitTest";
|
|
74
|
-
import {
|
|
74
|
+
import {
|
|
75
|
+
isChartProviderLoading,
|
|
76
|
+
drawChartGrid,
|
|
77
|
+
drawChartLegend,
|
|
78
|
+
drawXYSeriesAxes
|
|
79
|
+
} from "../../utils/canvasDrawHelpers";
|
|
80
|
+
import { useXYSeriesData, drawLineSeries } from "../../utils/xySeriesHelpers";
|
|
75
81
|
const clipId = useId();
|
|
76
82
|
const props = defineProps({
|
|
77
83
|
dataProvider: { type: null, required: false },
|
|
@@ -99,13 +105,7 @@ const dataRef = computed(() => props.dataProvider);
|
|
|
99
105
|
const { items, loading: dataLoading } = useChartData(dataRef);
|
|
100
106
|
const { progress, animate } = useChartAnimation();
|
|
101
107
|
const { exportPng, exportSvg: exportSvgFile } = useChartExport();
|
|
102
|
-
const isLoading = computed(() =>
|
|
103
|
-
const dp = props.dataProvider;
|
|
104
|
-
if (!dp) return dataLoading.value;
|
|
105
|
-
const rawLoading = dp.loading !== void 0 ? isRef(dp.loading) ? dp.loading.value : dp.loading?.value ?? dp.loading : false;
|
|
106
|
-
const rawInitial = dp.initialLoad !== void 0 ? isRef(dp.initialLoad) ? dp.initialLoad.value : dp.initialLoad?.value ?? dp.initialLoad : false;
|
|
107
|
-
return Boolean(dataLoading.value || rawLoading || rawInitial);
|
|
108
|
-
});
|
|
108
|
+
const isLoading = computed(() => isChartProviderLoading(props.dataProvider, dataLoading));
|
|
109
109
|
const tooltipStyle = computed(() => ({
|
|
110
110
|
left: `${tooltipState.value.x}px`,
|
|
111
111
|
top: `${tooltipState.value.y}px`
|
|
@@ -137,83 +137,22 @@ const {
|
|
|
137
137
|
onMouseUp,
|
|
138
138
|
onMouseLeave: onViewportMouseLeave
|
|
139
139
|
} = viewport;
|
|
140
|
-
const xAxisType = computed(() => {
|
|
141
|
-
if (!items.value.length) return "linear";
|
|
142
|
-
const sample = items.value.find((r) => r?.[props.xField] !== void 0 && r?.[props.xField] !== null)?.[props.xField];
|
|
143
|
-
if (sample === void 0 || sample === null) return "linear";
|
|
144
|
-
if (typeof sample === "number") return "linear";
|
|
145
|
-
if (typeof sample === "string") {
|
|
146
|
-
const cleaned = cleanNumber(sample, NaN);
|
|
147
|
-
if (Number.isFinite(cleaned)) return "linear";
|
|
148
|
-
const parsed = Date.parse(sample);
|
|
149
|
-
if (!isNaN(parsed) && !/^\d+$/.test(sample.trim()) && /[-/T:]|[A-Za-z]/.test(sample)) return "datetime";
|
|
150
|
-
return "category";
|
|
151
|
-
}
|
|
152
|
-
return "linear";
|
|
153
|
-
});
|
|
154
|
-
const isAllMidnight = computed(() => {
|
|
155
|
-
if (xAxisType.value !== "datetime" || !items.value.length) return false;
|
|
156
|
-
const checkCount = Math.min(items.value.length, 100);
|
|
157
|
-
for (let i = 0; i < checkCount; i++) {
|
|
158
|
-
const ts = parseValue(items.value[i][props.xField]);
|
|
159
|
-
const d = new Date(ts);
|
|
160
|
-
if (d.getHours() !== 0 || d.getMinutes() !== 0) return false;
|
|
161
|
-
}
|
|
162
|
-
return true;
|
|
163
|
-
});
|
|
164
|
-
const categoryList = computed(() => {
|
|
165
|
-
if (xAxisType.value !== "category") return [];
|
|
166
|
-
const seen = /* @__PURE__ */ new Set();
|
|
167
|
-
const list = [];
|
|
168
|
-
for (const item of items.value) {
|
|
169
|
-
const val = String(item[props.xField] ?? "");
|
|
170
|
-
if (!seen.has(val)) {
|
|
171
|
-
seen.add(val);
|
|
172
|
-
list.push(val);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return list;
|
|
176
|
-
});
|
|
177
|
-
const categoryIndexMap = computed(() => {
|
|
178
|
-
const map = {};
|
|
179
|
-
categoryList.value.forEach((cat, i) => {
|
|
180
|
-
map[cat] = i;
|
|
181
|
-
});
|
|
182
|
-
return map;
|
|
183
|
-
});
|
|
184
|
-
const resolveX = (item, index = 0) => {
|
|
185
|
-
if (!item) return index;
|
|
186
|
-
const raw = item[props.xField];
|
|
187
|
-
if (xAxisType.value === "category") return categoryIndexMap.value[String(raw)] ?? index;
|
|
188
|
-
return parseValue(raw, index);
|
|
189
|
-
};
|
|
190
|
-
const seriesMap = computed(() => {
|
|
191
|
-
const map = /* @__PURE__ */ new Map();
|
|
192
|
-
for (const item of items.value) {
|
|
193
|
-
const key = String(item[props.seriesField] ?? "default");
|
|
194
|
-
if (!map.has(key)) map.set(key, []);
|
|
195
|
-
map.get(key).push(item);
|
|
196
|
-
}
|
|
197
|
-
return map;
|
|
198
|
-
});
|
|
199
|
-
const sortedSeriesMap = computed(() => {
|
|
200
|
-
const map = /* @__PURE__ */ new Map();
|
|
201
|
-
const itemIndexMap = /* @__PURE__ */ new Map();
|
|
202
|
-
for (let i = 0; i < items.value.length; i++) {
|
|
203
|
-
itemIndexMap.set(items.value[i], i);
|
|
204
|
-
}
|
|
205
|
-
for (const [key, seriesItems] of seriesMap.value) {
|
|
206
|
-
const enriched = seriesItems.map((item, idx) => ({
|
|
207
|
-
item,
|
|
208
|
-
index: itemIndexMap.get(item) ?? idx,
|
|
209
|
-
xVal: resolveX(item, idx)
|
|
210
|
-
})).sort((a, b) => a.xVal - b.xVal);
|
|
211
|
-
map.set(key, enriched);
|
|
212
|
-
}
|
|
213
|
-
return map;
|
|
214
|
-
});
|
|
215
140
|
const xFieldRef = computed(() => props.xField);
|
|
216
141
|
const yFieldRef = computed(() => props.yField);
|
|
142
|
+
const seriesFieldRef = computed(() => props.seriesField);
|
|
143
|
+
const {
|
|
144
|
+
xAxisType,
|
|
145
|
+
isAllMidnight,
|
|
146
|
+
categoryList,
|
|
147
|
+
resolveX,
|
|
148
|
+
seriesMap,
|
|
149
|
+
sortedSeriesMap
|
|
150
|
+
} = useXYSeriesData({
|
|
151
|
+
items,
|
|
152
|
+
xField: xFieldRef,
|
|
153
|
+
yField: yFieldRef,
|
|
154
|
+
seriesField: seriesFieldRef
|
|
155
|
+
});
|
|
217
156
|
const axes = useChartAxes({
|
|
218
157
|
items,
|
|
219
158
|
xField: xFieldRef,
|
|
@@ -230,8 +169,18 @@ const draw = () => {
|
|
|
230
169
|
clear(props.backgroundColor);
|
|
231
170
|
const c = ctx.value;
|
|
232
171
|
const p = props.animated ? easeOut(progress.value) : 1;
|
|
233
|
-
|
|
234
|
-
|
|
172
|
+
drawChartGrid(c, axes.plotLeft, axes.plotTop, axes.plotWidth.value, axes.plotHeight.value);
|
|
173
|
+
drawXYSeriesAxes(c, {
|
|
174
|
+
axes,
|
|
175
|
+
xAxisType: xAxisType.value,
|
|
176
|
+
isAllMidnight: isAllMidnight.value,
|
|
177
|
+
categoryList: categoryList.value,
|
|
178
|
+
yMin: axes.yMin.value,
|
|
179
|
+
yMax: axes.yMax.value,
|
|
180
|
+
toY: axes.toY,
|
|
181
|
+
xAxisTitle: props.xAxisTitle,
|
|
182
|
+
yAxisTitle: props.yAxisTitle
|
|
183
|
+
});
|
|
235
184
|
c.save();
|
|
236
185
|
c.beginPath();
|
|
237
186
|
c.rect(axes.plotLeft, axes.plotTop, axes.plotWidth.value, axes.plotHeight.value);
|
|
@@ -239,153 +188,20 @@ const draw = () => {
|
|
|
239
188
|
let seriesIdx = 0;
|
|
240
189
|
for (const [, seriesData] of sortedSeriesMap.value) {
|
|
241
190
|
const color = props.colors[seriesIdx % props.colors.length];
|
|
242
|
-
|
|
191
|
+
drawLineSeries(c, seriesData, axes, props.yField, color, p, hoveredIndex.value);
|
|
243
192
|
seriesIdx++;
|
|
244
193
|
}
|
|
245
194
|
c.restore();
|
|
246
195
|
if (props.showLegend) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const keys = Array.from(seriesMap.value.keys());
|
|
256
|
-
let xOffset = axes.plotLeft;
|
|
257
|
-
const yPos = axes.plotTop + axes.plotHeight.value + 28;
|
|
258
|
-
keys.forEach((key, i) => {
|
|
259
|
-
const color = props.colors[i % props.colors.length];
|
|
260
|
-
c.fillStyle = color;
|
|
261
|
-
c.beginPath();
|
|
262
|
-
c.arc(xOffset + 5, yPos, 4, 0, Math.PI * 2);
|
|
263
|
-
c.fill();
|
|
264
|
-
c.fillStyle = "rgba(150,150,170,0.9)";
|
|
265
|
-
const label = key === "default" ? "Series" : key;
|
|
266
|
-
c.fillText(label, xOffset + 15, yPos);
|
|
267
|
-
xOffset += c.measureText(label).width + 35;
|
|
268
|
-
});
|
|
269
|
-
c.restore();
|
|
270
|
-
};
|
|
271
|
-
const drawGrid = (c) => {
|
|
272
|
-
c.save();
|
|
273
|
-
c.strokeStyle = "rgba(100,100,120,0.1)";
|
|
274
|
-
c.lineWidth = 1;
|
|
275
|
-
const ySteps = 6;
|
|
276
|
-
for (let i = 0; i <= ySteps; i++) {
|
|
277
|
-
const y = axes.plotTop + axes.plotHeight.value / ySteps * i;
|
|
278
|
-
c.beginPath();
|
|
279
|
-
c.moveTo(axes.plotLeft, y);
|
|
280
|
-
c.lineTo(axes.plotLeft + axes.plotWidth.value, y);
|
|
281
|
-
c.stroke();
|
|
282
|
-
}
|
|
283
|
-
const xSteps = 6;
|
|
284
|
-
for (let i = 0; i <= xSteps; i++) {
|
|
285
|
-
const x = axes.plotLeft + axes.plotWidth.value / xSteps * i;
|
|
286
|
-
c.beginPath();
|
|
287
|
-
c.moveTo(x, axes.plotTop);
|
|
288
|
-
c.lineTo(x, axes.plotTop + axes.plotHeight.value);
|
|
289
|
-
c.stroke();
|
|
290
|
-
}
|
|
291
|
-
c.restore();
|
|
292
|
-
};
|
|
293
|
-
const drawAxes = (c) => {
|
|
294
|
-
c.save();
|
|
295
|
-
c.strokeStyle = "rgba(150,150,170,0.5)";
|
|
296
|
-
c.lineWidth = 1;
|
|
297
|
-
c.fillStyle = "rgba(150,150,170,0.8)";
|
|
298
|
-
c.font = "11px system-ui, sans-serif";
|
|
299
|
-
c.textAlign = "right";
|
|
300
|
-
const ySteps = 5;
|
|
301
|
-
for (let i = 0; i <= ySteps; i++) {
|
|
302
|
-
const val = axes.yMin.value + (axes.yMax.value - axes.yMin.value) * (i / ySteps);
|
|
303
|
-
const y = axes.toY(val);
|
|
304
|
-
c.fillText(val.toFixed(1), axes.plotLeft - 8, y + 4);
|
|
305
|
-
}
|
|
306
|
-
c.textAlign = "center";
|
|
307
|
-
if (xAxisType.value === "category") {
|
|
308
|
-
const count = categoryList.value.length;
|
|
309
|
-
if (count > 0) {
|
|
310
|
-
const xSteps = Math.min(10, count - 1);
|
|
311
|
-
const stepSize = xSteps > 0 ? (count - 1) / xSteps : 1;
|
|
312
|
-
for (let i = 0; i <= xSteps; i++) {
|
|
313
|
-
const idx = Math.round(i * stepSize);
|
|
314
|
-
const x = axes.toX(idx);
|
|
315
|
-
const label = categoryList.value[idx] ?? "";
|
|
316
|
-
c.fillText(label, x, axes.plotTop + axes.plotHeight.value + 16);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
} else {
|
|
320
|
-
const xSteps = 5;
|
|
321
|
-
for (let i = 0; i <= xSteps; i++) {
|
|
322
|
-
const val = axes.xMin.value + (axes.xMax.value - axes.xMin.value) * (i / xSteps);
|
|
323
|
-
const x = axes.toX(val);
|
|
324
|
-
let label;
|
|
325
|
-
if (xAxisType.value === "datetime") {
|
|
326
|
-
label = isAllMidnight.value ? new Date(val).toLocaleDateString([], { month: "short", day: "numeric" }) : new Date(val).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
327
|
-
} else {
|
|
328
|
-
label = val.toFixed(1);
|
|
329
|
-
}
|
|
330
|
-
c.fillText(label, x, axes.plotTop + axes.plotHeight.value + 16);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
c.beginPath();
|
|
334
|
-
c.moveTo(axes.plotLeft, axes.plotTop + axes.plotHeight.value);
|
|
335
|
-
c.lineTo(axes.plotLeft + axes.plotWidth.value, axes.plotTop + axes.plotHeight.value);
|
|
336
|
-
c.stroke();
|
|
337
|
-
c.beginPath();
|
|
338
|
-
c.moveTo(axes.plotLeft, axes.plotTop);
|
|
339
|
-
c.lineTo(axes.plotLeft, axes.plotTop + axes.plotHeight.value);
|
|
340
|
-
c.stroke();
|
|
341
|
-
c.fillStyle = "rgba(120,120,140,0.8)";
|
|
342
|
-
if (props.xAxisTitle) {
|
|
343
|
-
c.textAlign = "center";
|
|
344
|
-
c.fillText(props.xAxisTitle, axes.plotLeft + axes.plotWidth.value / 2, axes.plotTop + axes.plotHeight.value + 34);
|
|
345
|
-
}
|
|
346
|
-
if (props.yAxisTitle) {
|
|
347
|
-
c.save();
|
|
348
|
-
c.translate(axes.plotLeft - 40, axes.plotTop + axes.plotHeight.value / 2);
|
|
349
|
-
c.rotate(-Math.PI / 2);
|
|
350
|
-
c.textAlign = "center";
|
|
351
|
-
c.fillText(props.yAxisTitle, 0, 0);
|
|
352
|
-
c.restore();
|
|
353
|
-
}
|
|
354
|
-
c.restore();
|
|
355
|
-
};
|
|
356
|
-
const drawLine = (c, data, color, progress2) => {
|
|
357
|
-
if (!data.length) return;
|
|
358
|
-
const totalPts = data.length;
|
|
359
|
-
const drawCount = Math.max(1, Math.floor(totalPts * progress2));
|
|
360
|
-
c.save();
|
|
361
|
-
c.strokeStyle = color;
|
|
362
|
-
c.lineWidth = 2.5;
|
|
363
|
-
c.lineJoin = "round";
|
|
364
|
-
c.lineCap = "round";
|
|
365
|
-
c.beginPath();
|
|
366
|
-
for (let i = 0; i < drawCount; i++) {
|
|
367
|
-
const pt = data[i];
|
|
368
|
-
const x = axes.toX(pt.xVal);
|
|
369
|
-
const y = axes.toY(parseValue(pt.item[props.yField]));
|
|
370
|
-
if (i === 0) c.moveTo(x, y);
|
|
371
|
-
else c.lineTo(x, y);
|
|
372
|
-
}
|
|
373
|
-
c.stroke();
|
|
374
|
-
const currentHoveredIdx = hoveredIndex.value;
|
|
375
|
-
for (let i = 0; i < drawCount; i++) {
|
|
376
|
-
const pt = data[i];
|
|
377
|
-
const x = axes.toX(pt.xVal);
|
|
378
|
-
const y = axes.toY(parseValue(pt.item[props.yField]));
|
|
379
|
-
const isHovered = currentHoveredIdx !== -1 && pt.index === currentHoveredIdx;
|
|
380
|
-
c.beginPath();
|
|
381
|
-
c.arc(x, y, isHovered ? 5 : 3, 0, Math.PI * 2);
|
|
382
|
-
c.fillStyle = isHovered ? "#fff" : color;
|
|
383
|
-
c.strokeStyle = color;
|
|
384
|
-
c.lineWidth = 2;
|
|
385
|
-
c.fill();
|
|
386
|
-
c.stroke();
|
|
196
|
+
drawChartLegend(
|
|
197
|
+
c,
|
|
198
|
+
Array.from(seriesMap.value.keys()),
|
|
199
|
+
props.colors,
|
|
200
|
+
axes.plotLeft,
|
|
201
|
+
axes.plotTop + axes.plotHeight.value + 28,
|
|
202
|
+
"circle"
|
|
203
|
+
);
|
|
387
204
|
}
|
|
388
|
-
c.restore();
|
|
389
205
|
};
|
|
390
206
|
watch(progress, draw);
|
|
391
207
|
watch([scale, panOffset, resizeTick, width, height, hoveredIndex], draw);
|
|
@@ -36,6 +36,8 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
|
36
36
|
y: number;
|
|
37
37
|
}) => any) | undefined;
|
|
38
38
|
}>, {
|
|
39
|
+
xAxisTitle: string;
|
|
40
|
+
yAxisTitle: string;
|
|
39
41
|
xField: string;
|
|
40
42
|
yField: string;
|
|
41
43
|
seriesField: string;
|
|
@@ -46,8 +48,6 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
|
46
48
|
colors: string[];
|
|
47
49
|
backgroundColor: string;
|
|
48
50
|
showLegend: boolean;
|
|
49
|
-
xAxisTitle: string;
|
|
50
|
-
yAxisTitle: string;
|
|
51
51
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
52
52
|
declare const _default: typeof __VLS_export;
|
|
53
53
|
export default _default;
|
|
@@ -38,6 +38,8 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
|
38
38
|
y: number;
|
|
39
39
|
}) => any) | undefined;
|
|
40
40
|
}>, {
|
|
41
|
+
xAxisTitle: string;
|
|
42
|
+
yAxisTitle: string;
|
|
41
43
|
xField: string;
|
|
42
44
|
yField: string;
|
|
43
45
|
seriesField: string;
|
|
@@ -48,8 +50,6 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
|
48
50
|
colors: string[];
|
|
49
51
|
backgroundColor: string;
|
|
50
52
|
showLegend: boolean;
|
|
51
|
-
xAxisTitle: string;
|
|
52
|
-
yAxisTitle: string;
|
|
53
53
|
labelField: string;
|
|
54
54
|
sizeField: string;
|
|
55
55
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
@@ -38,6 +38,8 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
|
38
38
|
y: number;
|
|
39
39
|
}) => any) | undefined;
|
|
40
40
|
}>, {
|
|
41
|
+
xAxisTitle: string;
|
|
42
|
+
yAxisTitle: string;
|
|
41
43
|
xField: string;
|
|
42
44
|
yField: string;
|
|
43
45
|
seriesField: string;
|
|
@@ -48,8 +50,6 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
|
48
50
|
colors: string[];
|
|
49
51
|
backgroundColor: string;
|
|
50
52
|
showLegend: boolean;
|
|
51
|
-
xAxisTitle: string;
|
|
52
|
-
yAxisTitle: string;
|
|
53
53
|
labelField: string;
|
|
54
54
|
sizeField: string;
|
|
55
55
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
@@ -6,6 +6,14 @@ export interface IChartDataContext<T = any> {
|
|
|
6
6
|
error: Ref<string | null>;
|
|
7
7
|
reload: () => Promise<void>;
|
|
8
8
|
}
|
|
9
|
+
export interface IUseChartDataOptions {
|
|
10
|
+
/**
|
|
11
|
+
* When true (default for server providers with `fetchAll()`), automatically requests
|
|
12
|
+
* the full unpaginated dataset from server providers (e.g. by invoking `provider.fetchAll()`).
|
|
13
|
+
* Set to `false` to opt out and use paginated data only.
|
|
14
|
+
*/
|
|
15
|
+
fetchAll?: boolean;
|
|
16
|
+
}
|
|
9
17
|
/**
|
|
10
18
|
* Extracts item rows from a Katlux DataProvider instance.
|
|
11
19
|
* Prioritizes complete unpaginated datasets (filteredData or allData)
|
|
@@ -16,5 +24,11 @@ export declare function extractProviderItems<T = any>(provider?: ADataProvider |
|
|
|
16
24
|
* Provider-agnostic data watcher for Katlux chart components.
|
|
17
25
|
* Consumes data through Katlux DataProvider instances (Server-side or Client-side).
|
|
18
26
|
* Uses provider.subscribe() instead of Vue watch() so it works with __v_skip providers.
|
|
27
|
+
*
|
|
28
|
+
* For server providers (CFlatServerDataProvider, CAPIFlatServerDataProvider):
|
|
29
|
+
* - By default, uses available full datasets (`allData`, `filteredData`, or accumulated `_allData`).
|
|
30
|
+
* - If bound to a paginated server provider without accumulation, pass `{ fetchAll: true }`
|
|
31
|
+
* to trigger `provider.fetchAll()` (which requests `pageSize: 0` without overwriting table pagination),
|
|
32
|
+
* or enable accumulation on the provider via `provider.setAccumulating(true)`.
|
|
19
33
|
*/
|
|
20
|
-
export declare function useChartData<T = any>(dataProvider: Ref<ADataProvider | null | undefined> | ADataProvider | null | undefined): IChartDataContext<T>;
|
|
34
|
+
export declare function useChartData<T = any>(dataProvider: Ref<ADataProvider | null | undefined> | ADataProvider | null | undefined, options?: IUseChartDataOptions): IChartDataContext<T>;
|
|
@@ -31,6 +31,13 @@ export function extractProviderItems(provider) {
|
|
|
31
31
|
}
|
|
32
32
|
return all;
|
|
33
33
|
}
|
|
34
|
+
const accumulated = isRef(instance._allData) ? instance._allData.value : instance._allData;
|
|
35
|
+
if (Array.isArray(accumulated) && accumulated.length > 0) {
|
|
36
|
+
if (hasActiveFilter && Array.isArray(filtered)) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
return accumulated;
|
|
40
|
+
}
|
|
34
41
|
let raw = isRef(instance.pageData) ? instance.pageData.value : instance.pageData;
|
|
35
42
|
if (!raw) return [];
|
|
36
43
|
if (Array.isArray(raw)) {
|
|
@@ -41,7 +48,7 @@ export function extractProviderItems(provider) {
|
|
|
41
48
|
}
|
|
42
49
|
return [];
|
|
43
50
|
}
|
|
44
|
-
export function useChartData(dataProvider) {
|
|
51
|
+
export function useChartData(dataProvider, options) {
|
|
45
52
|
const items = shallowRef([]);
|
|
46
53
|
const loading = ref(false);
|
|
47
54
|
const error = ref(null);
|
|
@@ -58,6 +65,25 @@ export function useChartData(dataProvider) {
|
|
|
58
65
|
}
|
|
59
66
|
};
|
|
60
67
|
let unsubscribe = null;
|
|
68
|
+
let lastQuerySignature = "";
|
|
69
|
+
const getQuerySignature = (provider) => {
|
|
70
|
+
const filter = isRef(provider?.filter) ? provider.filter.value : provider?.filter;
|
|
71
|
+
const sortList = isRef(provider?.sortList) ? provider.sortList.value : provider?.sortList;
|
|
72
|
+
try {
|
|
73
|
+
return JSON.stringify({ filter: filter ?? null, sortList: sortList ?? null });
|
|
74
|
+
} catch {
|
|
75
|
+
return "";
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const shouldFetchAll = (provider) => {
|
|
79
|
+
return options?.fetchAll !== false && Boolean(provider && typeof provider.fetchAll === "function");
|
|
80
|
+
};
|
|
81
|
+
const triggerFetchAll = (provider) => {
|
|
82
|
+
if (shouldFetchAll(provider)) {
|
|
83
|
+
provider.fetchAll().then(() => updateItems()).catch(() => {
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
61
87
|
const setupSubscription = () => {
|
|
62
88
|
if (unsubscribe) {
|
|
63
89
|
unsubscribe();
|
|
@@ -65,9 +91,18 @@ export function useChartData(dataProvider) {
|
|
|
65
91
|
}
|
|
66
92
|
const isServer = typeof window === "undefined" || typeof import.meta !== "undefined" && Boolean(import.meta.server);
|
|
67
93
|
const provider = isRef(dataProvider) ? dataProvider.value : dataProvider;
|
|
94
|
+
lastQuerySignature = getQuerySignature(provider);
|
|
68
95
|
if (!isServer && provider?.subscribe) {
|
|
69
|
-
unsubscribe = provider.subscribe(() =>
|
|
96
|
+
unsubscribe = provider.subscribe(() => {
|
|
97
|
+
const currentSignature = getQuerySignature(provider);
|
|
98
|
+
if (shouldFetchAll(provider) && currentSignature !== lastQuerySignature) {
|
|
99
|
+
lastQuerySignature = currentSignature;
|
|
100
|
+
triggerFetchAll(provider);
|
|
101
|
+
}
|
|
102
|
+
updateItems();
|
|
103
|
+
});
|
|
70
104
|
}
|
|
105
|
+
triggerFetchAll(provider);
|
|
71
106
|
updateItems();
|
|
72
107
|
};
|
|
73
108
|
if (isRef(dataProvider)) {
|
|
@@ -98,7 +133,9 @@ export function useChartData(dataProvider) {
|
|
|
98
133
|
loading.value = true;
|
|
99
134
|
error.value = null;
|
|
100
135
|
try {
|
|
101
|
-
if (provider
|
|
136
|
+
if (shouldFetchAll(provider)) {
|
|
137
|
+
await provider.fetchAll();
|
|
138
|
+
} else if (provider.refresh) {
|
|
102
139
|
await provider.refresh();
|
|
103
140
|
} else if (provider.loadPageData) {
|
|
104
141
|
await provider.loadPageData();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface IBarRect {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
w: number;
|
|
5
|
+
h: number;
|
|
6
|
+
item: any;
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IBarChartDrawParams {
|
|
10
|
+
ctx: CanvasRenderingContext2D;
|
|
11
|
+
plotLeft: number;
|
|
12
|
+
plotTop: number;
|
|
13
|
+
plotWidth: number;
|
|
14
|
+
plotHeight: number;
|
|
15
|
+
progress: number;
|
|
16
|
+
orientation: 'vertical' | 'horizontal';
|
|
17
|
+
mode: 'simple' | 'stacked' | 'clustered';
|
|
18
|
+
visibleCategories: string[];
|
|
19
|
+
groups: string[];
|
|
20
|
+
categoryMap: Map<string, any[]>;
|
|
21
|
+
groupField: string;
|
|
22
|
+
valueField: string;
|
|
23
|
+
minValue: number;
|
|
24
|
+
valueRange: number;
|
|
25
|
+
colors: string[];
|
|
26
|
+
hoveredIndex: number;
|
|
27
|
+
showLegend: boolean;
|
|
28
|
+
xAxisTitle?: string;
|
|
29
|
+
yAxisTitle?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function drawBarChartScene(params: IBarChartDrawParams): IBarRect[];
|