svghmi/widget_circularbar.ysl2
author Edouard Tisserant
Wed, 13 Jan 2021 10:28:09 +0100
branchsvghmi
changeset 3109 6c39d718e8cb
parent 3105 8819c8b66a42
child 3232 7bdb766c2a4d
permissions -rw-r--r--
Removed harmful assert in ProcessLogger.

ProcessLogger was having an assert in constructor when missing logger, leading to systematic exception when testing options accepted by compiler. This exception was silenced in ProjectController, and then MatIEC was always called without options.
// widget_circularbar.ysl2

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

        dispatch(value) {
            this.display_val = value;
            this.request_animate();
        }

        animate(){
            if(this.value_elt)
                this.value_elt.textContent = String(this.display_val);
            let [min,max,start,end] = this.range;
            let [cx,cy] = this.center;
            let [rx,ry] = this.proportions;
            let tip = start + (end-start)*Number(this.display_val)/(max-min);
            let size = 0;

            if (tip-start > Math.PI)
                size = 1;
            else
                size = 0;

            this.path_elt.setAttribute('d', "M "+(cx+rx*Math.cos(start))+","+(cy+ry*Math.sin(start))+
                                            " A "+rx+","+ry+
                                            " 0 "+size+
                                            " 1 "+(cx+rx*Math.cos(tip))+","+(cy+ry*Math.sin(tip)));
        }

        init() {
            let [start, end, cx, cy, rx, ry] = ["start", "end", "cx", "cy", "rx", "ry"].
                map(tag=>Number(this.path_elt.getAttribute('sodipodi:'+tag)))

            if (ry == 0) 
                ry = rx;

            if (start > end)
                end = end + 2*Math.PI;

            let [min,max] = [[this.min_elt,0],[this.max_elt,100]].map(([elt,def],i)=>elt?
                Number(elt.textContent) :
                this.args.length >= i+1 ? this.args[i] : def);

            this.range = [min, max, start, end];
            this.center = [cx, cy];
            this.proportions = [rx, ry];
        }
    }
    ||
}

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