4 Commits

Author SHA1 Message Date
李启源
3692e21dbc feat(chart): 增加炮号并优化 Tooltip 展示
All checks were successful
Package component / package (push) Successful in 4m5s
新增 WaveformSeries.shotNo 字段,Tooltip 展示炮号及坐标信息,并同步示例与测试。
2026-08-17 10:14:44 +08:00
李启源
54477ecbbd fix(ci): checkout release archive without git pack
All checks were successful
Package component / package (push) Successful in 6m22s
2026-08-13 22:03:57 +08:00
李启源
d349220395 fix(ci): avoid shallow tag pack checkout
Some checks failed
Package component / package (push) Failing after 2s
2026-08-13 21:56:58 +08:00
李启源
81f36bde71 feat(chart): support explicit nice x domains
Some checks failed
Package component / package (push) Failing after 3s
2026-08-13 21:51:49 +08:00
29 changed files with 381 additions and 84 deletions

View File

@@ -15,12 +15,13 @@ jobs:
run: |
set -euo pipefail
server_url="${{ gitea.server_url }}"
repository_url="${server_url%/}/${{ gitea.repository }}.git"
tag_name="${{ gitea.ref_name }}"
git init .
git remote add origin "$repository_url"
git fetch --depth 1 origin "refs/tags/$tag_name:refs/tags/$tag_name"
git checkout --detach "$tag_name^{commit}"
archive_url="${server_url%/}/api/v1/repos/${{ gitea.repository }}/archive/$tag_name.tar.gz"
curl --fail --show-error --silent --location "$archive_url" --output source.tar.gz
mkdir source
tar -xzf source.tar.gz --strip-components=1 -C source
cp -a source/. .
rm -rf source source.tar.gz
- name: Set up pnpm
run: |
@@ -214,7 +215,7 @@ jobs:
: "${RELEASE_TOKEN:?RELEASE_TOKEN is required}"
server_url="${{ gitea.server_url }}"
api_url="$server_url/api/v1/repos/${{ gitea.repository }}/releases"
target_commitish="$(git rev-parse HEAD)"
target_commitish="$TAG_NAME"
node - "$TAG_NAME" "$PACKAGE_VERSION" "$target_commitish" "$IS_PRERELEASE" > release.json <<'NODE'
const [tagName, packageVersion, targetCommitish, prerelease] = process.argv.slice(2)

View File

@@ -111,6 +111,7 @@ const data = ref<WaveformData>({
| `minVisiblePoints` | `number` | `0` | 缩放后至少保留的不同 X 坐标数 |
| `initialXDomain` | `[number, number]` | 未设置 | 所有图框的初始 X 范围 |
| `initialXDomains` | `Record<string, [number, number]>` | 未设置 | 按 track/series ID 配置初始范围 |
| `xDomainStrategy` | `WaveformXDomainStrategy` | `{ type: 'data' }` | 自动 X 轴视口范围策略 |
| `yDomain` | `[number, number]` | 未设置 | 所有波形的固定 Y 轴范围 |
| `yDomains` | `Record<string, [number, number]>` | 未设置 | 按 track/series ID 配置固定范围 |
| `grid` | `WaveformGridOptions` | `{ rowCount: 2, columnCount: 1, showPagination: true }` | 网格和分页 |
@@ -129,7 +130,7 @@ const data = ref<WaveformData>({
所有公开类型均可从包入口导入,例如 `WaveformData``WaveformSeries`
`WaveformAnnotation``WaveformLineStyle``WaveformRenderingOptions`
`WaveformAxesOptions``WaveformXAxisLabelFormatter``WaveformZeroLineOptions`
`WaveformAxesOptions``WaveformXAxisLabelFormatter``WaveformXDomainStrategy``WaveformZeroLineOptions`
`WaveformGridOptions``WaveformGridTrackLines`
### 数据结构
@@ -162,8 +163,8 @@ const points: WaveformData = {
const chartData: WaveformData = {
kind: 'series',
series: [
{ id: 'ch-a', name: '通道 A', trackId: 'group-1', data: samples },
{ id: 'ch-b', name: '通道 B', trackId: 'group-1', data: points },
{ id: 'ch-a', shotNo: '13300', name: '通道 A', trackId: 'group-1', data: samples },
{ id: 'ch-b', shotNo: '13300', name: '通道 B', trackId: 'group-1', data: points },
],
}
```
@@ -252,6 +253,26 @@ X 轴且包含多个轨道时使用按稳定 track ID 索引的 `yRanges`。平
重置组件内部缩放并触发 `zoom-reset`;调用方应在事件中取消区间请求并恢复首次完整数据。
外部重置按钮也可以通过模板引用调用组件公开的 `resetViewport()` 方法,然后执行相同的数据恢复逻辑。
没有显式配置初始范围时,可以通过 `xDomainStrategy` 将数据范围扩展为便于阅读的视口端点。
默认的 `{ type: 'data' }` 保持数据最小值和最大值不变;`type: 'nice'` 使用固定刻度数量计算
易读边界且只扩展视口不修改原始点位、tooltip、标注或缩放事件值
```vue
<WaveformChart
:data="chartData"
:x-domain-strategy="{ type: 'nice', bounds: 'end', tickCount: 10, includeExplicit: true }"
/>
```
例如秒坐标数据范围为 `[0, 4.999999]``timeUnit='ms'` 时,上述配置会使用
`[0, 5]` 作为初始及重置视口,两端 label 显示 `0``5000``bounds: 'end'`
只扩展右端;默认的 `bounds: 'both'`
会同时扩展两端。`tickCount` 默认为 `10`,只参与边界计算,不随组件宽度变化。
`initialXDomains``initialXDomain` 的显式配置默认保持原值;仅当 `includeExplicit: true`
也应用 nice 扩展。独立模式在未配置显式范围时
按图框分别计算,共享 X 轴模式则合并所有可见图框后计算。所有范围仍使用原始秒坐标,
`timeUnit` 只影响显示。
独立坐标模式下,回填响应应只替换 `seriesIds` 对应的系列,并调用
`resetViewport(trackIndex)`;其他图框的数据和缩放状态应保持不变。独立模式下双击图框触发的
`zoom-reset` payload 会包含该图框的 `trackIndex``seriesIds`;共享 X 范围模式的 payload
@@ -260,6 +281,9 @@ X 轴且包含多个轨道时使用按稳定 track ID 索引的 `yRanges`。平
多通道数据应为每个 `WaveformSeries` 提供稳定的 `id`。内部时间坐标始终使用秒,
`timeUnit` 只控制坐标轴和 tooltip 的显示单位。
Tooltip 每个系列按 `炮号:通道 (x:值 y:值)` 格式显示。`WaveformSeries.shotNo` 为空或未提供时,
炮号显示为“未配置炮号”Tooltip 不显示单位和误差附加文本。
### 线型、点型与误差棒
每条序列可以独立设置连线方式、数据点符号和误差棒:
@@ -267,6 +291,7 @@ X 轴且包含多个轨道时使用按稳定 track ID 索引的 `yRanges`。平
```ts
const series = {
id: 'temperature',
shotNo: '13300',
name: '温度',
lineType: 'step-end',
lineStyle: 'dashed',

View File

@@ -1,6 +1,6 @@
{
"name": "waveform-analysis",
"version": "0.1.32",
"version": "0.1.36",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/types/index.d.ts",

View File

@@ -16,6 +16,7 @@ const props = withDefaults(defineProps<WaveformChartProps>(), {
zoomable: true,
pannable: false,
minVisiblePoints: 0,
xDomainStrategy: () => ({ type: 'data' }),
timeUnit: 'ms',
frameNumber: undefined,
annotations: () => [],

View File

@@ -16,6 +16,7 @@ import type {
WaveformDisplayMode,
WaveformOverlayMode,
WaveformPoint,
WaveformXDomainStrategy,
WaveformXAxisLabelFormatter,
} from '../../types'
import { buildMinorTicks, formatXAxisLabel } from '../../utils'
@@ -26,6 +27,7 @@ import {
} from './grid'
import { axisTextMetrics, resolveYAxisSeriesGroups } from './layout'
import type { DisplaySeries, DisplayTrack, TrackLayout, WaveformYAxisLayout } from './types'
import { applyXDomainStrategy } from './xDomain'
import {
Y_AXIS_LABEL_BAND_WIDTH,
Y_AXIS_LABEL_GAP,
@@ -46,6 +48,7 @@ export interface BuildTrackLayoutsOptions {
sharedZoomDomain: [number, number]
initialXDomain?: [number, number]
initialXDomains?: Record<string, [number, number]>
xDomainStrategy?: WaveformXDomainStrategy
fixedYDomain?: [number, number]
fixedYDomains?: Record<string, [number, number]>
yDomains?: Record<string, [number, number]>
@@ -57,6 +60,21 @@ export interface BuildTrackLayoutsOptions {
showCompactEmptyTracks: boolean
}
function resolveIndependentXDomain(
track: DisplayTrack,
seriesId: string,
options: BuildTrackLayoutsOptions,
): [number, number] {
const strategy = options.xDomainStrategy ?? { type: 'data' }
const explicitDomain =
options.initialXDomains?.[track.id] ??
options.initialXDomains?.[seriesId] ??
options.initialXDomain
return explicitDomain
? applyXDomainStrategy(explicitDomain, strategy, true)
: applyXDomainStrategy(track.xDomain, strategy)
}
export function buildTrackLayouts(options: BuildTrackLayoutsOptions): TrackLayout[] {
const visibleCells = options.cells.map((cell) => ({ ...cell, hasSeries: Boolean(cell.series) }))
const bottomCells = getBottomRowCellIndexes(visibleCells, options.grid.columnCount)
@@ -88,13 +106,7 @@ export function buildTrackLayouts(options: BuildTrackLayoutsOptions): TrackLayou
const series = displayTrack.visibleSeries[0] ?? displayTrack.series[0] ?? emptySeries
const baseXScale =
options.displayMode === 'independent'
? scaleLinear(
options.initialXDomains?.[displayTrack.id] ??
options.initialXDomains?.[series.id] ??
options.initialXDomain ??
displayTrack.xDomain,
[0, cell.width],
)
? scaleLinear(resolveIndependentXDomain(displayTrack, series.id, options), [0, cell.width])
: scaleLinear(options.sharedZoomDomain, [0, cell.width])
const transform =
options.displayMode === 'independent'

View File

@@ -13,6 +13,7 @@ import type { NormalizedWaveformGridLineOptions } from './grid'
*/
export interface DisplaySeries {
id: string
shotNo?: string
trackId?: string
name: string
unit?: string
@@ -63,6 +64,7 @@ export interface WaveformYAxisLayout {
*/
export interface HoveredSeriesPoint {
id: string
shotNo?: string
name: string
unit?: string
color: string

View File

@@ -204,6 +204,7 @@ export function useWaveformChartLifecycle(context: LifecycleContext) {
() => props.minVisiblePoints,
() => props.initialXDomain,
() => props.initialXDomains,
() => props.xDomainStrategy,
() => props.displayMode,
() => chartTracks.value.length,
currentPage,

View File

@@ -34,6 +34,7 @@ import {
import type { DisplaySeries, DisplayTrack, TrackLayout } from './types'
import type { PreparedWaveformSeries } from './useWaveformData'
import type { ResolvedWaveformChartProps } from './waveformChartTypes'
import { applyXDomainStrategy } from './xDomain'
import type { useWaveformAnnotationInteraction } from '../annotation'
interface LayoutContext {
@@ -224,9 +225,13 @@ export function useWaveformLayout(context: LayoutContext) {
Number.isFinite(domain[1]) &&
domain[0] !== domain[1]
) {
return domain[0] < domain[1] ? domain : [domain[1], domain[0]]
return applyXDomainStrategy(
domain[0] < domain[1] ? domain : [domain[1], domain[0]],
props.xDomainStrategy,
true,
)
}
return sharedXDomain.value
return applyXDomainStrategy(sharedXDomain.value, props.xDomainStrategy)
})
const resolveInitialTrackDomain = (track: TrackLayout): [number, number] => {
const configuredDomain =
@@ -239,11 +244,18 @@ export function useWaveformLayout(context: LayoutContext) {
Number.isFinite(configuredDomain[1]) &&
configuredDomain[0] !== configuredDomain[1]
) {
return configuredDomain[0] < configuredDomain[1]
? configuredDomain
: [configuredDomain[1], configuredDomain[0]]
return applyXDomainStrategy(
configuredDomain[0] < configuredDomain[1]
? configuredDomain
: [configuredDomain[1], configuredDomain[0]],
props.xDomainStrategy,
true,
)
}
return paddedDomain(track.seriesList.flatMap((series) => series.xDomain))
return applyXDomainStrategy(
paddedDomain(track.seriesList.flatMap((series) => series.xDomain)),
props.xDomainStrategy,
)
}
const sharedZoomDomain = computed(
() =>
@@ -272,6 +284,7 @@ export function useWaveformLayout(context: LayoutContext) {
sharedZoomDomain: sharedZoomDomain.value,
initialXDomain: props.initialXDomain ? initialXDomain.value : undefined,
initialXDomains: props.initialXDomains,
xDomainStrategy: props.xDomainStrategy,
fixedYDomain: props.yDomain,
fixedYDomains: props.yDomains,
yDomains:

View File

@@ -11,6 +11,7 @@ import type {
WaveformPoint,
WaveformRenderingOptions,
WaveformTitleOptions,
WaveformXDomainStrategy,
WaveformZeroLineOptions,
WaveformZoomEndPayload,
WaveformZoomResetPayload,
@@ -33,6 +34,7 @@ export interface WaveformChartProps {
minVisiblePoints?: number
initialXDomain?: [number, number]
initialXDomains?: Record<string, [number, number]>
xDomainStrategy?: WaveformXDomainStrategy
yDomain?: [number, number]
yDomains?: Record<string, [number, number]>
timeUnit?: 's' | 'ms'
@@ -63,6 +65,7 @@ type DefaultedProp =
| 'zoomable'
| 'pannable'
| 'minVisiblePoints'
| 'xDomainStrategy'
| 'timeUnit'
| 'annotations'
| 'annotationsVisible'

View File

@@ -0,0 +1,28 @@
import { describe, expect, it } from 'vitest'
import { applyXDomainStrategy } from './xDomain'
describe('applyXDomainStrategy', () => {
it('keeps the exact data domain by default', () => {
expect(applyXDomainStrategy([0, 4999.999], { type: 'data' })).toEqual([0, 4999.999])
})
it('expands both bounds to stable nice values', () => {
expect(applyXDomainStrategy([123, 456], { type: 'nice' })).toEqual([100, 500])
})
it('can expand only the end bound', () => {
expect(applyXDomainStrategy([123, 456], { type: 'nice', bounds: 'end' })).toEqual([123, 500])
})
it('keeps explicit domains exact unless they are included', () => {
expect(applyXDomainStrategy([123, 456], { type: 'nice' }, true)).toEqual([123, 456])
expect(applyXDomainStrategy([123, 456], { type: 'nice', includeExplicit: true }, true)).toEqual(
[100, 500],
)
})
it('falls back to the default tick count for invalid values', () => {
expect(applyXDomainStrategy([0, 4999.999], { type: 'nice', tickCount: 0 })).toEqual([0, 5000])
})
})

View File

@@ -0,0 +1,25 @@
import { scaleLinear } from 'd3'
import type { WaveformXDomainStrategy } from '../../types'
const DEFAULT_NICE_TICK_COUNT = 10
function resolveTickCount(value: number | undefined): number {
if (!Number.isFinite(value) || (value ?? 0) < 1) return DEFAULT_NICE_TICK_COUNT
return Math.max(1, Math.trunc(value as number))
}
/** Derives a viewport domain without changing any source coordinates. */
export function applyXDomainStrategy(
domain: [number, number],
strategy: WaveformXDomainStrategy,
explicit = false,
): [number, number] {
if (strategy.type !== 'nice' || (explicit && !strategy.includeExplicit)) return [...domain]
const niceDomain = scaleLinear()
.domain(domain)
.nice(resolveTickCount(strategy.tickCount))
.domain() as [number, number]
return strategy.bounds === 'end' ? [domain[0], niceDomain[1]] : niceDomain
}

View File

@@ -9,6 +9,7 @@ export type {
WaveformDisplayMode,
WaveformOverlayMode,
WaveformInteractionMode,
WaveformXDomainStrategy,
WaveformZoomEndPayload,
WaveformZoomResetPayload,
WaveformAnnotationStyle,

View File

@@ -80,7 +80,7 @@ describe('WaveformTooltip', () => {
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 wrapper = mount(WaveformTooltip, {
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 wrapper = mount(WaveformTooltip, {
props: {
@@ -117,6 +119,7 @@ describe('WaveformTooltip', () => {
{
trackIndex: 0,
name: 'ENG8KJXAc(10001)',
shotNo: '炮 7',
color: '#ffb43b',
unit: 'A',
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, {
props: {
visible: true,
position: { x: 10, y: 10 },
timeUnit: 's',
hoveredPoint: { x: 1.234567, y: 12 },
seriesPoints: [],
seriesPoints: [
{ trackIndex: 0, name: '温度', color: '#f00', point: { x: 1.234567, y: 12 } },
],
containerWidth: 400,
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 wrapper = mount(WaveformTooltip, {
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('未配置炮号: 温度')
})
})

View File

@@ -1,12 +1,12 @@
<script setup lang="ts">
import { computed } from 'vue'
import { resolveWaveformPointErrors } from '../../core'
import { formatTooltipNumber, formatTooltipTime } from '../../utils'
import type { WaveformPoint } from '../data/types'
interface SeriesPoint {
trackIndex: number
name: string
shotNo?: string
color: string
unit?: string
point: WaveformPoint
@@ -34,7 +34,7 @@ const props = defineProps<Props>()
const tooltipGap = 12
const containerPadding = 8
const tooltipPlacementWidth = 238
const tooltipMaxWidth = 320
const tooltipMaxWidth = 560
const tooltipHorizontalPadding = 20
const tooltipLineHeight = 20
@@ -45,18 +45,18 @@ function estimateLineCount(text: string, width: number): number {
}
function formatSeriesText(seriesPoint: SeriesPoint): string {
const error = formatError(seriesPoint.point)
return `${seriesPoint.name ? `${seriesPoint.name}: ` : ''}${formatTooltipNumber(seriesPoint.point.y)}${
seriesPoint.unit ? ` ${seriesPoint.unit}` : ''
}${error ? ` ${error}` : ''}`
const timeText = formatTooltipTime(props.hoveredPoint?.x ?? seriesPoint.point.x, props.timeUnit)
return `${seriesPoint.shotNo?.trim() || '未配置炮号'} ${seriesPoint.name}${
seriesPoint.unit ? `(${seriesPoint.unit})` : ''
} (x:${timeText} y:${formatTooltipNumber(seriesPoint.point.y)})`
}
function estimateTooltipHeight(width: number, timeText: string): number {
function estimateTooltipHeight(width: number): number {
const seriesLines = props.seriesPoints.reduce(
(total, seriesPoint) => total + estimateLineCount(formatSeriesText(seriesPoint), width),
0,
)
return 16 + tooltipLineHeight * (estimateLineCount(timeText, width) + seriesLines) + 5
return 16 + tooltipLineHeight * seriesLines + 5
}
const tooltipStyle = computed(() => {
@@ -84,25 +84,18 @@ const tooltipStyle = computed(() => {
: { left: `${containerPadding}px`, maxWidth: `${availableWidth}px` }
const maxWidth = Number.parseFloat(horizontalStyle.maxWidth)
const timeText = `${props.timeUnit}: ${formatTooltipTime(props.hoveredPoint.x, props.timeUnit)}`
return {
...horizontalStyle,
top: `${Math.max(
8,
Math.min(
props.position.y - 18,
props.containerHeight - estimateTooltipHeight(maxWidth, timeText) - 8,
props.containerHeight - estimateTooltipHeight(maxWidth) - 8,
),
)}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>
<template>
@@ -111,9 +104,6 @@ function formatError(point: WaveformPoint): string | null {
class="waveform-tooltip waveform-chart__tooltip"
:style="tooltipStyle"
>
<span class="waveform-tooltip__time waveform-chart__tooltip-time">
{{ timeUnit }}: {{ formatTooltipTime(hoveredPoint.x, timeUnit) }}
</span>
<span
v-for="seriesPoint in seriesPoints"
:key="`${seriesPoint.trackIndex}-${seriesPoint.name}`"
@@ -121,12 +111,12 @@ function formatError(point: WaveformPoint): string | null {
>
<i :style="{ backgroundColor: seriesPoint.color }" />
<span class="waveform-tooltip__series-content">
<strong v-if="seriesPoint.name">{{ seriesPoint.name }}:</strong>
<span class="waveform-tooltip__value">
{{ formatTooltipNumber(seriesPoint.point.y)
}}{{ seriesPoint.unit ? ` ${seriesPoint.unit}` : '' }}
<small v-if="formatError(seriesPoint.point)">{{ formatError(seriesPoint.point) }}</small>
</span>
<span class="waveform-tooltip__series-label">{{ seriesPoint.shotNo?.trim() || '未配置炮号' }} {{
seriesPoint.name
}}<template v-if="seriesPoint.unit">({{ seriesPoint.unit }})</template></span>
<span class="waveform-tooltip__value">(x:{{ formatTooltipTime(hoveredPoint.x, timeUnit) }} y:{{
formatTooltipNumber(seriesPoint.point.y)
}})</span>
</span>
</span>
</div>
@@ -138,26 +128,17 @@ function formatError(point: WaveformPoint): string | null {
position: absolute;
z-index: 2;
display: grid;
gap: 3px;
gap: 2px;
width: max-content;
max-width: min(320px, calc(100% - 16px));
padding: 8px 10px;
color: #333;
font:
12px/1.45 ui-monospace,
SFMono-Regular,
Consolas,
monospace;
max-width: min(560px, calc(100% - 16px));
padding: 9px 12px;
color: #505050;
font: 14px/1.35 Arial, sans-serif;
pointer-events: none;
background: #fff;
border: 1px solid #d9d9d9;
border-radius: 2px;
box-shadow: 0 4px 12px rgb(16 24 40 / 12%);
}
.waveform-tooltip__time {
padding-bottom: 4px;
border-bottom: 1px solid #f0f0f0;
border: 1px solid #e3e7eb;
border-radius: 4px;
box-shadow: 0 3px 10px rgb(16 24 40 / 15%);
}
.waveform-tooltip__series {
@@ -176,9 +157,24 @@ function formatError(point: WaveformPoint): string | null {
}
.waveform-tooltip__series-content {
display: flex;
flex-wrap: nowrap;
gap: 12px;
align-items: baseline;
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 {
@@ -186,7 +182,7 @@ function formatError(point: WaveformPoint): string | null {
}
.waveform-tooltip__value {
overflow-wrap: anywhere;
color: #555;
}
.waveform-tooltip__series small {

View File

@@ -85,6 +85,7 @@ export function useWaveformHover(context: HoverContext) {
point: WaveformPoint,
): HoveredSeriesPoint => ({
id: series.id,
shotNo: series.shotNo,
name: series.name,
color: series.color,
unit: series.unit,

View File

@@ -9,6 +9,7 @@ export type {
WaveformDisplayMode,
WaveformOverlayMode,
WaveformInteractionMode,
WaveformXDomainStrategy,
WaveformAnnotationStyle,
WaveformAnnotation,
WaveformRenderingOptions,

View File

@@ -179,10 +179,10 @@ describe('WaveformChart', () => {
await flushPromises()
const tooltip = wrapper.get('.waveform-chart__tooltip')
expect(tooltip.text()).toContain('BT2_2M:')
expect(tooltip.text()).toContain('2 T')
expect(tooltip.text()).toContain('BT1_2M:')
expect(tooltip.text()).toContain('4 T')
expect(tooltip.text()).toContain('未配置炮号: BT2_2M')
expect(tooltip.text()).toContain('(x:1,000 y:2)')
expect(tooltip.text()).toContain('未配置炮号: BT1_2M')
expect(tooltip.text()).toContain('(x:1,000 y:4)')
const crosshairLines = wrapper.findAll('.waveform-chart__crosshair line')
expect(crosshairLines).toHaveLength(2)
crosshairLines.forEach((line) => {

View File

@@ -178,7 +178,7 @@ describe('WaveformChart', () => {
await flushPromises()
expect(wrapper.emitted('point-hover')?.at(-1)).toEqual([{ x: 1, y: 5 }])
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')
expect(crosshairLines).toHaveLength(1)
expect(crosshairLines[0].attributes('x1')).toBe(crosshairLines[0].attributes('x2'))
@@ -303,7 +303,7 @@ describe('WaveformChart', () => {
flushAnimationFrames()
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.get('.waveform-chart__line').element).toBe(pathBeforeHover)
expect(chartUpdate).not.toHaveBeenCalled()

View File

@@ -5,6 +5,13 @@ import { flushAnimationFrames } from '../../test/setup'
import { gridSeries, mountSizedChart } from '../../test/waveformChart'
describe('WaveformChart viewport reset', () => {
const niceExplicitStrategy = {
type: 'nice' as const,
bounds: 'end' as const,
tickCount: 10,
includeExplicit: true,
}
it('resets a shared viewport on double-click and emits a global payload', async () => {
const wrapper = await mountSizedChart(
{
@@ -111,4 +118,32 @@ describe('WaveformChart viewport reset', () => {
expect(wrapper.findAll('.waveform-chart__axis-endpoint--start')[0].text()).toBe('0')
expect(wrapper.findAll('.waveform-chart__axis-endpoint--end')[0].text()).toBe('1000')
})
it('resets shared and independent explicit domains to their included nice bounds', async () => {
const shared = await mountSizedChart(
{
kind: 'points',
points: [
{ x: 0, y: 0 },
{ x: 4.999999, y: 1 },
],
},
{ initialXDomain: [0, 4.999999], xDomainStrategy: niceExplicitStrategy },
)
const independent = await mountSizedChart(gridSeries(2), {
displayMode: 'independent',
initialXDomains: { 'channel-0': [0, 4.999999] },
xDomainStrategy: niceExplicitStrategy,
})
;(shared.vm as unknown as { resetViewport: () => void }).resetViewport()
;(independent.vm as unknown as { resetViewport: () => void }).resetViewport()
await flushPromises()
expect(shared.get('.waveform-chart__axis-endpoint--start').text()).toBe('0')
expect(shared.get('.waveform-chart__axis-endpoint--end').text()).toBe('5000')
const firstTrack = independent.findAll('.waveform-chart__track')[0]
expect(firstTrack.get('.waveform-chart__axis-endpoint--start').text()).toBe('0')
expect(firstTrack.get('.waveform-chart__axis-endpoint--end').text()).toBe('5000')
})
})

View File

@@ -0,0 +1,96 @@
import { describe, expect, it } from 'vitest'
import { gridSeries, mountSizedChart } from '../../test/waveformChart'
describe('WaveformChart x domain strategy', () => {
it('expands automatic x domains without changing source seconds', async () => {
const data = {
kind: 'points' as const,
points: [
{ x: 0, y: 0 },
{ x: 4.999999, y: 1 },
],
}
const wrapper = await mountSizedChart(data, {
timeUnit: 'ms',
xDomainStrategy: { type: 'nice', bounds: 'end' },
})
expect(wrapper.get('.waveform-chart__axis-endpoint--start').text()).toBe('0')
expect(wrapper.get('.waveform-chart__axis-endpoint--end').text()).toBe('5000')
expect(data.points[1]?.x).toBe(4.999999)
})
it('keeps explicit initial x domains exact by default', async () => {
const wrapper = await mountSizedChart(
{
kind: 'points',
points: [
{ x: 123, y: 0 },
{ x: 456, y: 1 },
],
},
{
timeUnit: 's',
initialXDomain: [120, 460],
xDomainStrategy: { type: 'nice' },
},
)
expect(wrapper.get('.waveform-chart__axis-endpoint--start').text()).toBe('120')
expect(wrapper.get('.waveform-chart__axis-endpoint--end').text()).toBe('460')
})
it('keeps explicit per-track initial x domains exact by default', async () => {
const wrapper = await mountSizedChart(gridSeries(1), {
displayMode: 'independent',
initialXDomains: { 'channel-0': [0, 4.999999] },
xDomainStrategy: { type: 'nice', bounds: 'end' },
})
expect(wrapper.get('.waveform-chart__axis-endpoint--start').text()).toBe('0')
expect(wrapper.get('.waveform-chart__axis-endpoint--end').text()).toBe('4999.999')
})
it('includes an explicit shared initial x domain when requested', async () => {
const wrapper = await mountSizedChart(
{
kind: 'points',
points: [
{ x: 0, y: 0 },
{ x: 4.999999, y: 1 },
],
},
{
initialXDomain: [0, 4.999999],
xDomainStrategy: {
type: 'nice',
bounds: 'end',
tickCount: 10,
includeExplicit: true,
},
},
)
expect(wrapper.get('.waveform-chart__axis-endpoint--start').text()).toBe('0')
expect(wrapper.get('.waveform-chart__axis-endpoint--end').text()).toBe('5000')
})
it('includes explicit per-track initial x domains in independent mode', async () => {
const wrapper = await mountSizedChart(gridSeries(2), {
displayMode: 'independent',
grid: { rowCount: 1, columnCount: 2 },
initialXDomains: {
'channel-0': [0, 4.999999],
'channel-1': [10, 14.999999],
},
xDomainStrategy: { type: 'nice', bounds: 'end', tickCount: 10, includeExplicit: true },
})
const tracks = wrapper.findAll('.waveform-chart__track')
expect(tracks[0]?.get('.waveform-chart__axis-endpoint--start').text()).toBe('0')
expect(tracks[0]?.get('.waveform-chart__axis-endpoint--end').text()).toBe('5000')
expect(tracks[1]?.get('.waveform-chart__axis-endpoint--start').text()).toBe('10000')
expect(tracks[1]?.get('.waveform-chart__axis-endpoint--end').text()).toBe('15000')
})
})

View File

@@ -102,4 +102,26 @@ describe('waveform data normalization', () => {
'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])
})
})

View File

@@ -132,6 +132,7 @@ export function normalizeWaveformSeries(data: WaveformData): NormalizedWaveformS
return {
id: uniqueId,
shotNo: series.shotNo?.trim() || undefined,
trackId: series.trackId?.trim() || undefined,
name: series.name,
unit: series.unit,

View File

@@ -13,6 +13,7 @@ describe('simulated waveform data', () => {
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.shotNo))).toEqual(new Set(['13300']))
first.series.forEach((series) => {
expect(series.data.kind).toBe('points')
if (series.data.kind !== 'points') return

View File

@@ -13,7 +13,7 @@ type ErrorGenerator = (
interface SimulatedSeriesDefinition extends Pick<
WaveformSeries,
'id' | 'name' | 'unit' | 'lineType' | 'pointType' | 'errorBar'
'id' | 'shotNo' | 'name' | 'unit' | 'lineType' | 'pointType' | 'errorBar'
> {
signal: SignalGenerator
errors?: ErrorGenerator
@@ -46,6 +46,7 @@ function createPoints(
const seriesDefinitions: SimulatedSeriesDefinition[] = [
{
id: 'simulated-sine',
shotNo: '13300',
name: '正弦基波',
unit: 'V',
lineType: 'none',
@@ -59,6 +60,7 @@ const seriesDefinitions: SimulatedSeriesDefinition[] = [
},
{
id: 'simulated-harmonic',
shotNo: '13300',
name: '谐波扰动',
unit: 'V',
lineType: 'linear',
@@ -68,6 +70,7 @@ const seriesDefinitions: SimulatedSeriesDefinition[] = [
},
{
id: 'simulated-damped',
shotNo: '13300',
name: '阻尼振荡',
unit: 'A',
lineType: 'linear',
@@ -79,6 +82,7 @@ const seriesDefinitions: SimulatedSeriesDefinition[] = [
},
{
id: 'simulated-step',
shotNo: '13300',
name: '阶跃响应',
unit: 'V',
lineType: 'linear',
@@ -87,6 +91,7 @@ const seriesDefinitions: SimulatedSeriesDefinition[] = [
},
{
id: 'simulated-pulse',
shotNo: '13300',
name: '脉冲响应',
unit: 'V',
lineType: 'linear',
@@ -95,6 +100,7 @@ const seriesDefinitions: SimulatedSeriesDefinition[] = [
},
{
id: 'simulated-noise',
shotNo: '13300',
name: '带噪信号',
unit: 'A',
lineType: 'linear',

View File

@@ -13,6 +13,7 @@ export type {
WaveformDisplayMode,
WaveformOverlayMode,
WaveformInteractionMode,
WaveformXDomainStrategy,
WaveformZoomEndPayload,
WaveformZoomResetPayload,
WaveformAnnotationStyle,

View File

@@ -26,6 +26,17 @@ export type WaveformOverlayMode = 'single-axis' | 'multi-axis'
/** 标注工具模式 */
export type WaveformInteractionMode = 'zoom' | 'annotation'
/** Controls how the initial X viewport is derived when no explicit domain is configured. */
export interface WaveformXDomainStrategy {
type: 'data' | 'nice'
/** Selects which bounds are expanded when type is `nice`. Defaults to `both`. */
bounds?: 'both' | 'end'
/** Stable tick count used to calculate nice bounds. Defaults to 10. */
tickCount?: number
/** Applies the strategy to explicit initial domains. Defaults to false. */
includeExplicit?: boolean
}
/** Describes the X-axis viewport after a zoom gesture completes. */
export interface WaveformZoomEndPayload {
start: number

View File

@@ -47,6 +47,8 @@ export type SingleWaveformData =
*/
export interface WaveformSeries {
id?: string
/** 炮号,未提供时 Tooltip 显示“未配置炮号”。 */
shotNo?: string
/** 相同 trackId 的系列叠加在同一图框中;默认每个系列独占一个图框。 */
trackId?: string
name: string
@@ -74,6 +76,7 @@ export type WaveformData =
*/
export interface NormalizedWaveformSeries {
id: string
shotNo?: string
trackId?: string
name: string
unit?: string

View File

@@ -8,6 +8,7 @@ export type {
WaveformDisplayMode,
WaveformOverlayMode,
WaveformInteractionMode,
WaveformXDomainStrategy,
WaveformZoomEndPayload,
WaveformZoomResetPayload,
WaveformAnnotationStyle,

View File

@@ -19,6 +19,7 @@ const chartData: WaveformData = {
series: [
{
id: 'voltage',
shotNo: '13300',
name: '电压',
unit: 'V',
color: '#1677ff',
@@ -33,6 +34,7 @@ const chartData: WaveformData = {
},
{
id: 'current',
shotNo: '13300',
name: '电流',
unit: 'mA',
color: '#d4380d',