svghmi/widget_meter.ysl2
author Edouard Tisserant
Thu, 25 Mar 2021 10:13:12 +0100
branchsvghmi
changeset 3199 1582753e409b
parent 3104 14d15712fcca
child 3232 7bdb766c2a4d
permissions -rw-r--r--
SVGHMI: Filter unseen geometry from inkscape CSV output.

When inkscape exports geometry form all objects, then it also includes objects from svg:defs. This makes problems when deciding if an object is part of a page, since coordinate of objects in svg:defs can eventualy be contained in a page. In the end, those objects where getting detached when leaving pages where they where found, leading for exemple to non working text on clipping when the clipped text was cloned in multiple page.
// widget_meter.ysl2

template "widget[@type='Meter']", mode="widget_class"{
    ||
    class MeterWidget extends Widget{
        frequency = 10;
        origin = undefined;
        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,totallength] = this.range;
            let length = Math.max(0,Math.min(totallength,(Number(this.display_val)-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,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, 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");
}