feat(workbench): expand SCADA monitoring and investigation presentation
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import { createChartSampleTimeSchema } from "./presentation/command-schema";
|
||||
|
||||
const sampleTimeSchema = createChartSampleTimeSchema();
|
||||
|
||||
export type SafeChartSpec = {
|
||||
title?: string;
|
||||
chartType: "line" | "bar";
|
||||
@@ -7,8 +11,9 @@ export type SafeChartSpec = {
|
||||
|
||||
export type SafeChartSeries = {
|
||||
name: string;
|
||||
data: number[];
|
||||
type?: "line" | "bar";
|
||||
data: Array<number | null>;
|
||||
type?: "line" | "bar" | "scatter";
|
||||
sample_times?: Array<string | null>;
|
||||
};
|
||||
|
||||
export type SafeChartData = {
|
||||
@@ -34,6 +39,7 @@ type RawChartSeries = {
|
||||
points?: unknown;
|
||||
values?: unknown;
|
||||
type?: unknown;
|
||||
sample_times?: unknown;
|
||||
};
|
||||
|
||||
export function parseChartSpec(value: unknown): SafeChartSpec {
|
||||
@@ -75,12 +81,12 @@ export function normalizeSafeChartData(value: unknown, maxPoints = 24): SafeChar
|
||||
.map((point, index) => {
|
||||
const parsed = pointToLabelValue(point as RawChartPoint, xData[index] ?? `${index + 1}`);
|
||||
if (!parsed) {
|
||||
labelsFromPoints[index] = xData[index] ?? `${index + 1}`;
|
||||
return null;
|
||||
}
|
||||
labelsFromPoints[index] = parsed.label;
|
||||
return parsed.value;
|
||||
})
|
||||
.filter((item): item is number => item !== null);
|
||||
});
|
||||
|
||||
if (!data.length) {
|
||||
return null;
|
||||
@@ -93,7 +99,11 @@ export function normalizeSafeChartData(value: unknown, maxPoints = 24): SafeChar
|
||||
return {
|
||||
name: stringValue(item.name) ?? `系列 ${seriesIndex + 1}`,
|
||||
data,
|
||||
type: item.type === "line" || item.type === "bar" ? item.type : undefined
|
||||
type: item.type === "line" || item.type === "bar" || item.type === "scatter" ? item.type : undefined,
|
||||
...(Array.isArray(item.sample_times) ? { sample_times: data.map((value, index) => {
|
||||
const time = item.sample_times as unknown[];
|
||||
return value !== null && sampleTimeSchema.safeParse(time[index]).success ? time[index] as string : null;
|
||||
}) } : {})
|
||||
};
|
||||
})
|
||||
.filter((item): item is SafeChartSeries => Boolean(item));
|
||||
@@ -101,7 +111,8 @@ export function normalizeSafeChartData(value: unknown, maxPoints = 24): SafeChar
|
||||
const clippedXData = xData.slice(0, maxPoints);
|
||||
const clippedSeries = normalizedSeries.map((series) => ({
|
||||
...series,
|
||||
data: series.data.slice(0, clippedXData.length)
|
||||
data: series.data.slice(0, clippedXData.length),
|
||||
...(series.sample_times ? { sample_times: series.sample_times.slice(0, clippedXData.length) } : {})
|
||||
}));
|
||||
|
||||
return clippedXData.length > 0 && clippedSeries.length > 0
|
||||
|
||||
Reference in New Issue
Block a user