svghmi/widget_meter.ysl2
author Edouard Tisserant
Thu, 04 Jun 2020 11:14:21 +0200
branchsvghmi
changeset 2980 2a21d6060d64
parent 2883 8e3d130399b0
child 3045 f6d428330e04
permissions -rw-r--r--
SVGHMI: add "unsubscribable" property to widgets in order to generalize what already happens for jump buttons.
In most cases jump buttons do not really subscribe to pointed HMI variable, path is given as a relative page jump path. When widget.unsubscribable is set to true, no subscription is made on page switch, but still offset is updated.
This fixes bug happening on relative jump buttons without "disabled" element where offset did not change on relative page switch.
// widget_meter.ysl2


template "widget[@type='Meter']", mode="widget_defs" {
    param "hmi_element";
    |     frequency: 10,
    labels("needle range");
    optional_labels("value min max");
    |     dispatch: function(value) {
    |         if(this.value_elt)
    |             this.value_elt.textContent = String(value);
    |         let [min,max,totallength] = this.range;
    |         let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
    |         let tip = this.range_elt.getPointAtLength(length);
    |         this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
    |     },
    |     origin: undefined,
    |     range: undefined,
    |     init: function() {
    |         let min = this.min_elt ?
    |                     Number(this.min_elt.textContent) :
    |                     this.args.length >= 1 ? this.args[0] : 0;
    |         let max = this.max_elt ?
    |                     Number(this.max_elt.textContent) :
    |                     this.args.length >= 2 ? this.args[1] : 100;
    |         this.range = [min, max, this.range_elt.getTotalLength()]
    |         this.origin = this.needle_elt.getPointAtLength(0);
    |     },
}