增加对 ? 的支持

This commit is contained in:
锦恢 2024-11-30 19:42:17 +08:00
parent 1cf41bd897
commit 860d5df52a
5 changed files with 65 additions and 31 deletions

View File

@ -215,7 +215,7 @@ text.high-impedance {
} }
text.unknown { text.unknown {
fill: hsl(287, 100%, 67%); fill: #f48771;
} }
text.pc { text.pc {

View File

@ -27,13 +27,13 @@ const screenWidthPixel = window.screen.width * getRatio() / 100;
// rgba 颜色通道,都是预设的颜色 // rgba 颜色通道,都是预设的颜色
export const gl_Colors_template = [ export const gl_Colors_template = [
[0, 0, 0, 0 ], // 0: 空 [0, 0, 0, 0 ], // 0: 空
[0, 0, 255, 1], // 1: 未知态 X 默认颜色 [0, 0, 255, 1], // 1: 未知态 默认颜色
[51, 230, 26, 1], // 2: value = 0 用于 width = 1 的信号 默认颜色 [51, 230, 26, 1], // 2: value = 0 用于 width = 1 的信号 默认颜色
[51, 230, 26, 1], // 3: value = 1 用于 width = 1 的信号 默认颜色 [51, 230, 26, 1], // 3: value = 1 用于 width = 1 的信号 默认颜色
[230, 51, 51, 1], // 4: 高阻态 Z 默认颜色 [230, 51, 51, 1], // 4: 高阻态 X 默认颜色
[124, 77, 255, 1], // 5: vec 用于 width > 1 的信号 [124, 77, 255, 1], // 5: vec 用于 width > 1 的信号
[255, 0, 255, 1], // 6: yellow [255, 0, 255, 1], // 6: yellow
[255, 0, 255, 1], // 7: strange purple [244, 135, 113, 1], // 7: unknownvec 未知状态,混杂了 x 的数值
[0, 255, 0, 0.5], // 8: (l L) weak 0 [0, 255, 0, 0.5], // 8: (l L) weak 0
[255, 0, 255, 0.5], // 9: (h H) weak 1 [255, 0, 255, 0.5], // 9: (h H) weak 1
[255, 0, 0, 0.5], // 10: (w W) weak unknown [255, 0, 0, 0.5], // 10: (w W) weak unknown

View File

@ -205,15 +205,11 @@ class WebGL2WaveRender {
* maskVertices: Int32Array * maskVertices: Int32Array
* }} * }}
*/ */
makeVecVertex(link, wave, time, debug = false) { makeVecVertex(link, wave, time) {
const lookup = this.globalLookup; const lookup = this.globalLookup;
const vecRenderFn = this.selectVecRenderFn(lookup, link, wave, time); const vecRenderFn = this.selectVecRenderFn(lookup, link, wave, time);
const { lineVertices, maskVertices } = vecRenderFn(lookup, link, wave, time); const { lineVertices, maskVertices } = vecRenderFn(lookup, link, wave, time);
if (debug) {
console.log(lineVertices);
}
return { return {
lineVertices: new Int32Array(lineVertices), lineVertices: new Int32Array(lineVertices),
maskVertices: new Int32Array(maskVertices) maskVertices: new Int32Array(maskVertices)

View File

@ -293,7 +293,6 @@ export class JSValueRender {
// 未知 // 未知
default: return '?'; default: return '?';
} }
} }
/** /**

View File

@ -292,6 +292,10 @@ export function renderAsCommonDigital(lookup, link, wave, time) {
const lineVertices = []; const lineVertices = [];
const maskVertices = []; const maskVertices = [];
// 获取外部自定义颜色
// 这部分颜色只会染色非异常部分的信号
let userDefineCommonColor = getUserDefineCommonColor(lookup, link);
for (let i = 0; i < length; ++ i) { for (let i = 0; i < length; ++ i) {
const [t1, val, mask] = wave[i]; const [t1, val, mask] = wave[i];
const t2 = (i === (length - 1)) ? time : wave[i + 1][0]; const t2 = (i === (length - 1)) ? time : wave[i + 1][0];
@ -306,15 +310,21 @@ export function renderAsCommonDigital(lookup, link, wave, time) {
const a2 = {x: t1, y: 1, shift: 1}; const a2 = {x: t1, y: 1, shift: 1};
const a3 = {x: t2, y: 1, shift: 2}; const a3 = {x: t2, y: 1, shift: 2};
// 选择当前的颜色
// 颜色的定义在 gl_Colors_template 中
// 默认为 5vec 专用颜色
let color = 5; let color = 5;
const renderOptions = lookup.currentSignalRenderOptions; const renderOptions = lookup.currentSignalRenderOptions;
if (mask) { if (mask) {
if (val) {
// ? 代表 unknown比如 b1xx0xx0xx1xx000xxxx0 这种,一部分高阻的就是
color = 7;
} else {
// 颜色 4 代表高阻态
color = 4; color = 4;
} else if (renderOptions.has(link)) {
const option = renderOptions.get(link);
if (typeof option.color === 'number') {
color = option.color;
} }
} else if (userDefineCommonColor !== undefined) {
color = userDefineCommonColor;
} }
const points = [ a1, p1, a3, a2, p0, a0 ]; const points = [ a1, p1, a3, a2, p0, a0 ];
@ -474,21 +484,29 @@ function getMappingFunc(formatCode, maxVal, minVal) {
* @returns {VecRenderNumberVertices} * @returns {VecRenderNumberVertices}
*/ */
export function renderAsLadderAnalog(lookup, link, wave, time) { export function renderAsLadderAnalog(lookup, link, wave, time) {
const renderOptions = lookup.currentSignalRenderOptions;
const formatCode = getValFormatCode(lookup, link); const formatCode = getValFormatCode(lookup, link);
const signal = lookup.link2CurrentWires.get(link); const signal = lookup.link2CurrentWires.get(link);
const width = signal.size; const width = signal.size;
const { maxVal, minVal } = getMaxMinByFormat(link, wave, time, formatCode, width); const { maxVal, minVal } = getMaxMinByFormat(link, wave, time, formatCode, width);
const coordinateTransform = getMappingFunc(formatCode, maxVal, minVal); const coordinateTransform = getMappingFunc(formatCode, maxVal, minVal);
// 数值解释器,负责将对应的数值翻译成渲染用的 y
const valueRender = new JSValueRender(link, width); const valueRender = new JSValueRender(link, width);
// 获取外部自定义颜色
// 这部分颜色只会染色非异常部分的信号
let userDefineCommonColor = getUserDefineCommonColor(lookup, link);
function makeLadderAnalogRenderParam(link, wave, time) { function makeLadderAnalogRenderParam(link, wave, time) {
const [t1, val, mask] = wave; const [t1, val, mask] = wave;
if (mask) { if (mask) {
// 不定态 // 颜色 4 代表高阻态
return { y: -1, color: 4 }; // 7 代表 unknown比如 b1xx0xx0xx1xx000xxxx0 这种,一部分高阻的就是
let color = val ? 7 : 4;
return { y: -1, color };
} }
// 根据当前格式进行转换 // 根据当前格式进行转换
@ -497,11 +515,8 @@ export function renderAsLadderAnalog(lookup, link, wave, time) {
const y = coordinateTransform(numVal); const y = coordinateTransform(numVal);
const colorParam = { y, color: 5 }; const colorParam = { y, color: 5 };
if (renderOptions.has(link)) { if (userDefineCommonColor !== undefined) {
const option = renderOptions.get(link); colorParam.color = userDefineCommonColor;
if (typeof option.color === 'number') {
colorParam.color = option.color;
}
} }
return colorParam; return colorParam;
@ -631,6 +646,24 @@ function getSlope(p1, p2, p3) {
} }
} }
/**
* @description 获取用户定义这个信号的颜色只选择正常部分的颜色
* @param {GlobalLookup} lookup
* @param {string} link
* @returns {number | undefined}
*/
function getUserDefineCommonColor(lookup, link) {
const renderOptions = lookup.currentSignalRenderOptions;
if (renderOptions.has(link)) {
const option = renderOptions.get(link);
if (typeof option.color === 'number') {
return option.color;
}
}
return undefined;
}
/** /**
* @description Analog (Line) 模拟状 * @description Analog (Line) 模拟状
* @param {GlobalLookup} lookup * @param {GlobalLookup} lookup
@ -640,7 +673,6 @@ function getSlope(p1, p2, p3) {
* @returns {VecRenderNumberVertices} * @returns {VecRenderNumberVertices}
*/ */
export function renderAsLineAnalog(lookup, link, wave, time) { export function renderAsLineAnalog(lookup, link, wave, time) {
const renderOptions = lookup.currentSignalRenderOptions;
const formatCode = getValFormatCode(lookup, link); const formatCode = getValFormatCode(lookup, link);
const signal = lookup.link2CurrentWires.get(link); const signal = lookup.link2CurrentWires.get(link);
const width = signal.size; const width = signal.size;
@ -651,14 +683,24 @@ export function renderAsLineAnalog(lookup, link, wave, time) {
const length = wave.length; const length = wave.length;
const lineVertices = []; const lineVertices = [];
const maskVertices = []; const maskVertices = [];
// 数值解释器,负责将对应的数值翻译成渲染用的 y
const valueRender = new JSValueRender(link, width); const valueRender = new JSValueRender(link, width);
// 获取外部自定义颜色
// 这部分颜色只会染色非异常部分的信号
let userDefineCommonColor = getUserDefineCommonColor(lookup, link);
function makeLineAnalogRenderParam(link, wave, time) { function makeLineAnalogRenderParam(link, wave, time) {
const [t1, val, mask] = wave; const [t1, val, mask] = wave;
if (mask) { if (mask) {
// 颜色 4 代表高阻态
// 7 代表 unknown比如 b1xx0xx0xx1xx000xxxx0 这种,一部分高阻的就是
let color = val ? 7 : 4;
// 不定态 // 不定态
return { y: -1, color: 4 }; return { y: -1, color };
} }
// 根据当前格式进行转换 // 根据当前格式进行转换
@ -667,11 +709,8 @@ export function renderAsLineAnalog(lookup, link, wave, time) {
const y = coordinateTransform(numVal); const y = coordinateTransform(numVal);
const colorParam = { y, color: 5 }; const colorParam = { y, color: 5 };
if (renderOptions.has(link)) { if (userDefineCommonColor !== undefined) {
const option = renderOptions.get(link); colorParam.color = userDefineCommonColor;
if (typeof option.color === 'number') {
colorParam.color = option.color;
}
} }
return colorParam; return colorParam;