dgaberscek@2944: // widget_circularbar.ysl2 dgaberscek@2944: usveticic@3045: template "widget[@type='CircularBar']", mode="widget_class"{ usveticic@3045: || usveticic@3045: class CircularBarWidget extends Widget{ usveticic@3045: frequency = 10; usveticic@3045: range = undefined; usveticic@3045: usveticic@3045: dispatch(value) { usveticic@3045: if(this.value_elt) usveticic@3045: this.value_elt.textContent = String(value); usveticic@3045: let [min,max,start,end] = this.range; usveticic@3045: let [cx,cy] = this.center; usveticic@3045: let [rx,ry] = this.proportions; usveticic@3045: let tip = start + (end-start)*Number(value)/(max-min); usveticic@3045: let size = 0; usveticic@3045: if (tip-start > Math.PI) { usveticic@3045: size = 1; usveticic@3045: } else { usveticic@3045: size = 0; usveticic@3045: } usveticic@3045: 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))); usveticic@3045: } usveticic@3045: usveticic@3045: init() { usveticic@3045: let start = Number(this.path_elt.getAttribute('sodipodi:start')); usveticic@3045: let end = Number(this.path_elt.getAttribute('sodipodi:end')); usveticic@3045: let cx = Number(this.path_elt.getAttribute('sodipodi:cx')); usveticic@3045: let cy = Number(this.path_elt.getAttribute('sodipodi:cy')); usveticic@3045: let rx = Number(this.path_elt.getAttribute('sodipodi:rx')); usveticic@3045: let ry = Number(this.path_elt.getAttribute('sodipodi:ry')); usveticic@3045: if (ry == 0) { usveticic@3045: ry = rx; usveticic@3045: } usveticic@3045: if (start > end) { usveticic@3045: end = end + 2*Math.PI; usveticic@3045: } usveticic@3045: let min = this.min_elt ? usveticic@3045: Number(this.min_elt.textContent) : usveticic@3045: this.args.length >= 1 ? this.args[0] : 0; usveticic@3045: let max = this.max_elt ? usveticic@3045: Number(this.max_elt.textContent) : usveticic@3045: this.args.length >= 2 ? this.args[1] : 100; usveticic@3045: this.range = [min, max, start, end]; usveticic@3045: this.center = [cx, cy]; usveticic@3045: this.proportions = [rx, ry]; usveticic@3045: } usveticic@3045: } usveticic@3045: || usveticic@3045: } dgaberscek@2944: dgaberscek@2944: template "widget[@type='CircularBar']", mode="widget_defs" { dgaberscek@2944: param "hmi_element"; dgaberscek@2944: labels("path"); dgaberscek@2944: optional_labels("value min max"); usveticic@3045: |, dgaberscek@2944: }