feat: 修改debugger的波形显示

This commit is contained in:
SikongJueluo 2025-07-21 18:11:43 +08:00
parent e872f24936
commit e7c8d3fb9e
1 changed files with 89 additions and 41 deletions

View File

@ -95,15 +95,15 @@ const option = computed((): EChartsOption => {
.map((channel, index) => (channel.enabled ? index : -1)) .map((channel, index) => (channel.enabled ? index : -1))
.filter((index) => index !== -1); .filter((index) => index !== -1);
//
const channelCount = enabledChannels.length; const channelCount = enabledChannels.length;
const channelSpacing = 2; // const channelSpacing = 2; //
//
if (channelCount === 0) { if (channelCount === 0) {
return {}; return {};
} }
// 使 //
const grids: GridComponentOption[] = [ const grids: GridComponentOption[] = [
{ {
left: "5%", left: "5%",
@ -147,34 +147,84 @@ const option = computed((): EChartsOption => {
}, },
]; ];
// //
const series: LineSeriesOption[] = enabledChannelIndices.map( const series: LineSeriesOption[] = [];
(originalIndex: number, displayIndex: number) => ({ enabledChannelIndices.forEach((originalIndex: number, displayIndex: number) => {
name: enabledChannels[displayIndex].name, const channel = analyzer.logicData.value!.y[originalIndex];
type: "line", if (channel.type === "logic") {
data: analyzer.logicData.value!.y[originalIndex].value.map( // logic
(value: number) => value + displayIndex * channelSpacing + 0.2, series.push({
), name: channel.name,
step: "end", type: "line",
lineStyle: { data: channel.value.map(
width: 2, (value: number) => value + displayIndex * channelSpacing + 0.2,
color: enabledChannels[displayIndex].color, ),
}, step: "end",
areaStyle: { lineStyle: {
opacity: 0.3, width: 2,
origin: displayIndex * channelSpacing, color: channel.color,
color: enabledChannels[displayIndex].color, },
}, areaStyle: {
symbol: "none", opacity: 0.3,
// origin: displayIndex * channelSpacing,
sampling: "lttb", color: channel.color,
// },
animation: false, symbol: "none",
}), sampling: "lttb",
); animation: false,
});
} else if (channel.type === "number") {
// numberVCD仿线10areaStyle
const values = channel.value;
const xArr = analyzer.logicData.value!.x;
//
function buildVcdLine(valArr: number[], high: number, low: number) {
const points: {x: number, y: number}[] = [];
for (let i = 0; i < valArr.length; i++) {
const v = valArr[i] > 0 ? high : low;
points.push({x: xArr[i], y: v});
//
if (i < valArr.length - 1 && valArr[i] !== valArr[i+1]) {
// x+0.3y
const nextV = valArr[i+1] > 0 ? high : low;
points.push({x: xArr[i]+0.3, y: nextV});
}
}
// yxcategory
return points.map(p => p.y);
}
// 1线
series.push({
name: channel.name + "_1",
type: "line",
data: buildVcdLine(values, displayIndex * channelSpacing + 1, displayIndex * channelSpacing),
step: false, // step
lineStyle: {
width: 2,
color: channel.color,
},
symbol: "none",
sampling: "lttb",
animation: false,
});
// 0线
series.push({
name: channel.name + "_0",
type: "line",
data: buildVcdLine(values, displayIndex * channelSpacing, displayIndex * channelSpacing + 1),
step: false,
lineStyle: {
width: 2,
color: channel.color,
},
symbol: "none",
sampling: "lttb",
animation: false,
});
}
});
return { return {
//
animation: false, animation: false,
tooltip: { tooltip: {
trigger: "axis", trigger: "axis",
@ -183,31 +233,29 @@ const option = computed((): EChartsOption => {
label: { label: {
backgroundColor: "#6a7985", backgroundColor: "#6a7985",
}, },
// axisPointer
animation: false, animation: false,
}, },
formatter: (params: any) => { formatter: (params: any) => {
if (Array.isArray(params) && params.length > 0) { if (Array.isArray(params) && params.length > 0) {
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) => {
// 01 const channel = analyzer.logicData.value!.y[originalIndex];
enabledChannelIndices.forEach( if (channel.type === "logic") {
(originalIndex: number, displayIndex: number) => { const channelName = channel.name;
const channelName = enabledChannels[displayIndex].name; const originalValue = channel.value[dataIndex];
const originalValue =
analyzer.logicData.value!.y[originalIndex].value[dataIndex];
tooltip += `${channelName}: ${originalValue}<br/>`; tooltip += `${channelName}: ${originalValue}<br/>`;
}, } else if (channel.type === "number") {
); const channelName = channel.name;
const originalValue = channel.value[dataIndex];
tooltip += `${channelName}: ${originalValue}<br/>`;
}
});
return tooltip; return tooltip;
} }
return ""; return "";
}, },
// tooltip
hideDelay: 100, hideDelay: 100,
}, },
toolbox: { toolbox: {