diff --git a/dist/integrity.txt b/dist/integrity.txt new file mode 100644 index 0000000..8136291 --- /dev/null +++ b/dist/integrity.txt @@ -0,0 +1 @@ +vgauge-1.0.3.min.js" integrity="sha384-CHO+7z8zcSwLXXCTCa9fzKJqv5Koiu1opo6vcZNl/ByNUrkhRM8cuyBHiP0PKGQ4" crossorigin="anonymous" diff --git a/dist/vgauge-1.0.3.min.js b/dist/vgauge-1.0.3.min.js new file mode 100644 index 0000000..182ae27 --- /dev/null +++ b/dist/vgauge-1.0.3.min.js @@ -0,0 +1,85 @@ +// vgauge.js 1.0.3, copyright (c) 2024 A.J.Bauer, licensed under the MIT License,see LICENSE.txt for full license text. + +class VGauge{static isNonEmptyString(s){return typeof s==='string'&&s!=='';} +static isInteger(n){return Number.isInteger(parseInt(n));} +static isBoolean(b){return typeof b==='boolean';} +static isNonEmptyArray(a){return Array.isArray(a)&&a.length>0;} +static hexRgbForColor(color){let hr,hg,hb;if(color.startsWith('#')){if(color.length===4){hr=color.charAt(1);hg=color.charAt(2);hb=color.charAt(3);return'#'+hr+hr+hg+hg+hb+hb;}else{return color.substring(0,8);}}else if(color.startsWith('rgb')){const allInts=color.match(/\d+/g);if(allInts.length>2){return'#'+parseInt(allInts[0]).toString(16)+parseInt(allInts[1]).toString(16)+parseInt(allInts[2]).toString(16);}else{console.error(this.constructor.name+': unexpected value for rgb color');return'#ff0000';}}else if(color.length>0){console.error(this.constructor.name+': unsupported color');}} +static _getObjectInitializer(obj,n,t,c){const ld='\r\n';t=(t===undefined?0:t);c=(c===undefined?false:c);let str=' '.repeat(t)+'{'+ld;t+=n;const last=Object.keys(obj).slice(-1)[0];for(const[key,value]of Object.entries(obj)){if(obj.hasOwnProperty(key)){if(Array.isArray(value)){str+=' '.repeat(t)+key+': ['+ld;for(var i=0;i{const textPoint={x:0,y:0};const rotate=angleMath.PI?'1':'0')+' 1 '+point1.x+' '+point1.y+' ' ++'L '+point2.x+','+point2.y+' ' ++'A '+this._settings.cluster.outerRadius+' '+this._settings.cluster.outerRadius+' '+(angle-prevAngle)*180.0/Math.PI+' ' ++(angle-prevAngle>Math.PI?'1':'0')+' 0 '+prevPoint2.x+' '+prevPoint2.y+' ' ++'L '+prevPoint1.x+','+prevPoint1.y+' Z';const path=Array.from(this._svgElems.cluster.querySelectorAll('path'))[i];path.setAttribute('d',d);path.setAttribute('opacity',sector.opacity);if(VGauge.isNonEmptyString(sector.fill)){path.setAttribute('fill',VGauge.hexRgbForColor(sector.fill));} +else{path.setAttribute('fill',VGauge.hexRgbForColor(this._currentColor));} +if(this._settings.cluster.useTickLabels){if(i===0){addSvgTickLabel(this._settings.min,this._settings.startAngle*Math.PI/180.0);} +addSvgTickLabel(sector.sweepTo,angle);} +prevSweepTo=sector.sweepTo;prevAngle=angle;}} +if(this._settings.targetValue){if(VGauge.isNonEmptyString(this._settings.targetValue.indicator.path)){const d=(new DOMParser).parseFromString(this._settings.targetValue.indicator.path,"image/svg+xml").querySelector('[d]').getAttribute('d');this._svgElems.targetValueIndicator.setAttribute('d',d);} +if(VGauge.isNonEmptyString(this._settings.targetValue.indicator.fill)){this._svgElems.targetValueIndicator.setAttribute('fill',this._settings.targetValue.indicator.fill);}else{this._svgElems.targetValueIndicator.setAttribute('fill','currentColor');} +if(VGauge.isNonEmptyString(this._settings.targetValue.label.fontSize)){this._svgElems.targetValueLabel.setAttribute('font-size',this._settings.targetValue.label.fontSize);} +if(VGauge.isNonEmptyString(this._settings.targetValue.label.fill)){this._svgElems.targetValueLabel.setAttribute('fill',this._settings.targetValue.label.fill);}else{this._svgElems.targetValueLabel.setAttribute('fill','currentColor');} +this._svgElems.targetValueLabel.setAttribute('text-anchor','middle');this._svgElems.targetValueLabel.setAttribute('dominant-baseline','alphabetic');} +if(this._settings.targetValue){this.targetValue=this._settings.targetValue.min;} +this._initialized=true;this.refresh();} +else{console.error(this.constructor.name+': could not find container for id '+this._id);}} +_update(){const prevAngle=this._settings.startAngle*Math.PI/180.0;let angle=this._settings.startAngle*Math.PI/180.0+(this._value-this._settings.min)*this._settings.sweepAngle/(this._settings.max-this._settings.min)*Math.PI/180.0;const prevPoint1={x:this._settings.indicator.innerRadius*Math.cos(prevAngle),y:this._settings.indicator.innerRadius*Math.sin(prevAngle)};const prevPoint2={x:this._settings.indicator.outerRadius*Math.cos(prevAngle),y:this._settings.indicator.outerRadius*Math.sin(prevAngle)};const point1={x:this._settings.indicator.innerRadius*Math.cos(angle),y:this._settings.indicator.innerRadius*Math.sin(angle)};const point2={x:this._settings.indicator.outerRadius*Math.cos(angle),y:this._settings.indicator.outerRadius*Math.sin(angle)};this._svgElems.value.innerHTML=this._value.toFixed(this._settings.tweek.value.decimals);const d='M '+prevPoint1.x+','+prevPoint1.y+' ' ++'A '+this._settings.indicator.innerRadius+' '+this._settings.indicator.innerRadius+' '+(angle-prevAngle)*180.0/Math.PI+' ' ++(angle-prevAngle>Math.PI?'1':'0')+' 1 '+point1.x+' '+point1.y+' ' ++'L '+point2.x+','+point2.y+' ' ++'A '+this._settings.indicator.outerRadius+' '+this._settings.indicator.outerRadius+' '+(angle-prevAngle)*180.0/Math.PI+' ' ++(angle-prevAngle>Math.PI?'1':'0')+' 0 '+prevPoint2.x+' '+prevPoint2.y+' ' ++'L '+prevPoint1.x+','+prevPoint1.y+' Z';if(this._settings.cluster&&VGauge.isNonEmptyArray(this._settings.cluster.sectors)){let sector=this._settings.cluster.sectors.find(x=>x.sweepTo>=this._value);if(sector===undefined){sector=this._settings.cluster.sectors[0];} +if(VGauge.isNonEmptyString(sector.fill)){this._svgElems.valueSector.setAttribute('fill',VGauge.hexRgbForColor(sector.fill));}else{this._svgElems.valueSector.setAttribute('fill',VGauge.hexRgbForColor(this._currentColor));}} +else{this._svgElems.valueSector.setAttribute('fill',VGauge.hexRgbForColor(this._currentColor));this._svgElems.valueSector.setAttribute('opacity',1);} +this._svgElems.valueSector.setAttribute('d',d);if(this._settings.targetValue){const tipPoint={x:0,y:0};angle=this._settings.startAngle*Math.PI/180.0+(this._targetValue-this._settings.min)*this._settings.sweepAngle/(this._settings.max-this._settings.min)*Math.PI/180.0;tipPoint.x=this._settings.targetValue.indicator.radius*Math.cos(angle);tipPoint.y=this._settings.targetValue.indicator.radius*Math.sin(angle);let rotate=angle*180.0/Math.PI-90;let transform='translate('+tipPoint.x+','+tipPoint.y+') rotate('+rotate+')';this._svgElems.targetValueIndicator.setAttribute('transform',transform);const rotateLabel=angle0&&this._height>0){this._update();}} +get min(){return this._settings.min;} +get max(){return this._settings.max;} +get settings(){return this._settings;} +set settings(obj){this._settings=obj;} +set value(value){if(this._value!==value){if(valuethis._max){this._value=this._max;} +else{this._value=parseFloat(value);} +if(this._initialized){this._update();}}} +get value(){return this._value;} +set targetValue(value){if(this._settings.targetValue){if(value!==this._targetValue){if(valuethis._settings.targetValue.max){this._targetValue=parseFloat(this._settings.targetValue.max);} +else{this._targetValue=parseFloat(value);} +this._update();}}} +get targetValue(){return this._targetValue;} +get gridOpacity(){const grid=this._svgElems.helperGrid;if(grid){return parseFloat(grid.getAttribute('opacity'));} +return 0;} +set gridOpacity(o){const grid=this._svgElems.helperGrid;if(grid){grid.setAttribute('opacity',o);}} +setIconOpacity(id,opacity){const icon=this._container.querySelector('[rid="'+id+'"]');if(icon){icon.setAttribute('opacity',opacity);}}} \ No newline at end of file