feat: 修改debugger的波形显示

This commit is contained in:
2025-07-21 18:11:43 +08:00
parent e872f24936
commit e7c8d3fb9e

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") {
// number类型VCD仿真样式两个线条1和0变化时有斜率过渡点无areaStyle
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});
}
}
// 返回y数组x由category轴控制
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) => {
// 只显示启用通道在当前时间点的原始数值0或1 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: {