diff --git a/data/index.htm b/data/index.htm
index 5a33da50..8685f7ba 100644
--- a/data/index.htm
+++ b/data/index.htm
@@ -29,7 +29,7 @@
-
diff --git a/data/index.js b/data/index.js
index 3315327e..b1dca7d6 100644
--- a/data/index.js
+++ b/data/index.js
@@ -90,6 +90,26 @@ function makeWS() {
}
}
+function linearToLogarithm(json, value) {
+ if (value == 0) return 0;
+
+ var minp = json.min?json.min:0;
+ var maxp = json.max?json.max:255;
+
+ // The result should be between 100 an 10000000
+ var minv = minp?Math.log(minp):0;
+ var maxv = Math.log(maxp);
+
+ // calculate adjustment factor
+ var scale = (maxv-minv) / (maxp - minp);
+
+ let result = Math.exp(minv + scale*(value-minp));
+
+ console.log(json, minv, maxv, scale, result);
+
+ return Math.round(result);
+}
+
function generateHTML(parentNode, json, rowNr = -1) {
// console.log("generateHTML", parentNode, json);
if (Array.isArray(json)) {
@@ -221,7 +241,7 @@ function generateHTML(parentNode, json, rowNr = -1) {
let valueNode = cE("a");
valueNode.setAttribute('href', json.value);
- valueNode.setAttribute('target', "_blank");
+ // valueNode.setAttribute('target', "_blank"); //does not work well on mobile
valueNode.innerText = json.value;
if (rowNr == -1) {
@@ -263,21 +283,19 @@ function generateHTML(parentNode, json, rowNr = -1) {
valueNode.type = json.type;
valueNode.min = json.min?json.min:0;
valueNode.max = json.max?json.max:255; //range slider default 0..255
- // valueNode.addEventListener('input', (event) => {console.log(json.type + " input", event);gId(json.id + "_rv").innerText = this.value;});
valueNode.disabled = json.ro;
if (json.value) valueNode.value = json.value;
//numerical ui value changes while draging the slider (oninput)
valueNode.addEventListener('input', (event) => {
- gId(json.id + "_rv").innerText = event.target.value;
+ gId(json.id + "_rv").innerText = json.log?linearToLogarithm(json, event.target.value):event.target.value;
});
//server value changes after draging the slider (onchange)
valueNode.addEventListener('change', (event) => {
- console.log(json.type + " change", event.target, json.id);
setInput(event.target);
});
rangeValueNode = cE("span");
rangeValueNode.id = json.id + "_rv"; //rangeValue
- if (json.value) rangeValueNode.innerText = json.value;
+ if (json.value) rangeValueNode.innerText = json.log?linearToLogarithm(json, json.value):json.value;
} else {
//input types: text, search, tel, url, email, and password.
@@ -306,6 +324,8 @@ function generateHTML(parentNode, json, rowNr = -1) {
}
else {
if (json.max) valueNode.setAttribute('maxlength', json.max); //for text and textarea set max length valueNode.maxlength is not working for some reason
+ if (json.id == "serverName")
+ gId("instanceName").innerText = json.value;
}
}
} //not checkbox or button or range
@@ -386,7 +406,7 @@ function processUpdate(json) {
else { //uiFun or {variable:{label:value}}
for (var key of Object.keys(json)) {
if (key != "uiFun") { //was the request
- if (gId(key)) {
+ if (gId(key)) { //is the key a var?
processVarNode(gId(key), key, json[key]);
}
else
@@ -400,7 +420,8 @@ function processVarNode(node, key, json) {
let overruleValue = false;
if (json.hasOwnProperty("label")) {
- console.log("processUpdate label", key, json.label);
+ if (key != "insTbl") // tbd: table should not update
+ console.log("processVarNode label", key, json.label);
if (node.nodeName.toLocaleLowerCase() == "input" && node.type == "button") {
node.value = initCap(json.label);
}
@@ -416,7 +437,8 @@ function processVarNode(node, key, json) {
}
}
if (json.hasOwnProperty("comment")) {
- console.log("processUpdate comment", key, json.comment);
+ if (key != "insTbl") // tbd: table should not update
+ console.log("processVarNode comment", key, json.comment);
// normal:
// table or canvas