| | |
| | | import { stepCurveChartOption } from './stepCurveChart' |
| | | import type { PersistedTestRecord } from '@/api/tests' |
| | | import { toTestDisplayValue } from './testDataUnits' |
| | | |
| | |
| | | const value = row[field[metric.key]] |
| | | return [[(Number(time) - item.zeroTime) / 1000, value == null ? null : toTestDisplayValue(metric.key, Number(value))] as [number, number | null]] |
| | | }).sort((left, right) => left[0] - right[0])) |
| | | const [dataMin, dataMax] = series.reduce<[number, number]>(([min, max], points) => points.reduce<[number, number]>(([low, high], [, value]) => |
| | | value === null ? [low, high] : [Math.min(low, value), Math.max(high, value)], [min, max]), [0, 0]) |
| | | const range = Math.max(dataMax - dataMin, 1) |
| | | const timeMax = series.reduce((max, points) => points.reduce((value, [time]) => Math.max(value, time), max), 0) |
| | | const timeUnit = timeMax >= 3600 ? 3600 : timeMax >= 180 ? 60 : 1 |
| | | const timeLabel = timeUnit === 3600 ? 'h' : timeUnit === 60 ? 'min' : 's' |
| | | const axisMax = Math.max(metric.unit === '℃' ? Math.ceil(dataMax / 10) * 10 : Math.ceil(dataMax * 10) / 10, 1) |
| | | const yAxis = (position: 'left' | 'right') => ({ |
| | | type: 'value', name: metric.unit, position, min: dataMin - range * 0.05, max: axisMax, |
| | | nameTextStyle: { color: '#8795a3', fontSize: 10 }, |
| | | axisLine: { show: true, lineStyle: { color: '#cbd8e4' } }, |
| | | axisTick: { show: true, lineStyle: { color: '#cbd8e4' } }, |
| | | splitLine: { show: position === 'left', lineStyle: { color: '#e8eef4' } }, |
| | | axisLabel: { color: '#8795a3', fontSize: 10, formatter: (value: number) => Number(value.toPrecision(6)).toString() }, |
| | | }) |
| | | return { |
| | | animation: false, color: colors, grid: { top: 40, right: 32, bottom: 42, left: 32, containLabel: true }, |
| | | tooltip: { trigger: 'axis' }, legend: { show: false }, |
| | | xAxis: { type: 'value', min: 0, max: timeMax > 0 ? timeMax : undefined, splitNumber: 4, name: `相对时间 / ${timeLabel}`, nameLocation: 'middle', nameGap: 28, |
| | | axisLine: { lineStyle: { color: '#cbd8e4' } }, axisLabel: { color: '#8795a3', fontSize: 10, hideOverlap: true, |
| | | formatter: (value: number) => Number((value / timeUnit).toFixed(3)).toString() }, |
| | | nameTextStyle: { color: '#26333f', fontSize: 11, fontWeight: 600 } }, |
| | | yAxis: [yAxis('left'), yAxis('right')], |
| | | // 全部冻结点先参与坐标计算;隐藏仅控制渲染,不重算零点、不缩短范围、不移动其他来源颜色。 |
| | | series: items.flatMap((item, index) => item.hidden ? [] : [{ name: item.name, type: 'line', smooth: false, |
| | | connectNulls: false, showSymbol: true, symbolSize: 5, itemStyle: { color: colors[index % colors.length] }, |
| | | lineStyle: { width: 2, color: colors[index % colors.length] }, data: series[index] || [] }]), |
| | | } |
| | | return stepCurveChartOption(metric, items.map((item, index) => ({ name: item.name, hidden: item.hidden, points: series[index] || [] })), colors) |
| | | } |