feat(chart): 增加炮号并优化 Tooltip 展示
All checks were successful
Package component / package (push) Successful in 4m5s
All checks were successful
Package component / package (push) Successful in 4m5s
新增 WaveformSeries.shotNo 字段,Tooltip 展示炮号及坐标信息,并同步示例与测试。
This commit is contained in:
@@ -163,8 +163,8 @@ const points: WaveformData = {
|
|||||||
const chartData: WaveformData = {
|
const chartData: WaveformData = {
|
||||||
kind: 'series',
|
kind: 'series',
|
||||||
series: [
|
series: [
|
||||||
{ id: 'ch-a', name: '通道 A', trackId: 'group-1', data: samples },
|
{ id: 'ch-a', shotNo: '13300', name: '通道 A', trackId: 'group-1', data: samples },
|
||||||
{ id: 'ch-b', name: '通道 B', trackId: 'group-1', data: points },
|
{ id: 'ch-b', shotNo: '13300', name: '通道 B', trackId: 'group-1', data: points },
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -281,6 +281,9 @@ X 轴且包含多个轨道时使用按稳定 track ID 索引的 `yRanges`。平
|
|||||||
多通道数据应为每个 `WaveformSeries` 提供稳定的 `id`。内部时间坐标始终使用秒,
|
多通道数据应为每个 `WaveformSeries` 提供稳定的 `id`。内部时间坐标始终使用秒,
|
||||||
`timeUnit` 只控制坐标轴和 tooltip 的显示单位。
|
`timeUnit` 只控制坐标轴和 tooltip 的显示单位。
|
||||||
|
|
||||||
|
Tooltip 每个系列按 `炮号:通道 (x:值 y:值)` 格式显示。`WaveformSeries.shotNo` 为空或未提供时,
|
||||||
|
炮号显示为“未配置炮号”;Tooltip 不显示单位和误差附加文本。
|
||||||
|
|
||||||
### 线型、点型与误差棒
|
### 线型、点型与误差棒
|
||||||
|
|
||||||
每条序列可以独立设置连线方式、数据点符号和误差棒:
|
每条序列可以独立设置连线方式、数据点符号和误差棒:
|
||||||
@@ -288,6 +291,7 @@ X 轴且包含多个轨道时使用按稳定 track ID 索引的 `yRanges`。平
|
|||||||
```ts
|
```ts
|
||||||
const series = {
|
const series = {
|
||||||
id: 'temperature',
|
id: 'temperature',
|
||||||
|
shotNo: '13300',
|
||||||
name: '温度',
|
name: '温度',
|
||||||
lineType: 'step-end',
|
lineType: 'step-end',
|
||||||
lineStyle: 'dashed',
|
lineStyle: 'dashed',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "waveform-analysis",
|
"name": "waveform-analysis",
|
||||||
"version": "0.1.35",
|
"version": "0.1.36",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
"types": "./dist/types/index.d.ts",
|
"types": "./dist/types/index.d.ts",
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import type { NormalizedWaveformGridLineOptions } from './grid'
|
|||||||
*/
|
*/
|
||||||
export interface DisplaySeries {
|
export interface DisplaySeries {
|
||||||
id: string
|
id: string
|
||||||
|
shotNo?: string
|
||||||
trackId?: string
|
trackId?: string
|
||||||
name: string
|
name: string
|
||||||
unit?: string
|
unit?: string
|
||||||
@@ -63,6 +64,7 @@ export interface WaveformYAxisLayout {
|
|||||||
*/
|
*/
|
||||||
export interface HoveredSeriesPoint {
|
export interface HoveredSeriesPoint {
|
||||||
id: string
|
id: string
|
||||||
|
shotNo?: string
|
||||||
name: string
|
name: string
|
||||||
unit?: string
|
unit?: string
|
||||||
color: string
|
color: string
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ describe('WaveformTooltip', () => {
|
|||||||
expect(tooltip.attributes('style')).toContain('max-width: 280px')
|
expect(tooltip.attributes('style')).toContain('max-width: 280px')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows resolved asymmetric errors beside the hovered value', () => {
|
it('omits units and errors from the strict x/y value format', () => {
|
||||||
const pointWithErrors = { x: 1, y: 12, error: 1, upperError: 2 }
|
const pointWithErrors = { x: 1, y: 12, error: 1, upperError: 2 }
|
||||||
const wrapper = mount(WaveformTooltip, {
|
const wrapper = mount(WaveformTooltip, {
|
||||||
props: {
|
props: {
|
||||||
@@ -102,10 +102,12 @@ describe('WaveformTooltip', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(wrapper.get('.waveform-tooltip__series small').text()).toBe('(+2 / -1)')
|
expect(wrapper.get('.waveform-tooltip__value').text()).toBe('(x:1 y:12)')
|
||||||
|
expect(wrapper.get('.waveform-tooltip__value').text()).not.toContain('C')
|
||||||
|
expect(wrapper.get('.waveform-tooltip__value').text()).not.toContain('+2')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('keeps a formatted value and its unit in one value container', () => {
|
it('renders the configured shot number, channel, and formatted coordinates', () => {
|
||||||
const hoveredPoint = { x: 1, y: -1405.4932 }
|
const hoveredPoint = { x: 1, y: -1405.4932 }
|
||||||
const wrapper = mount(WaveformTooltip, {
|
const wrapper = mount(WaveformTooltip, {
|
||||||
props: {
|
props: {
|
||||||
@@ -117,6 +119,7 @@ describe('WaveformTooltip', () => {
|
|||||||
{
|
{
|
||||||
trackIndex: 0,
|
trackIndex: 0,
|
||||||
name: 'ENG8KJXAc(10001)',
|
name: 'ENG8KJXAc(10001)',
|
||||||
|
shotNo: '炮 7',
|
||||||
color: '#ffb43b',
|
color: '#ffb43b',
|
||||||
unit: 'A',
|
unit: 'A',
|
||||||
point: hoveredPoint,
|
point: hoveredPoint,
|
||||||
@@ -127,26 +130,31 @@ describe('WaveformTooltip', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(wrapper.get('.waveform-tooltip__value').text()).toBe('-1,405.4932 A')
|
expect(wrapper.get('.waveform-tooltip__series-label').text()).toBe('炮 7: ENG8KJXAc(10001)(A)')
|
||||||
|
expect(wrapper.get('.waveform-tooltip__value').text()).toBe('(x:1,000 y:-1,405.4932)')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('formats tooltip time with at most four decimal places', () => {
|
it('renders each series row with the formatted x coordinate and series label', () => {
|
||||||
const wrapper = mount(WaveformTooltip, {
|
const wrapper = mount(WaveformTooltip, {
|
||||||
props: {
|
props: {
|
||||||
visible: true,
|
visible: true,
|
||||||
position: { x: 10, y: 10 },
|
position: { x: 10, y: 10 },
|
||||||
timeUnit: 's',
|
timeUnit: 's',
|
||||||
hoveredPoint: { x: 1.234567, y: 12 },
|
hoveredPoint: { x: 1.234567, y: 12 },
|
||||||
seriesPoints: [],
|
seriesPoints: [
|
||||||
|
{ trackIndex: 0, name: '温度', color: '#f00', point: { x: 1.234567, y: 12 } },
|
||||||
|
],
|
||||||
containerWidth: 400,
|
containerWidth: 400,
|
||||||
containerHeight: 300,
|
containerHeight: 300,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(wrapper.get('.waveform-tooltip__time').text()).toBe('s: 1.2346')
|
expect(wrapper.find('.waveform-tooltip__time').exists()).toBe(false)
|
||||||
|
expect(wrapper.get('.waveform-tooltip__series-label').text()).toBe('未配置炮号: 温度')
|
||||||
|
expect(wrapper.get('.waveform-tooltip__value').text()).toBe('(x:1.2346 y:12)')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('omits the error label when both resolved errors are zero', () => {
|
it('uses the fallback shot number when shotNo is blank', () => {
|
||||||
const point = { x: 1, y: 12 }
|
const point = { x: 1, y: 12 }
|
||||||
const wrapper = mount(WaveformTooltip, {
|
const wrapper = mount(WaveformTooltip, {
|
||||||
props: {
|
props: {
|
||||||
@@ -160,6 +168,6 @@ describe('WaveformTooltip', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(wrapper.find('.waveform-tooltip__series small').exists()).toBe(false)
|
expect(wrapper.get('.waveform-tooltip__series-label').text()).toBe('未配置炮号: 温度')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { resolveWaveformPointErrors } from '../../core'
|
|
||||||
import { formatTooltipNumber, formatTooltipTime } from '../../utils'
|
import { formatTooltipNumber, formatTooltipTime } from '../../utils'
|
||||||
import type { WaveformPoint } from '../data/types'
|
import type { WaveformPoint } from '../data/types'
|
||||||
|
|
||||||
interface SeriesPoint {
|
interface SeriesPoint {
|
||||||
trackIndex: number
|
trackIndex: number
|
||||||
name: string
|
name: string
|
||||||
|
shotNo?: string
|
||||||
color: string
|
color: string
|
||||||
unit?: string
|
unit?: string
|
||||||
point: WaveformPoint
|
point: WaveformPoint
|
||||||
@@ -34,7 +34,7 @@ const props = defineProps<Props>()
|
|||||||
const tooltipGap = 12
|
const tooltipGap = 12
|
||||||
const containerPadding = 8
|
const containerPadding = 8
|
||||||
const tooltipPlacementWidth = 238
|
const tooltipPlacementWidth = 238
|
||||||
const tooltipMaxWidth = 320
|
const tooltipMaxWidth = 560
|
||||||
const tooltipHorizontalPadding = 20
|
const tooltipHorizontalPadding = 20
|
||||||
const tooltipLineHeight = 20
|
const tooltipLineHeight = 20
|
||||||
|
|
||||||
@@ -45,18 +45,18 @@ function estimateLineCount(text: string, width: number): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatSeriesText(seriesPoint: SeriesPoint): string {
|
function formatSeriesText(seriesPoint: SeriesPoint): string {
|
||||||
const error = formatError(seriesPoint.point)
|
const timeText = formatTooltipTime(props.hoveredPoint?.x ?? seriesPoint.point.x, props.timeUnit)
|
||||||
return `${seriesPoint.name ? `${seriesPoint.name}: ` : ''}${formatTooltipNumber(seriesPoint.point.y)}${
|
return `${seriesPoint.shotNo?.trim() || '未配置炮号'}: ${seriesPoint.name}${
|
||||||
seriesPoint.unit ? ` ${seriesPoint.unit}` : ''
|
seriesPoint.unit ? `(${seriesPoint.unit})` : ''
|
||||||
}${error ? ` ${error}` : ''}`
|
} (x:${timeText} y:${formatTooltipNumber(seriesPoint.point.y)})`
|
||||||
}
|
}
|
||||||
|
|
||||||
function estimateTooltipHeight(width: number, timeText: string): number {
|
function estimateTooltipHeight(width: number): number {
|
||||||
const seriesLines = props.seriesPoints.reduce(
|
const seriesLines = props.seriesPoints.reduce(
|
||||||
(total, seriesPoint) => total + estimateLineCount(formatSeriesText(seriesPoint), width),
|
(total, seriesPoint) => total + estimateLineCount(formatSeriesText(seriesPoint), width),
|
||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
return 16 + tooltipLineHeight * (estimateLineCount(timeText, width) + seriesLines) + 5
|
return 16 + tooltipLineHeight * seriesLines + 5
|
||||||
}
|
}
|
||||||
|
|
||||||
const tooltipStyle = computed(() => {
|
const tooltipStyle = computed(() => {
|
||||||
@@ -84,25 +84,18 @@ const tooltipStyle = computed(() => {
|
|||||||
: { left: `${containerPadding}px`, maxWidth: `${availableWidth}px` }
|
: { left: `${containerPadding}px`, maxWidth: `${availableWidth}px` }
|
||||||
|
|
||||||
const maxWidth = Number.parseFloat(horizontalStyle.maxWidth)
|
const maxWidth = Number.parseFloat(horizontalStyle.maxWidth)
|
||||||
const timeText = `${props.timeUnit}: ${formatTooltipTime(props.hoveredPoint.x, props.timeUnit)}`
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...horizontalStyle,
|
...horizontalStyle,
|
||||||
top: `${Math.max(
|
top: `${Math.max(
|
||||||
8,
|
8,
|
||||||
Math.min(
|
Math.min(
|
||||||
props.position.y - 18,
|
props.position.y - 18,
|
||||||
props.containerHeight - estimateTooltipHeight(maxWidth, timeText) - 8,
|
props.containerHeight - estimateTooltipHeight(maxWidth) - 8,
|
||||||
),
|
),
|
||||||
)}px`,
|
)}px`,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function formatError(point: WaveformPoint): string | null {
|
|
||||||
const { lower, upper } = resolveWaveformPointErrors(point)
|
|
||||||
if (lower === 0 && upper === 0) return null
|
|
||||||
return `(+${formatTooltipNumber(upper)} / -${formatTooltipNumber(lower)})`
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -111,9 +104,6 @@ function formatError(point: WaveformPoint): string | null {
|
|||||||
class="waveform-tooltip waveform-chart__tooltip"
|
class="waveform-tooltip waveform-chart__tooltip"
|
||||||
:style="tooltipStyle"
|
:style="tooltipStyle"
|
||||||
>
|
>
|
||||||
<span class="waveform-tooltip__time waveform-chart__tooltip-time">
|
|
||||||
{{ timeUnit }}: {{ formatTooltipTime(hoveredPoint.x, timeUnit) }}
|
|
||||||
</span>
|
|
||||||
<span
|
<span
|
||||||
v-for="seriesPoint in seriesPoints"
|
v-for="seriesPoint in seriesPoints"
|
||||||
:key="`${seriesPoint.trackIndex}-${seriesPoint.name}`"
|
:key="`${seriesPoint.trackIndex}-${seriesPoint.name}`"
|
||||||
@@ -121,12 +111,12 @@ function formatError(point: WaveformPoint): string | null {
|
|||||||
>
|
>
|
||||||
<i :style="{ backgroundColor: seriesPoint.color }" />
|
<i :style="{ backgroundColor: seriesPoint.color }" />
|
||||||
<span class="waveform-tooltip__series-content">
|
<span class="waveform-tooltip__series-content">
|
||||||
<strong v-if="seriesPoint.name">{{ seriesPoint.name }}:</strong>
|
<span class="waveform-tooltip__series-label">{{ seriesPoint.shotNo?.trim() || '未配置炮号' }}: {{
|
||||||
<span class="waveform-tooltip__value">
|
seriesPoint.name
|
||||||
{{ formatTooltipNumber(seriesPoint.point.y)
|
}}<template v-if="seriesPoint.unit">({{ seriesPoint.unit }})</template></span>
|
||||||
}}{{ seriesPoint.unit ? ` ${seriesPoint.unit}` : '' }}
|
<span class="waveform-tooltip__value">(x:{{ formatTooltipTime(hoveredPoint.x, timeUnit) }} y:{{
|
||||||
<small v-if="formatError(seriesPoint.point)">{{ formatError(seriesPoint.point) }}</small>
|
formatTooltipNumber(seriesPoint.point.y)
|
||||||
</span>
|
}})</span>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -138,26 +128,17 @@ function formatError(point: WaveformPoint): string | null {
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 3px;
|
gap: 2px;
|
||||||
width: max-content;
|
width: max-content;
|
||||||
max-width: min(320px, calc(100% - 16px));
|
max-width: min(560px, calc(100% - 16px));
|
||||||
padding: 8px 10px;
|
padding: 9px 12px;
|
||||||
color: #333;
|
color: #505050;
|
||||||
font:
|
font: 14px/1.35 Arial, sans-serif;
|
||||||
12px/1.45 ui-monospace,
|
|
||||||
SFMono-Regular,
|
|
||||||
Consolas,
|
|
||||||
monospace;
|
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border: 1px solid #d9d9d9;
|
border: 1px solid #e3e7eb;
|
||||||
border-radius: 2px;
|
border-radius: 4px;
|
||||||
box-shadow: 0 4px 12px rgb(16 24 40 / 12%);
|
box-shadow: 0 3px 10px rgb(16 24 40 / 15%);
|
||||||
}
|
|
||||||
|
|
||||||
.waveform-tooltip__time {
|
|
||||||
padding-bottom: 4px;
|
|
||||||
border-bottom: 1px solid #f0f0f0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.waveform-tooltip__series {
|
.waveform-tooltip__series {
|
||||||
@@ -176,9 +157,24 @@ function formatError(point: WaveformPoint): string | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.waveform-tooltip__series-content {
|
.waveform-tooltip__series-content {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
gap: 12px;
|
||||||
|
align-items: baseline;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
overflow-wrap: anywhere;
|
}
|
||||||
white-space: normal;
|
|
||||||
|
.waveform-tooltip__series-label {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.waveform-tooltip__value {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.waveform-tooltip__series strong {
|
.waveform-tooltip__series strong {
|
||||||
@@ -186,7 +182,7 @@ function formatError(point: WaveformPoint): string | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.waveform-tooltip__value {
|
.waveform-tooltip__value {
|
||||||
overflow-wrap: anywhere;
|
color: #555;
|
||||||
}
|
}
|
||||||
|
|
||||||
.waveform-tooltip__series small {
|
.waveform-tooltip__series small {
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ export function useWaveformHover(context: HoverContext) {
|
|||||||
point: WaveformPoint,
|
point: WaveformPoint,
|
||||||
): HoveredSeriesPoint => ({
|
): HoveredSeriesPoint => ({
|
||||||
id: series.id,
|
id: series.id,
|
||||||
|
shotNo: series.shotNo,
|
||||||
name: series.name,
|
name: series.name,
|
||||||
color: series.color,
|
color: series.color,
|
||||||
unit: series.unit,
|
unit: series.unit,
|
||||||
|
|||||||
@@ -179,10 +179,10 @@ describe('WaveformChart', () => {
|
|||||||
await flushPromises()
|
await flushPromises()
|
||||||
|
|
||||||
const tooltip = wrapper.get('.waveform-chart__tooltip')
|
const tooltip = wrapper.get('.waveform-chart__tooltip')
|
||||||
expect(tooltip.text()).toContain('BT2_2M:')
|
expect(tooltip.text()).toContain('未配置炮号: BT2_2M')
|
||||||
expect(tooltip.text()).toContain('2 T')
|
expect(tooltip.text()).toContain('(x:1,000 y:2)')
|
||||||
expect(tooltip.text()).toContain('BT1_2M:')
|
expect(tooltip.text()).toContain('未配置炮号: BT1_2M')
|
||||||
expect(tooltip.text()).toContain('4 T')
|
expect(tooltip.text()).toContain('(x:1,000 y:4)')
|
||||||
const crosshairLines = wrapper.findAll('.waveform-chart__crosshair line')
|
const crosshairLines = wrapper.findAll('.waveform-chart__crosshair line')
|
||||||
expect(crosshairLines).toHaveLength(2)
|
expect(crosshairLines).toHaveLength(2)
|
||||||
crosshairLines.forEach((line) => {
|
crosshairLines.forEach((line) => {
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ describe('WaveformChart', () => {
|
|||||||
await flushPromises()
|
await flushPromises()
|
||||||
expect(wrapper.emitted('point-hover')?.at(-1)).toEqual([{ x: 1, y: 5 }])
|
expect(wrapper.emitted('point-hover')?.at(-1)).toEqual([{ x: 1, y: 5 }])
|
||||||
expect(wrapper.find('.waveform-chart__tooltip').exists()).toBe(true)
|
expect(wrapper.find('.waveform-chart__tooltip').exists()).toBe(true)
|
||||||
expect(wrapper.get('.waveform-chart__tooltip-time').text()).toBe('ms: 1,000')
|
expect(wrapper.get('.waveform-tooltip__series-label').text()).toContain('未配置炮号:')
|
||||||
const crosshairLines = wrapper.findAll('.waveform-chart__crosshair line')
|
const crosshairLines = wrapper.findAll('.waveform-chart__crosshair line')
|
||||||
expect(crosshairLines).toHaveLength(1)
|
expect(crosshairLines).toHaveLength(1)
|
||||||
expect(crosshairLines[0].attributes('x1')).toBe(crosshairLines[0].attributes('x2'))
|
expect(crosshairLines[0].attributes('x1')).toBe(crosshairLines[0].attributes('x2'))
|
||||||
@@ -303,7 +303,7 @@ describe('WaveformChart', () => {
|
|||||||
flushAnimationFrames()
|
flushAnimationFrames()
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
|
|
||||||
expect(wrapper.get('.waveform-chart__tooltip-time').text()).toBe('ms: 1,000')
|
expect(wrapper.get('.waveform-tooltip__series-label').text()).toContain('未配置炮号:')
|
||||||
expect(wrapper.findAll('.waveform-chart__crosshair line')).toHaveLength(1)
|
expect(wrapper.findAll('.waveform-chart__crosshair line')).toHaveLength(1)
|
||||||
expect(wrapper.get('.waveform-chart__line').element).toBe(pathBeforeHover)
|
expect(wrapper.get('.waveform-chart__line').element).toBe(pathBeforeHover)
|
||||||
expect(chartUpdate).not.toHaveBeenCalled()
|
expect(chartUpdate).not.toHaveBeenCalled()
|
||||||
|
|||||||
@@ -102,4 +102,26 @@ describe('waveform data normalization', () => {
|
|||||||
'solid',
|
'solid',
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('preserves trimmed shot numbers and omits blank values', () => {
|
||||||
|
const result = normalizeWaveformSeries({
|
||||||
|
kind: 'series',
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
id: 'with-shot',
|
||||||
|
shotNo: ' 13300 ',
|
||||||
|
name: '通道 A',
|
||||||
|
data: { kind: 'points', points: [{ x: 0, y: 1 }] },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'without-shot',
|
||||||
|
shotNo: ' ',
|
||||||
|
name: '通道 B',
|
||||||
|
data: { kind: 'points', points: [{ x: 0, y: 2 }] },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.map((series) => series.shotNo)).toEqual(['13300', undefined])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ export function normalizeWaveformSeries(data: WaveformData): NormalizedWaveformS
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
id: uniqueId,
|
id: uniqueId,
|
||||||
|
shotNo: series.shotNo?.trim() || undefined,
|
||||||
trackId: series.trackId?.trim() || undefined,
|
trackId: series.trackId?.trim() || undefined,
|
||||||
name: series.name,
|
name: series.name,
|
||||||
unit: series.unit,
|
unit: series.unit,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ describe('simulated waveform data', () => {
|
|||||||
|
|
||||||
expect(first.series).toHaveLength(6)
|
expect(first.series).toHaveLength(6)
|
||||||
expect(new Set(first.series.map((series) => series.id)).size).toBe(6)
|
expect(new Set(first.series.map((series) => series.id)).size).toBe(6)
|
||||||
|
expect(new Set(first.series.map((series) => series.shotNo))).toEqual(new Set(['13300']))
|
||||||
first.series.forEach((series) => {
|
first.series.forEach((series) => {
|
||||||
expect(series.data.kind).toBe('points')
|
expect(series.data.kind).toBe('points')
|
||||||
if (series.data.kind !== 'points') return
|
if (series.data.kind !== 'points') return
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ type ErrorGenerator = (
|
|||||||
|
|
||||||
interface SimulatedSeriesDefinition extends Pick<
|
interface SimulatedSeriesDefinition extends Pick<
|
||||||
WaveformSeries,
|
WaveformSeries,
|
||||||
'id' | 'name' | 'unit' | 'lineType' | 'pointType' | 'errorBar'
|
'id' | 'shotNo' | 'name' | 'unit' | 'lineType' | 'pointType' | 'errorBar'
|
||||||
> {
|
> {
|
||||||
signal: SignalGenerator
|
signal: SignalGenerator
|
||||||
errors?: ErrorGenerator
|
errors?: ErrorGenerator
|
||||||
@@ -46,6 +46,7 @@ function createPoints(
|
|||||||
const seriesDefinitions: SimulatedSeriesDefinition[] = [
|
const seriesDefinitions: SimulatedSeriesDefinition[] = [
|
||||||
{
|
{
|
||||||
id: 'simulated-sine',
|
id: 'simulated-sine',
|
||||||
|
shotNo: '13300',
|
||||||
name: '正弦基波',
|
name: '正弦基波',
|
||||||
unit: 'V',
|
unit: 'V',
|
||||||
lineType: 'none',
|
lineType: 'none',
|
||||||
@@ -59,6 +60,7 @@ const seriesDefinitions: SimulatedSeriesDefinition[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'simulated-harmonic',
|
id: 'simulated-harmonic',
|
||||||
|
shotNo: '13300',
|
||||||
name: '谐波扰动',
|
name: '谐波扰动',
|
||||||
unit: 'V',
|
unit: 'V',
|
||||||
lineType: 'linear',
|
lineType: 'linear',
|
||||||
@@ -68,6 +70,7 @@ const seriesDefinitions: SimulatedSeriesDefinition[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'simulated-damped',
|
id: 'simulated-damped',
|
||||||
|
shotNo: '13300',
|
||||||
name: '阻尼振荡',
|
name: '阻尼振荡',
|
||||||
unit: 'A',
|
unit: 'A',
|
||||||
lineType: 'linear',
|
lineType: 'linear',
|
||||||
@@ -79,6 +82,7 @@ const seriesDefinitions: SimulatedSeriesDefinition[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'simulated-step',
|
id: 'simulated-step',
|
||||||
|
shotNo: '13300',
|
||||||
name: '阶跃响应',
|
name: '阶跃响应',
|
||||||
unit: 'V',
|
unit: 'V',
|
||||||
lineType: 'linear',
|
lineType: 'linear',
|
||||||
@@ -87,6 +91,7 @@ const seriesDefinitions: SimulatedSeriesDefinition[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'simulated-pulse',
|
id: 'simulated-pulse',
|
||||||
|
shotNo: '13300',
|
||||||
name: '脉冲响应',
|
name: '脉冲响应',
|
||||||
unit: 'V',
|
unit: 'V',
|
||||||
lineType: 'linear',
|
lineType: 'linear',
|
||||||
@@ -95,6 +100,7 @@ const seriesDefinitions: SimulatedSeriesDefinition[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'simulated-noise',
|
id: 'simulated-noise',
|
||||||
|
shotNo: '13300',
|
||||||
name: '带噪信号',
|
name: '带噪信号',
|
||||||
unit: 'A',
|
unit: 'A',
|
||||||
lineType: 'linear',
|
lineType: 'linear',
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ export type SingleWaveformData =
|
|||||||
*/
|
*/
|
||||||
export interface WaveformSeries {
|
export interface WaveformSeries {
|
||||||
id?: string
|
id?: string
|
||||||
|
/** 炮号,未提供时 Tooltip 显示“未配置炮号”。 */
|
||||||
|
shotNo?: string
|
||||||
/** 相同 trackId 的系列叠加在同一图框中;默认每个系列独占一个图框。 */
|
/** 相同 trackId 的系列叠加在同一图框中;默认每个系列独占一个图框。 */
|
||||||
trackId?: string
|
trackId?: string
|
||||||
name: string
|
name: string
|
||||||
@@ -74,6 +76,7 @@ export type WaveformData =
|
|||||||
*/
|
*/
|
||||||
export interface NormalizedWaveformSeries {
|
export interface NormalizedWaveformSeries {
|
||||||
id: string
|
id: string
|
||||||
|
shotNo?: string
|
||||||
trackId?: string
|
trackId?: string
|
||||||
name: string
|
name: string
|
||||||
unit?: string
|
unit?: string
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const chartData: WaveformData = {
|
|||||||
series: [
|
series: [
|
||||||
{
|
{
|
||||||
id: 'voltage',
|
id: 'voltage',
|
||||||
|
shotNo: '13300',
|
||||||
name: '电压',
|
name: '电压',
|
||||||
unit: 'V',
|
unit: 'V',
|
||||||
color: '#1677ff',
|
color: '#1677ff',
|
||||||
@@ -33,6 +34,7 @@ const chartData: WaveformData = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'current',
|
id: 'current',
|
||||||
|
shotNo: '13300',
|
||||||
name: '电流',
|
name: '电流',
|
||||||
unit: 'mA',
|
unit: 'mA',
|
||||||
color: '#d4380d',
|
color: '#d4380d',
|
||||||
|
|||||||
Reference in New Issue
Block a user