edouard@2883: // widget_meter.ysl2 Edouard@2792: usveticic@3045: template "widget[@type='Meter']", mode="widget_class"{ usveticic@3045: || usveticic@3045: class MeterWidget extends Widget{ usveticic@3045: frequency = 10; usveticic@3045: origin = undefined; usveticic@3045: range = undefined; usveticic@3045: usveticic@3045: dispatch(value) { edouard@3104: this.display_val = value; edouard@3104: this.request_animate(); edouard@3104: } edouard@3104: edouard@3104: animate(){ usveticic@3045: if(this.value_elt) edouard@3104: this.value_elt.textContent = String(this.display_val); usveticic@3045: let [min,max,totallength] = this.range; edouard@3104: let length = Math.max(0,Math.min(totallength,(Number(this.display_val)-min)*totallength/(max-min))); usveticic@3045: let tip = this.range_elt.getPointAtLength(length); usveticic@3045: this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y); usveticic@3045: } usveticic@3045: usveticic@3045: init() { edouard@3104: let [min,max] = [[this.min_elt,0],[this.max_elt,100]].map(([elt,def],i)=>elt? edouard@3104: Number(elt.textContent) : edouard@3104: this.args.length >= i+1 ? this.args[i] : def); edouard@3104: usveticic@3045: this.range = [min, max, this.range_elt.getTotalLength()] usveticic@3045: this.origin = this.needle_elt.getPointAtLength(0); usveticic@3045: } usveticic@3045: usveticic@3045: } usveticic@3045: || usveticic@3045: } Edouard@2790: edouard@2883: template "widget[@type='Meter']", mode="widget_defs" { edouard@2883: param "hmi_element"; edouard@2883: labels("needle range"); edouard@2883: optional_labels("value min max"); edouard@2883: } Edouard@2810: Edouard@2810: