From 0f458f629916bac98dcb8fbece61755db3e5d7ba Mon Sep 17 00:00:00 2001 From: Roe-xin Date: Tue, 30 Dec 2025 15:35:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=B3=A2=E5=BD=A2?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E8=84=9A=E6=9C=AC=E7=BB=98=E5=88=B6=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E6=94=AF=E6=8C=81=E5=8D=95=E6=AF=94=E7=89=B9?= =?UTF-8?q?=E5=92=8C=E5=A4=9A=E6=AF=94=E7=89=B9=E4=BF=A1=E5=8F=B7=E7=9A=84?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E7=BB=98=E5=88=B6=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/waveformPreviewContent.ts | 84 +++++++++++++++-------------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/src/views/waveformPreviewContent.ts b/src/views/waveformPreviewContent.ts index 6c98a77..9e20df4 100644 --- a/src/views/waveformPreviewContent.ts +++ b/src/views/waveformPreviewContent.ts @@ -263,61 +263,63 @@ export function getWaveformPreviewScript(): string { const timeRange = maxTime - minTime || 1; // 绘制波形 - let pathData = ''; - let lastX = leftMargin; - let lastValue = signal.values[0].value; + if (signal.width === 1) { + // 单比特信号 - 绘制数字波形 + let pathData = ''; + const yHigh = y; + const yLow = y + signalHeight; - signal.values.forEach((point, i) => { - const x = leftMargin + ((point.time - minTime) / timeRange) * waveformWidth; - const value = point.value; - - if (signal.width === 1) { - // 单比特信号 - 绘制数字波形 - const yHigh = y; - const yLow = y + signalHeight; - const currentY = (value === '1') ? yHigh : yLow; + signal.values.forEach((point, i) => { + const x = leftMargin + ((point.time - minTime) / timeRange) * waveformWidth; + const currentY = (point.value === '1') ? yHigh : yLow; if (i === 0) { pathData = \`M \${x} \${currentY}\`; } else { - // 绘制垂直跳变 - const prevY = (lastValue === '1') ? yHigh : yLow; + const prevValue = signal.values[i - 1].value; + const prevY = (prevValue === '1') ? yHigh : yLow; if (prevY !== currentY) { pathData += \` L \${x} \${prevY} L \${x} \${currentY}\`; } else { pathData += \` L \${x} \${currentY}\`; } } + }); - lastValue = value; - lastX = x; - } else { - // 多比特信号 - 绘制总线波形(梯形) - const yTop = y + 5; - const yBottom = y + signalHeight - 5; - const transitionWidth = 5; - - if (i === 0) { - pathData = \`M \${x} \${yTop + (yBottom - yTop) / 2}\`; - } else { - // 绘制梯形过渡 - pathData += \` L \${x - transitionWidth} \${yTop} L \${x} \${yTop + (yBottom - yTop) / 2}\`; - } - - lastX = x; - } - }); - - // 延伸到右边界 - if (signal.width === 1) { - const lastY = (lastValue === '1') ? y : (y + signalHeight); + // 延伸到右边界 + const lastValue = signal.values[signal.values.length - 1].value; + const lastY = (lastValue === '1') ? yHigh : yLow; pathData += \` L \${leftMargin + waveformWidth} \${lastY}\`; - } else { - const yMid = y + signalHeight / 2; - pathData += \` L \${leftMargin + waveformWidth} \${yMid}\`; - } - svgContent += \`\`; + svgContent += \`\`; + } else { + // 多比特信号 - 绘制总线波形(上下双线) + const yTop = y + 5; + const yBottom = y + signalHeight - 5; + const transitionWidth = 4; + + let topPath = \`M \${leftMargin} \${yTop}\`; + let bottomPath = \`M \${leftMargin} \${yBottom}\`; + + signal.values.forEach((point, i) => { + const x = leftMargin + ((point.time - minTime) / timeRange) * waveformWidth; + + // 上线和下线都延伸到变化点 + topPath += \` L \${x} \${yTop}\`; + bottomPath += \` L \${x} \${yBottom}\`; + + // 绘制梯形过渡 + topPath += \` L \${x + transitionWidth} \${yBottom} L \${x + transitionWidth} \${yTop}\`; + bottomPath += \` L \${x + transitionWidth} \${yTop} L \${x + transitionWidth} \${yBottom}\`; + }); + + // 延伸到右边界 + topPath += \` L \${leftMargin + waveformWidth} \${yTop}\`; + bottomPath += \` L \${leftMargin + waveformWidth} \${yBottom}\`; + + svgContent += \`\`; + svgContent += \`\`; + } }); // 绘制时间轴