Compare commits
5 Commits
bur-35
...
65dc9fcaf0
| Author | SHA1 | Date | |
|---|---|---|---|
| 65dc9fcaf0 | |||
|
|
102cbd1a40 | ||
| d9962a4a4b | |||
|
|
262c4f34a0 | ||
| 96600a1cf5 |
@@ -18,6 +18,10 @@ type HistoryChartProps = {
|
||||
};
|
||||
|
||||
/** Контейнер истории: загружает выбранные теги и передает готовые серии в область ECharts. */
|
||||
function isXAxisDataZoom(state: DataZoomState): boolean {
|
||||
return state.dataZoomId?.startsWith('history-x-') || state.dataZoomIndex === 0 || state.dataZoomIndex === 1;
|
||||
}
|
||||
|
||||
export function HistoryChart({
|
||||
edge,
|
||||
from,
|
||||
@@ -49,7 +53,12 @@ export function HistoryChart({
|
||||
);
|
||||
|
||||
const handleDataZoom = useCallback((event: DataZoomEventBatch) => {
|
||||
const state = event.batch?.[0] ?? event;
|
||||
const state = (event.batch ?? [event]).find(isXAxisDataZoom);
|
||||
|
||||
if (!state) {
|
||||
return;
|
||||
}
|
||||
|
||||
dataZoomRef.current = {
|
||||
start: state.start,
|
||||
end: state.end,
|
||||
|
||||
@@ -8,6 +8,8 @@ export type TooltipParam = {
|
||||
};
|
||||
|
||||
export type DataZoomState = {
|
||||
dataZoomId?: string;
|
||||
dataZoomIndex?: number;
|
||||
start?: number;
|
||||
end?: number;
|
||||
startValue?: number;
|
||||
|
||||
@@ -60,6 +60,19 @@ function formatChartValue(value: number): string {
|
||||
}).format(value);
|
||||
}
|
||||
|
||||
/** Показывает одно значение, если min/avg/max визуально совпадают. */
|
||||
function formatTooltipValue(value: AvgPointValue): string {
|
||||
const avg = formatChartValue(value[1]);
|
||||
const min = formatChartValue(value[2]);
|
||||
const max = formatChartValue(value[3]);
|
||||
|
||||
if (min === avg && avg === max) {
|
||||
return avg;
|
||||
}
|
||||
|
||||
return `min ${min} · avg ${avg} · max ${max}`;
|
||||
}
|
||||
|
||||
function isAvgPointValue(value: unknown): value is AvgPointValue {
|
||||
return Array.isArray(value) && value.length >= 5 && value.every((item) => typeof item === 'number');
|
||||
}
|
||||
@@ -91,7 +104,7 @@ export function formatTooltip(params: unknown): string {
|
||||
'<div class="chart-tooltip-row">',
|
||||
`<span class="chart-tooltip-label" style="--chart-tooltip-marker-color:${item.color ?? 'currentColor'};">${item.seriesName ?? ''}</span>`,
|
||||
'<strong>',
|
||||
`min ${formatChartValue(value[2])} · avg ${formatChartValue(value[1])} · max ${formatChartValue(value[3])}`,
|
||||
formatTooltipValue(value),
|
||||
value[4] > 1 ? ` · ${value[4]} точек` : '',
|
||||
'</strong>',
|
||||
'</div>',
|
||||
|
||||
@@ -54,7 +54,7 @@ export function createHistoryChartOptions({
|
||||
grid: {
|
||||
top: 54,
|
||||
left: 48,
|
||||
right: 24,
|
||||
right: 56,
|
||||
bottom: 72,
|
||||
},
|
||||
xAxis: {
|
||||
@@ -79,7 +79,9 @@ export function createHistoryChartOptions({
|
||||
},
|
||||
dataZoom: [
|
||||
{
|
||||
id: 'history-x-inside',
|
||||
type: 'inside',
|
||||
xAxisIndex: 0,
|
||||
throttle: 80,
|
||||
start: dataZoomState.start,
|
||||
end: dataZoomState.end,
|
||||
@@ -87,7 +89,9 @@ export function createHistoryChartOptions({
|
||||
endValue: dataZoomState.endValue,
|
||||
},
|
||||
{
|
||||
id: 'history-x-slider',
|
||||
type: 'slider',
|
||||
xAxisIndex: 0,
|
||||
bottom: 18,
|
||||
height: 28,
|
||||
borderColor: 'rgba(148, 163, 184, 0.24)',
|
||||
@@ -102,6 +106,28 @@ export function createHistoryChartOptions({
|
||||
startValue: dataZoomState.startValue,
|
||||
endValue: dataZoomState.endValue,
|
||||
},
|
||||
{
|
||||
id: 'history-y-inside',
|
||||
type: 'inside',
|
||||
yAxisIndex: 0,
|
||||
filterMode: 'none',
|
||||
throttle: 80,
|
||||
},
|
||||
{
|
||||
id: 'history-y-slider',
|
||||
type: 'slider',
|
||||
yAxisIndex: 0,
|
||||
filterMode: 'none',
|
||||
right: 8,
|
||||
width: 12,
|
||||
borderColor: 'rgba(148, 163, 184, 0.24)',
|
||||
fillerColor: 'rgba(91, 143, 249, 0.18)',
|
||||
handleStyle: {
|
||||
color: '#d4a574',
|
||||
borderColor: '#e8c9a0',
|
||||
},
|
||||
textStyle: { color: '#94a3b8' },
|
||||
},
|
||||
],
|
||||
series,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user