svghmi/widget_meter.ysl2
author usveticic
Mon, 19 Oct 2020 09:29:11 +0200
branchsvghmi
changeset 3064 4b44d09c48a7
parent 3045 f6d428330e04
child 3104 14d15712fcca
permissions -rw-r--r--
- New widget customHtml which allows to insert block of html code
- widget animate transfered to animaterotation
- widget animate, left to be more customizable
- changes to svghmi_v2/svghmi.svg
// widget_meter.ysl2

template "widget[@type='Meter']", mode="widget_class"{
    ||
    class MeterWidget extends Widget{
        frequency = 10;
        origin = undefined;
        range = undefined;

        dispatch(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);
        }

        init() {
            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);
        }

    }
    ||
}

template "widget[@type='Meter']", mode="widget_defs" {
    param "hmi_element";
    labels("needle range");
    optional_labels("value min max");
    |,
}