修复默认不是 16 进制渲染格式的问题 | 修复有符号数字计算错误的问题 | 给高位宽的数字加上前缀 0
This commit is contained in:
parent
3834ffe02c
commit
5aac2f15c4
1
.gitignore
vendored
1
.gitignore
vendored
@ -22,5 +22,6 @@ pnpm-debug.log*
|
||||
*.sln
|
||||
*.sw?
|
||||
*.vcd
|
||||
*.view
|
||||
|
||||
deploy.bat
|
@ -16,8 +16,8 @@
|
||||
|
||||
<script>
|
||||
window.readVcdFile = async () => {
|
||||
let inputVcdFile = 'test.vcd';
|
||||
let inputViewFile = 'test.view';
|
||||
let inputVcdFile = 'movAvg.vcd';
|
||||
let inputViewFile = 'movAvg.view';
|
||||
const response = await fetch(inputVcdFile);
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
return [arrayBuffer, inputVcdFile, inputViewFile];
|
||||
|
BIN
public/test.view
BIN
public/test.view
Binary file not shown.
@ -6,7 +6,7 @@ const getLabel = (lane) => {
|
||||
lane = {};
|
||||
}
|
||||
|
||||
const width = Number(lane.width || 1);
|
||||
const width = Number(lane.width || 1);
|
||||
const valueRender = new FormatValueRender(lane.ref, width, '');
|
||||
|
||||
return (value, mask, x, w, link) => {
|
||||
|
@ -55,24 +55,28 @@ function getVecRenderModal(link) {
|
||||
function addVecRenderItem(link) {
|
||||
const link2CurrentWires = globalLookup.link2CurrentWires;
|
||||
const modal = getVecRenderModal(link);
|
||||
|
||||
if (modal === 0) {
|
||||
const signal = link2CurrentWires.get(link);
|
||||
return {
|
||||
name: signal.name,
|
||||
kind: signal.kind,
|
||||
ref: signal.link
|
||||
ref: signal.link,
|
||||
width: signal.size
|
||||
}
|
||||
} else if (modal === 1) {
|
||||
return {
|
||||
name: '',
|
||||
kind: '',
|
||||
ref: ''
|
||||
ref: '',
|
||||
width: 1
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
name: '',
|
||||
kind: '',
|
||||
ref: ''
|
||||
ref: '',
|
||||
width: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,7 +105,8 @@ function* renderValues(desc, pstate) {
|
||||
renderSignals.push({
|
||||
name: '',
|
||||
kind: '',
|
||||
ref: ''
|
||||
ref: '',
|
||||
width: 1
|
||||
});
|
||||
// 如果没有关闭,把所有子节点加入其中
|
||||
if (view.groupInfo.collapse === false) {
|
||||
@ -172,11 +177,13 @@ function* renderValues(desc, pstate) {
|
||||
const xCur = getX(pstate, tCur);
|
||||
|
||||
if (vPre !== undefined || mPre !== undefined) {
|
||||
if (xPre > width && xCur > width) { // both time stamps to the right
|
||||
if (xPre > width && xCur > width) {
|
||||
// both time stamps to the right
|
||||
break perLane;
|
||||
}
|
||||
|
||||
if (!((xPre < sidebarWidth) && (xCur < sidebarWidth))) { // both time stamps to the left
|
||||
if (!((xPre < sidebarWidth) && (xCur < sidebarWidth))) {
|
||||
// both time stamps to the left
|
||||
const xPreNorm = ((xPre > sidebarWidth) ? xPre : sidebarWidth) | 0;
|
||||
const xCurNorm = ((xCur < width) ? xCur : width) | 0;
|
||||
const w = xCurNorm - xPreNorm;
|
||||
|
@ -14,7 +14,8 @@ function getValueFormatCode(link) {
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
// 默认 16 进制
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,7 +74,7 @@ export class FormatValueRender {
|
||||
* @returns {string} 转换后需要渲染的字符串
|
||||
*/
|
||||
render(value, pos) {
|
||||
const formatCode = this.formatCode;
|
||||
const formatCode = this.formatCode;
|
||||
switch (formatCode) {
|
||||
// 二进制
|
||||
case 0: return this.radixTransform(2, value, pos);
|
||||
@ -136,7 +137,29 @@ export class FormatValueRender {
|
||||
|
||||
|
||||
// 无符号的各类进制数字
|
||||
const valueString = value.toString(radix);
|
||||
let valueString = value.toString(radix);
|
||||
// 如果是 2, 8, 16 进制,需要根据宽度自动完全前面的 0 的填充
|
||||
let displayWidth, padding;
|
||||
switch (radix) {
|
||||
case 2:
|
||||
displayWidth = Number(width);
|
||||
padding = "0".repeat(displayWidth - valueString.length);
|
||||
valueString = padding + valueString;
|
||||
break;
|
||||
case 8:
|
||||
displayWidth = Math.ceil(Number(width) / 3);
|
||||
padding = "0".repeat(displayWidth - valueString.length);
|
||||
valueString = padding + valueString;
|
||||
break;
|
||||
case 16:
|
||||
displayWidth = Math.ceil(Number(width) / 4);
|
||||
padding = "0".repeat(displayWidth - valueString.length);
|
||||
valueString = padding + valueString;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (pos === -1 || valueString.length <= pos) {
|
||||
return valueString;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user