implement configuration of format for numbers display

- '*' for a default (5 signiciant digits)
- '*<dig>' for an other number of significant digits
- '*.<dig>' for fixed number of digits after decimal point
This commit is contained in:
2026-04-10 12:47:17 +02:00
parent b3a43af6fd
commit 3ec80585b1
+17 -6
View File
@@ -8,6 +8,10 @@ var description;
var changeFuncs = {};
var updateValues = {};
function formatValue(value, prec) {
return Number(value.toPrecision(prec)).toString();
}
function handle_describing(action, modpar, data) {
description = data;
for (const mod of Object.keys(data.modules)) {
@@ -43,8 +47,14 @@ function handle_describing(action, modpar, data) {
if (func.includes("text")) {
const pat = elem.textContent;
changeFuncs[mod + ":" + (param || 'value')] = function (value) {
elem.textContent = pat.replace('*', value.toFixed(1));
elem.style.fill = "#d5d5d5";
let [repl, dot, fix] = pat.match(/\*(\.)?(\d)?/);
if (dot) {
formatted = value.toFixed(fix || 0);
} else {
formatted = formatValue(value, fix || 5);
}
elem.textContent = pat.replace(repl, formatted);
// elem.style.color = "000000";
}
}
if (func.includes("command")) {
@@ -55,6 +65,7 @@ function handle_describing(action, modpar, data) {
}
})
if (stateElement && clickElement) {
// the clickElement needs a reference to the state for toggleTarget()
clickElement.stateElement = stateElement;
}
}
@@ -115,12 +126,12 @@ function updateState(state) {
}
function changeFill(element, state) {
stateElement = element.stateElement || element;
stateElement.state = state;
// stateElement = element.stateElement || element;
element.state = state;
if (state in colors) {
stateElement.style.fill = colors[state];
element.style.fill = colors[state];
} else {
stateElement.style.fill = "#eaeaea" ;
element.style.fill = "#eaeaea" ;
}
}