feat: 添加数值类型的波形显示

This commit is contained in:
SikongJueluo 2025-07-29 14:57:07 +08:00
parent 6c1bda50ce
commit f200d90fc0
No known key found for this signature in database
2 changed files with 155 additions and 83 deletions

View File

@ -39,6 +39,7 @@ import {
DataZoomComponent, DataZoomComponent,
AxisPointerComponent, AxisPointerComponent,
ToolboxComponent, ToolboxComponent,
MarkLineComponent,
} from "echarts/components"; } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers"; import { CanvasRenderer } from "echarts/renderers";
import type { ComposeOption } from "echarts/core"; import type { ComposeOption } from "echarts/core";
@ -48,6 +49,7 @@ import type {
TooltipComponentOption, TooltipComponentOption,
GridComponentOption, GridComponentOption,
DataZoomComponentOption, DataZoomComponentOption,
MarkLineComponentOption,
} from "echarts/components"; } from "echarts/components";
import type { import type {
ToolboxComponentOption, ToolboxComponentOption,
@ -66,6 +68,7 @@ use([
DataZoomComponent, DataZoomComponent,
LineChart, LineChart,
CanvasRenderer, CanvasRenderer,
MarkLineComponent,
]); ]);
type EChartsOption = ComposeOption< type EChartsOption = ComposeOption<
@ -75,6 +78,7 @@ type EChartsOption = ComposeOption<
| GridComponentOption | GridComponentOption
| DataZoomComponentOption | DataZoomComponentOption
| LineSeriesOption | LineSeriesOption
| MarkLineComponentOption
>; >;
const analyzer = useRequiredInjection(useWaveformManager); const analyzer = useRequiredInjection(useWaveformManager);
@ -90,7 +94,9 @@ const option = computed((): EChartsOption => {
if (isUndefined(analyzer.logicData.value)) return {}; if (isUndefined(analyzer.logicData.value)) return {};
// 使y // 使y
const enabledChannels = analyzer.logicData.value.y.filter(channel => channel.enabled); const enabledChannels = analyzer.logicData.value.y.filter(
(channel) => channel.enabled,
);
const enabledChannelIndices = analyzer.logicData.value.y const enabledChannelIndices = analyzer.logicData.value.y
.map((channel, index) => (channel.enabled ? index : -1)) .map((channel, index) => (channel.enabled ? index : -1))
.filter((index) => index !== -1); .filter((index) => index !== -1);
@ -149,7 +155,8 @@ const option = computed((): EChartsOption => {
// //
const series: LineSeriesOption[] = []; const series: LineSeriesOption[] = [];
enabledChannelIndices.forEach((originalIndex: number, displayIndex: number) => { enabledChannelIndices.forEach(
(originalIndex: number, displayIndex: number) => {
const channel = analyzer.logicData.value!.y[originalIndex]; const channel = analyzer.logicData.value!.y[originalIndex];
if (channel.type === "logic") { if (channel.type === "logic") {
// logic // logic
@ -174,28 +181,79 @@ const option = computed((): EChartsOption => {
animation: false, animation: false,
}); });
} else if (channel.type === "number") { } else if (channel.type === "number") {
// numberVCD仿线10areaStyle
const values = channel.value; const values = channel.value;
const xArr = analyzer.logicData.value!.x; const xArr = analyzer.logicData.value!.x;
// //
function buildVcdLine(valArr: number[], high: number, low: number) { function buildVcdLine(valArr: number[], high: number, low: number) {
const points: {x: number, y: number}[] = []; const points: { x: number; y: number }[] = [];
let lastValue = high; let lastValue = high;
points.push({x: xArr[0], y: lastValue}); points.push({ x: xArr[0], y: lastValue });
for (let i = 1; i < valArr.length; i++) { for (let i = 1; i < valArr.length; i++) {
const v = valArr[i] !== valArr[i-1] ? (lastValue === high ? low : high) : lastValue; const v =
points.push({x: xArr[i], y: v}); valArr[i] !== valArr[i - 1]
? lastValue === high
? low
: high
: lastValue;
points.push({ x: xArr[i], y: v });
lastValue = v; lastValue = v;
} }
// yxcategory return points.map((p) => p.y);
return points.map(p => p.y);
} }
//
function buildMarkLines(valArr: number[], yBase: number) {
const markLines: any[] = [];
let lastValue = valArr[0];
let lastIdx = 0;
//
function formatValue(val: number) {
if (channel.base === "hex") return "0x" + val.toString(16).toUpperCase();
if (channel.base === "bin") return "0b" + val.toString(2);
return val.toString();
}
for (let i = 1; i <= valArr.length; i++) {
if (i === valArr.length || valArr[i] !== lastValue) {
markLines.push([
{
xAxis: lastIdx,
yAxis: yBase,
label: {
formatter: formatValue(lastValue),
position: "insideMiddle",
color: channel.color,
fontSize: 18,
opacity: 1,
},
lineStyle: {
opacity: 0,
},
},
{
xAxis: i - 1,
yAxis: yBase,
lineStyle: {
opacity: 0,
},
},
]);
lastValue = valArr[i];
lastIdx = i;
}
}
return markLines;
}
// 1线 // 1线
series.push({ series.push({
name: channel.name + "_1", name: channel.name + "_1",
type: "line", type: "line",
data: buildVcdLine(values, displayIndex * channelSpacing + 1, displayIndex * channelSpacing), data: buildVcdLine(
step: false, // step values,
displayIndex * channelSpacing + 1,
displayIndex * channelSpacing,
),
step: false,
lineStyle: { lineStyle: {
width: 2, width: 2,
color: channel.color, color: channel.color,
@ -203,12 +261,23 @@ const option = computed((): EChartsOption => {
symbol: "none", symbol: "none",
sampling: "lttb", sampling: "lttb",
animation: false, animation: false,
// markLine
markLine: {
data: buildMarkLines(values, displayIndex * channelSpacing + 0.5),
emphasis: {
disabled: true,
},
},
}); });
// 0线 // 0线
series.push({ series.push({
name: channel.name + "_0", name: channel.name + "_0",
type: "line", type: "line",
data: buildVcdLine(values, displayIndex * channelSpacing, displayIndex * channelSpacing + 1), data: buildVcdLine(
values,
displayIndex * channelSpacing,
displayIndex * channelSpacing + 1,
),
step: false, step: false,
lineStyle: { lineStyle: {
width: 2, width: 2,
@ -219,7 +288,8 @@ const option = computed((): EChartsOption => {
animation: false, animation: false,
}); });
} }
}); },
);
return { return {
animation: false, animation: false,
@ -237,7 +307,8 @@ const option = computed((): EChartsOption => {
const timeValue = analyzer.logicData.value!.x[params[0].dataIndex]; const timeValue = analyzer.logicData.value!.x[params[0].dataIndex];
const dataIndex = params[0].dataIndex; const dataIndex = params[0].dataIndex;
let tooltip = `Time: ${timeValue.toFixed(3)}${analyzer.logicData.value!.xUnit}<br/>`; let tooltip = `Time: ${timeValue.toFixed(3)}${analyzer.logicData.value!.xUnit}<br/>`;
enabledChannelIndices.forEach((originalIndex: number, displayIndex: number) => { enabledChannelIndices.forEach(
(originalIndex: number, displayIndex: number) => {
const channel = analyzer.logicData.value!.y[originalIndex]; const channel = analyzer.logicData.value!.y[originalIndex];
if (channel.type === "logic") { if (channel.type === "logic") {
const channelName = channel.name; const channelName = channel.name;
@ -248,7 +319,8 @@ const option = computed((): EChartsOption => {
const originalValue = channel.value[dataIndex]; const originalValue = channel.value[dataIndex];
tooltip += `${channelName}: ${originalValue}<br/>`; tooltip += `${channelName}: ${originalValue}<br/>`;
} }
}); },
);
return tooltip; return tooltip;
} }
return ""; return "";

View File

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<div class="card"> <div class="card m-5 bg-base-200 shadow-2xl">
<WaveformDisplay /> <WaveformDisplay />
</div> </div>
</div> </div>