svghmi/widget_meter.ysl2
branchsvghmi
changeset 2883 8e3d130399b0
parent 2882 ac08a5d15c15
child 3045 f6d428330e04
equal deleted inserted replaced
2882:ac08a5d15c15 2883:8e3d130399b0
       
     1 // widget_meter.ysl2
       
     2 
       
     3 
       
     4 template "widget[@type='Meter']", mode="widget_defs" {
       
     5     param "hmi_element";
       
     6     |     frequency: 10,
       
     7     labels("needle range");
       
     8     optional_labels("value min max");
       
     9     |     dispatch: function(value) {
       
    10     |         if(this.value_elt)
       
    11     |             this.value_elt.textContent = String(value);
       
    12     |         let [min,max,totallength] = this.range;
       
    13     |         let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
       
    14     |         let tip = this.range_elt.getPointAtLength(length);
       
    15     |         this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
       
    16     |     },
       
    17     |     origin: undefined,
       
    18     |     range: undefined,
       
    19     |     init: function() {
       
    20     |         let min = this.min_elt ?
       
    21     |                     Number(this.min_elt.textContent) :
       
    22     |                     this.args.length >= 1 ? this.args[0] : 0;
       
    23     |         let max = this.max_elt ?
       
    24     |                     Number(this.max_elt.textContent) :
       
    25     |                     this.args.length >= 2 ? this.args[1] : 100;
       
    26     |         this.range = [min, max, this.range_elt.getTotalLength()]
       
    27     |         this.origin = this.needle_elt.getPointAtLength(0);
       
    28     |     },
       
    29 }
       
    30 
       
    31