Skip to content

Commit

Permalink
getLabel as module
Browse files Browse the repository at this point in the history
  • Loading branch information
drom committed Feb 5, 2024
1 parent 9191ee7 commit 00b39d9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
32 changes: 32 additions & 0 deletions lib/get-label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

const getLabel = (vPre, mPre, x, w, fmt) => {
const radix = (fmt || {}).radix;
const base = ({
b: 2, o: 8, d: 10, h: 16, H: 16
})[radix] || 16;

if (mPre) {
if (vPre) {
return ['text', {x, class: 'zxviolet'}, '?'];
} else {
return ['text', {x, class: 'xred'}, 'x'];
}
} else {
const numPos = (w / 8) |0;
let txtOrig = vPre.toString(base);
if (radix === 'H') {
txtOrig = txtOrig.toUpperCase();
}

// ? txtOrig.slice(0, numPos - 1) + '\u22ef' // MSB
const txtShort = (txtOrig.length > numPos)
? ((numPos === 1)
? '\u22EE'
: '\u22EF' + txtOrig.slice(1 - numPos)) // LSB
: txtOrig;
return ['text', {x}, ['title', txtOrig], txtShort]; // idx.toString(36)]);
}
};

module.exports = getLabel;
30 changes: 1 addition & 29 deletions lib/render-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const bracer = require('./bracer.js');
const vline = require('./vline.js');
const getX = require('./get-x.js');
const vlineStylo = require('./vline-stylo.js');
const getLabel = require('./get-label.js');

const defs = ['defs',
['linearGradient', {id: 'valid'},
Expand All @@ -33,35 +34,6 @@ const defs = ['defs',
})
];

const getLabel = (vPre, mPre, x, w, fmt) => {
const radix = (fmt || {}).radix;
const base = ({
b: 2, o: 8, d: 10, h: 16, H: 16
})[radix] || 16;

if (mPre) {
if (vPre) {
return ['text', {x, class: 'zxviolet'}, '?'];
} else {
return ['text', {x, class: 'xred'}, 'x'];
}
} else {
const numPos = (w / 8) |0;
let txtOrig = vPre.toString(base);
if (radix === 'H') {
txtOrig = txtOrig.toUpperCase();
}

// ? txtOrig.slice(0, numPos - 1) + '\u22ef' // MSB
const txtShort = (txtOrig.length > numPos)
? ((numPos === 1)
? '\u22EE'
: '\u22EF' + txtOrig.slice(1 - numPos)) // LSB
: txtOrig;
return ['text', {x}, ['title', txtOrig], txtShort]; // idx.toString(36)]);
}
};

const renderValues = function* (desc, pstate) {
const { width, height, sidebarWidth, yOffset, yStep, topBarHeight, botBarHeight } = pstate;
const { view } = desc;
Expand Down

0 comments on commit 00b39d9

Please sign in to comment.