fix(charts): simplify time labels in investigation views
Generic Container CI/CD / test-build-publish (push) Successful in 1m25s
Frontend CI/CD / build-test-publish-and-deploy (push) Successful in 1m26s

This commit is contained in:
2026-11-07 21:03:43 +08:00
parent 4a7781d5e5
commit 8a63926284
7 changed files with 96 additions and 20 deletions
+29
View File
@@ -41,3 +41,32 @@ export function formatDisplayText(text: string | null | undefined): string {
});
}).join("");
}
/** Chart labels use the display clock without repeating its zone to readers. */
export function formatChartDisplayText(value: string): string {
return formatDisplayText(value)
.replace(/[((]\s*(?:上海时间|Asia\/Shanghai|UTC\s*\+\s*8(?::00)?)\s*[))]/g, "")
.replace(/(?:上海时间|Asia\/Shanghai|UTC\s*\+\s*8(?::00)?)(?![\w:+-])\s*/g, "")
.replace(/[,,]\s*([))])/g, "$1")
.trim();
}
type ChartDisplayFields = {
title: string;
x_axis_name?: string;
y_axis_name?: string;
x_data: string[];
series: Array<{ name: string }>;
};
/** Preserve values and original sample timestamps; convert only visible labels. */
export function withChartDisplayTimes<T extends ChartDisplayFields>(chart: T): T {
const utcAxis = /UTC(?:\s*\+?0(?::00)?)?(?![\w+:-])/.test(chart.x_axis_name ?? "");
const bareTime = /^(?:\d{4}-\d{2}-\d{2}[T ])?\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?$/;
return { ...chart,
title: formatChartDisplayText(chart.title),
...(chart.x_axis_name ? { x_axis_name: formatChartDisplayText(chart.x_axis_name.replace(/UTC(?:\s*\+?0(?::00)?)?(?![\w+:-])/g, "UTC+8")) || "时间" } : {}),
x_data: chart.x_data.map((label) => formatChartDisplayText(utcAxis && bareTime.test(label) ? `${label} UTC` : label)),
series: chart.series.map((series) => ({ ...series, name: formatChartDisplayText(series.name) }))
};
}