From 2babe9d99d63e25390a734850af634396d7f9c82 Mon Sep 17 00:00:00 2001 From: yexb <553699424@qq.com> Date: Thu, 7 May 2026 09:38:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(waveform):=20=E6=B7=BB=E5=8A=A0=E6=B3=A2?= =?UTF-8?q?=E5=BD=A2=E5=9B=BE=E8=B6=8B=E5=8A=BF=E5=B7=A5=E5=85=B7=E5=92=8C?= =?UTF-8?q?=E5=9D=90=E6=A0=87=E8=BD=B4=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现波形图纵坐标显示规则,包括最大最小值显示、刻度均分、对称边界等功能 - 添加多图趋势图对齐规则,确保绘图区左边界一致和标签宽度统一 - 集成图表点击事件发射器,支持时间标签、数值和系列名称的数据传递 - 实现波形图缩放、平移、测量、峰值标记等交互功能 - 添加坐标轴刻度精度控制和可读步长归一化处理 - 实现多图对齐的网格配置和纵坐标标签防重叠机制 - 添加波形图全屏展示和图片导出功能 - 实现趋势图峰值标记点和测量游标功能 --- AGENTS.md | 20 + .../src/components/echarts/line/index.vue | 30 +- .../waveform/components/WaveformToolbar.vue | 8 +- .../components/WaveformTrendChartArea.vue | 174 ++++++ .../components/WaveformTrendPanel.vue | 304 ++++++---- .../views/tools/waveform/components/types.ts | 20 + frontend/src/views/tools/waveform/index.vue | 556 +++++++++++++++--- 7 files changed, 903 insertions(+), 209 deletions(-) create mode 100644 frontend/src/views/tools/waveform/components/WaveformTrendChartArea.vue diff --git a/AGENTS.md b/AGENTS.md index 79dd483..6fb5322 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -64,4 +64,24 @@ PR 应包含: ## 安全与配置提示 `public/ssl/`、`build/extraResources/` 与 `electron/config/` 包含敏感运行资源。不要硬编码新的密钥或口令;凡是影响打包或启动的本地 `.env`、端口或运行配置调整,都应同步记录到 `doc/`。 +## 趋势图纵坐标显示规则 +涉及 waveform 或其他趋势图纵坐标时,统一遵循以下规则: + +- 必须显示纵坐标最大值和最小值,图表配置中应显式保留 `showMaxLabel` 与 `showMinLabel`。 +- 纵坐标刻度值采用均分方式生成,不再使用会改变刻度间隔的“友好刻度”取整逻辑。 +- 纵坐标最大值和最小值基于图形内真实最大值、最小值按 `1.2` 倍扩展;正数下边界使用 `0.8` 倍向下留白,负数上边界使用 `0.8` 倍向上留白,避免正数最小值或负数最大值被扩展到数据内侧。 +- 当数据同时包含正负值且正负幅值接近时,纵坐标最大值和最小值应尽量对称,按较大绝对值向外取整后取 `±同一边界`,例如最大值 `178`、最小值 `-177` 时显示为 `180` 与 `-180`。 +- 当最大值、最小值相同或数据接近 `0` 时,需要补充兜底范围,避免坐标轴退化为一条线;小于 `1` 的小数范围按实际小数精度保留,不强制取整。 +- 当纵坐标区间较小且均分后出现冗长小数时,应优先使用 `1`、`2`、`2.5`、`5` 等可读步长归一化刻度;必要时可少量增加分段,但必须继续保证刻度均分、最大最小值显示、真实数据完整落在坐标范围内。 +- 纵坐标标签不能重叠。小高度趋势图应减少均分段数,优先保证最大值、最小值和必要中间值可读;高度足够时再增加分段。 + +## 多图趋势图对齐规则 +涉及 waveform 或其他上下堆叠的多张趋势图时,统一遵循以下规则: + +- 同一组多图必须保证绘图区左边界一致,纵向观察时各图的 y 轴线、x 轴 `0` 起点和曲线起始位置应上下对齐。 +- 多图不得让 ECharts 按各自纵坐标标签宽度自动改变绘图区起点;应使用统一的 `grid.left`,并显式配置 `grid.containLabel: false` 或等效方案,避免 `150`、`2`、`-100` 等标签宽度差异导致曲线区域错位。 +- 纵坐标标签宽度预留应按同组图中最长标签统一评估,必要时增加统一的左侧 `grid.left`,不能为单张图单独调整左边距。 +- 横坐标首尾标签、单位文字或底部留白只能影响底部显示空间,不应改变绘图区左边界;调整 `grid.bottom`、`axisLabel.margin`、`nameGap` 时,需要同步检查多图 x=0 起点是否仍然对齐。 +- 验证多图趋势图时,至少检查单通道拆分图和全部通道列表图两种场景;判断标准是多张图左侧坐标轴竖线形成同一条垂直线,底部横坐标标签不遮挡、不贴线。 + diff --git a/frontend/src/components/echarts/line/index.vue b/frontend/src/components/echarts/line/index.vue index 12ae2a2..cc110e2 100644 --- a/frontend/src/components/echarts/line/index.vue +++ b/frontend/src/components/echarts/line/index.vue @@ -29,6 +29,15 @@ const color = [ const chartRef = ref() const props = defineProps(['options', 'isInterVal', 'pieInterVal', 'group']) +const emit = defineEmits<{ + 'chart-click': [ + value: { + timeLabel: string + value: number + seriesName: string + } + ] +}>() let chart: echarts.ECharts | any = null const resizeHandler = () => { // 不在视野中的时候不进行resize @@ -41,7 +50,6 @@ const resizeHandler = () => { }) } const initChart = () => { - if (!props.isInterVal && !props.pieInterVal) { chart?.dispose() } @@ -127,8 +135,24 @@ const initChart = () => { // console.log(options.series,"获取x轴"); handlerBar(options) - // 处理柱状图 chart.setOption(options, true) + chart.off('click') + chart.on('click', (params: any) => { + const value = Array.isArray(params.value) ? params.value[1] : params.value + + if (params.componentType !== 'series' || !Number.isFinite(Number(value))) return + + emit('chart-click', { + timeLabel: `${params.name ?? params.dataIndex ?? ''}`, + value: Number(value), + seriesName: `${params.seriesName || ''}` + }) + }) + chart.dispatchAction({ + type: 'takeGlobalCursor', + key: 'dataZoomSelect', + dataZoomSelectActive: props.options?.activeTool === 'box-zoom' + }) setTimeout(() => { chart.resize() @@ -176,7 +200,7 @@ const handlerYAxis = () => { axisLabel: { color: '#000', fontSize: 14, - formatter: function (value) { + formatter: function (value: number) { return value.toFixed(0) // 格式化显示为一位小数 } }, diff --git a/frontend/src/views/tools/waveform/components/WaveformToolbar.vue b/frontend/src/views/tools/waveform/components/WaveformToolbar.vue index 85e8203..9b56a14 100644 --- a/frontend/src/views/tools/waveform/components/WaveformToolbar.vue +++ b/frontend/src/views/tools/waveform/components/WaveformToolbar.vue @@ -68,17 +68,13 @@ - - - 下载数据 - + + diff --git a/frontend/src/views/tools/waveform/components/WaveformTrendPanel.vue b/frontend/src/views/tools/waveform/components/WaveformTrendPanel.vue index 9cd2ccc..6a9a8b0 100644 --- a/frontend/src/views/tools/waveform/components/WaveformTrendPanel.vue +++ b/frontend/src/views/tools/waveform/components/WaveformTrendPanel.vue @@ -4,65 +4,88 @@ + +
+
+ + + +
+
-
-
- -
-
- -
-
-
-
- -
-
-
-
-
暂无波形数据
-
请选择同一组 `.cfg` 和 `.dat` 文件后自动解析并展示。
-
- 最近一次解析失败:{{ lastParseErrorMessage }} -
-
-
+ + + + +