@nwebui/react-niagara-px
Version:
React Niagara Px View
67 lines • 1.98 kB
JavaScript
import Converter from "./Converter";
export default class INumericToSimple extends Converter {
constructor(nativeConverter) {
super(nativeConverter);
}
convert(widget, target) {
if (!target.isComplex()) {
console.warn("INumericToSimple for non complex not implemented");
return;
}
const converter = this.nativeConverter;
const name = converter.name();
const num = target.get("out", "value");
const v = num.value;
const map = new NumericToSimpleMap(converter.get("map") + "");
const mappedValue = map.map(v);
const image = widget.get(name);
widget.set(name, image.decodeFromString(mappedValue));
}
}
class NumericToSimpleMap {
type;
mapping = [];
default = "";
parseNum(s) {
if (s === "+inf") {
return Infinity;
}
else if (s === "-inf") {
return -Infinity;
}
return +s;
}
constructor(mapstr) {
const i = mapstr.indexOf(" ");
this.type = mapstr.substring(0, i);
const maps = mapstr
.substring(i + 1)
.split(";")
.filter((x) => x);
this.mapping = [];
maps.forEach((m) => {
const ss = m.split("=", 2);
if (ss[0] === "default") {
this.default = ss[1];
}
else {
const ss2 = ss[0].split(":", 2);
this.mapping.push([
this.parseNum(ss2[0]),
this.parseNum(ss2[1]),
ss[1],
]);
}
});
}
map(v) {
const ret = this.default;
for (const m of this.mapping) {
if (v >= m[0] && v <= m[1]) {
return m[2];
}
}
return ret;
}
}
//# sourceMappingURL=INumericToSimple.js.map