/*! * The MIT License (MIT) * * Copyright (c) 2016 Mykhailo Stadnyk * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * @version 2.0.9 */ !function(e){"use strict";function t(e){if(Array.isArray(e)){for(var t=0,i=Array(e.length);t1&&(d=1),t&&t(1===d?d:r(d)),s0){for(a=e.toFixed(i).toString().split("."),n=r-a[0].length;o1?(r=~i.indexOf("."),~i.indexOf("-")?"-"+[t.majorTicksInt+t.majorTicksDec+2+(r?1:0)-i.length].join("0")+i.replace("-",""):[t.majorTicksInt+t.majorTicksDec+1+(r?1:0)-i.length].join("0")+i):i}function f(e){return e*Math.PI/180}function v(e,t){return{x:-e*Math.sin(t),y:e*Math.cos(t)}}function b(e,t,i,r){var o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],n=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0,a=e.createLinearGradient(o?0:n,o?n:0,o?0:r,o?r:0);return a.addColorStop(0,t),a.addColorStop(1,i),a}function m(e,t){var i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(i)return e.restore(),!0;e.save();var r=t.borderShadowWidth;return r&&(e.shadowBlur=r,e.shadowColor=t.colorBorderShadow),!0}function g(e,t){t.needleShadow&&(e.shadowOffsetX=2,e.shadowOffsetY=2,e.shadowBlur=10,e.shadowColor=t.colorNeedleShadowDown)}function p(e,t,i){return e["font"+t+"Style"]+" "+e["font"+t+"Weight"]+" "+e["font"+t+"Size"]*i+"px "+e["font"+t]}function w(e,t,i,r,o,n){if(t.valueBox){var a=t.valueText||u(i,t);e.shadowOffsetX=null,e.shadowOffsetY=null,e.shadowBlur=null,e.shadowColor="",e.strokeStyle=null,e.lineWidth=0,e.save(),e.font=p(t,"Value",n/200),e.save(),e.beginPath();var l=.12*n,s=parseFloat(t.valueBoxStroke)||0,d=2*n-2*s,c=e.measureText(t.valueText?a:"-"+u(0,t)).width,f=c+.05*n,v=l+.07*n,b=n*t.valueBoxBorderRadius/100,m=(parseFloat(t.valueBoxWidth)||0)/100*d;m>f&&(f=m),f>d&&(f=d);var g=r-f/2,w=o-l-.04*n;b?h(e,g,w,f,v,b):e.rect(g,w,f,v);var y=o-.12*n-.025*n+(.12*n+.045*n)/2;if(t.valueBoxStroke){var T=e.createRadialGradient(r,y,n/10,r,y,n/5);T.addColorStop(0,t.colorValueBoxRect),T.addColorStop(1,t.colorValueBoxRectEnd),e.strokeStyle=T,e.lineWidth=n*t.valueBoxStroke/100,e.stroke()}t.colorValueBoxShadow&&(e.shadowBlur=.012*n,e.shadowColor=t.colorValueBoxShadow),t.colorValueBoxBackground&&(e.fillStyle=t.colorValueBoxBackground,e.fill()),e.closePath(),e.restore(),t.valueTextShadow&&(e.shadowOffsetX=.004*n,e.shadowOffsetY=.004*n,e.shadowBlur=.012*n,e.shadowColor=t.colorValueTextShadow),e.fillStyle=t.colorValueText,e.textAlign="center",e.fillText(a,g+f/2,o),e.restore()}}function y(e,t,i,r,o,n,a,l){e.beginPath(),e.fillStyle=l?ie.linearGradient(e,a,l,o>n?o:n,n>o,o>n?i:r):a,t>0?ie.roundRect(e,i,r,o,n,t):e.rect(i,r,o,n),e.fill(),e.closePath()}function T(e,t,i,r,o,n,a,l,s){e.beginPath(),e.lineWidth=t,e.strokeStyle=s?ie.linearGradient(e,l,s,a,!0,o):l,i>0?ie.roundRect(e,r,o,n,a,i):e.rect(r,o,n,a),e.stroke(),e.closePath()}function k(e,t,i,r,o,n){e.save();var a=t.borderRadius,l=o-t.borderShadowWidth-t.borderOuterWidth,s=l-t.borderOuterWidth-t.borderMiddleWidth,d=s-t.borderMiddleWidth-t.borderInnerWidth,h=d-t.borderInnerWidth,u=n-t.borderShadowWidth-t.borderOuterWidth,c=u-t.borderOuterWidth-t.borderMiddleWidth,f=c-t.borderMiddleWidth-t.borderInnerWidth,v=f-t.borderInnerWidth,b=i-(s-l)/2,m=b-(d-s)/2,g=m-(h-d)/2,p=r-(c-u)/2,w=p-(f-c)/2,k=w-(v-f)/2,x=0,S=!1;return t.borderOuterWidth&&(S=ie.drawShadow(e,t,S),T(e,t.borderOuterWidth,a,i+t.borderOuterWidth/2-x,r+t.borderOuterWidth/2-x,l,u,t.colorBorderOuter,t.colorBorderOuterEnd),x+=.5),t.borderMiddleWidth&&(S=ie.drawShadow(e,t,S),T(e,t.borderMiddleWidth,a-=1+2*x,b+t.borderMiddleWidth/2-x,p+t.borderMiddleWidth/2-x,s+2*x,c+2*x,t.colorBorderMiddle,t.colorBorderMiddleEnd),x+=.5),t.borderInnerWidth&&(S=ie.drawShadow(e,t,S),T(e,t.borderInnerWidth,a-=1+2*x,m+t.borderInnerWidth/2-x,w+t.borderInnerWidth/2-x,d+2*x,f+2*x,t.colorBorderInner,t.colorBorderInnerEnd),x+=.5),ie.drawShadow(e,t,S),y(e,a,g,k,h+2*x,v+2*x,t.colorPlate,t.colorPlateEnd),e.restore(),[g,k,h,v]}function x(e,t,i,r,o,n){var a=J.pixelRatio,l=n>=o,s=l?.85*o:n,d=l?n:o;i=l?K(i+(o-s)/2):i;var h=!!t.title,u=!!t.units,c=!!t.valueBox,f=void 0,v=void 0,b=void 0;l?(v=K(.05*d),f=K(.075*d),b=K(.075*d),h&&(d-=f,r+=f),u&&(d-=v),c&&(d-=b)):(v=f=K(.15*s),h&&(s-=f,r+=f),u&&(s-=v));var m=2*t.barStrokeWidth,g=t.barBeginCircle?K(s*t.barBeginCircle/200-m/2):0,p=K(s*t.barWidth/100-m),w=K(d*t.barLength/100-m),y=K((d-w)/2),T=K(i+(l?s/2:y+g)),k=K(r+(l?d-y-g+m/2:s/2)),x=!l||t.hasLeft&&t.hasRight?0:(t.hasRight?-1:1)*t.ticksWidth/100*s,S=l||t.hasLeft&&t.hasRight?0:(t.hasRight?-1:1)*t.ticksWidth/100*s;return e.barDimensions={isVertical:l,width:s,length:d,barWidth:p,barLength:w,strokeWidth:m,barMargin:y,radius:g,pixelRatio:a,barOffset:null,titleMargin:h?f:0,unitsMargin:u?v:0,get ticksLength(){return this.barLength-this.barOffset-this.strokeWidth},X:i+x,Y:r+S,x0:T+x,y0:k+S,baseX:i,baseY:r,ticksPadding:t.ticksPadding/100},e.barDimensions}function S(e,t,i,r,o,n,a){var l=x(e,t,r,o,n,a),s=l.isVertical,d=l.width,h=l.barWidth,u=l.barLength,c=l.strokeWidth,f=l.barMargin,v=l.radius,b=l.x0,m=l.y0,g=l.X,p=l.Y,w=u;if(e.save(),e.beginPath(),t.barBeginCircle){var y=ie.radians(s?270:0),T=Math.asin(h/2/v),k=Math.cos(T),S=Math.sin(T),W=b+(s?v*S:v*k-c/2),O=s?m-v*k:m+v*S,B=Q(s?O-m:W-b);e.barDimensions.barOffset=K(B+v);var M=s?K(b-v*S):W,V=s?O:K(m-v*S);"progress"===i&&(u=e.barDimensions.barOffset+(u-e.barDimensions.barOffset)*(t.value-t.minValue)/(t.maxValue-t.minValue));var j=K(W+u-e.barDimensions.barOffset+c/2),P=K(O-u+e.barDimensions.barOffset-c/2);e.arc(b,m,v,y+T,y-T),s?(e.moveTo(W,V),e.lineTo(W,P),e.lineTo(M,P),e.lineTo(M,V)):(e.moveTo(W,V),e.lineTo(j,V),e.lineTo(j,O),e.lineTo(W,O))}else{var N=K(s?g+(d-h)/2:g+f),C=K(s?p+u+f:p+(d-h)/2);"progress"===i&&(u*=(t.value-t.minValue)/(t.maxValue-t.minValue)),s?e.rect(N,C,h,-u):e.rect(N,C,u,h)}"progress"!==i&&t.barStrokeWidth&&(e.lineWidth=c,e.strokeStyle=t.colorBarStroke,e.stroke()),"progress"!==i&&t.colorBar?(e.fillStyle=t.colorBarEnd?ie.linearGradient(e,t.colorBar,t.colorBarEnd,u,s,s?p:g):t.colorBar,e.fill()):"progress"===i&&t.colorBarProgress&&(e.fillStyle=t.colorBarProgressEnd?ie.linearGradient(e,t.colorBarProgress,t.colorBarProgressEnd,w,s,s?p:g):t.colorBarProgress,e.fill()),e.closePath(),t.barBeginCircle&&(e.barDimensions.radius+=c),e.barDimensions.barWidth+=c,e.barDimensions.barLength+=c}function W(e,t,i,r,o,n){S(e,t,"",i,r,o,n)}function O(e,t){return t.needleSide!==e||t.tickSide!==e||t.numberSide!==e}function B(e,t,i,r,o,n){t.barProgress&&S(e,t,"progress",i,r,o,n)}function M(e,t){var i=e.barDimensions,r=i.isVertical,o=i.width,n=i.length,a=i.barWidth,l=i.barOffset,s=i.barMargin,d=i.X,h=i.Y,u=i.ticksLength,c=i.ticksPadding,f=o*(parseFloat(t.highlightsWidth)||0)/100;if(t.highlights&&f){var v="right"!==t.tickSide,b="left"!==t.tickSide,m=0,g=t.highlights.length,p=(o-a)/2,w=t.maxValue-t.minValue,y=K(r?d+p:d+s+l),T=f,k=r?h+n-s-l:h+p,x=K((t.ticksWidth/100+c)*o)+(f-t.ticksWidth/100*o),S=K(a+c*o);for(e.save();mn&&(d*=-1),e.moveTo(i-u,r),e.lineTo(i+u,r),e.lineTo(i+u,r+d),e.lineTo(i,n),e.lineTo(i-u,r+d),e.lineTo(i-u,r)):(i>o&&(d*=-1),e.moveTo(i,r-u),e.lineTo(i,r+u),e.lineTo(i+d,r+u),e.lineTo(o,r),e.lineTo(i+d,r-u),e.lineTo(i,r-u)),e.fill(),e.closePath()}function Y(e,t,i,r,o,n,a){e.barDimensions.isVertical&&ie.drawValueBox(e,t,i,r+n/2,o+a-40*(n/300),n)}var z=function e(t,i,r){null===t&&(t=Function.prototype);var o=Object.getOwnPropertyDescriptor(t,i);if(void 0===o){var n=Object.getPrototypeOf(t);return null===n?void 0:e(n,i,r)}if("value"in o)return o.value;var a=o.get;if(void 0!==a)return a.call(r)},_=function(){function e(e,t){var i=[],r=!0,o=!1,n=void 0;try{for(var a,l=e[Symbol.iterator]();!(r=(a=l.next()).done)&&(i.push(a.value),!t||i.length!==t);r=!0);}catch(e){o=!0,n=e}finally{try{!r&&l.return&&l.return()}finally{if(o)throw n}}return i}return function(t,i){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),F=function(){function e(e,t){for(var i=0;i>>0;if(0===o)return-1;var n=+t||0;if(Math.abs(n)===1/0&&(n=0),n>=o)return-1;for(i=Math.max(n>=0?n:o-Math.abs(n),0);i>>0,r=arguments[1],o=r>>0,n=o<0?Math.max(i+o,0):Math.min(o,i),a=arguments[2],l=void 0===a?i:a>>0,s=l<0?Math.max(i+l,0):Math.min(l,i);n=(7-4*t)/11)return-Math.pow((11-6*t-11*e)/4,2)+Math.pow(i,2)},elastic:function(e){return 1-q.delastic(1-e)},delastic:function(e){var t=1.5;return Math.pow(2,10*(e-1))*Math.cos(20*Math.PI*t/3*e)}},U=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"linear",i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:250,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){};if(o(this,t),this.duration=i,this.rule=e,this.draw=r,this.end=n,"function"!=typeof this.draw)throw new TypeError("Invalid animation draw callback:",r);if("function"!=typeof this.end)throw new TypeError("Invalid animation end callback:",n)}return F(t,[{key:"animate",value:function(t,i){var r=this,o=e.performance&&e.performance.now?e.performance.now():n("animationStartTime")||Date.now();t=t||this.draw,i=i||this.end,this.frame=G(function(e){return a(e,t,o,q[r.rule]||r.rule,r.duration,i,r)})}},{key:"destroy",value:function(){if(this.frame){var e=n("cancelAnimationFrame")||function(e){};e(this.frame),this.frame=null}this.draw=null,this.end=null}}]),t}();U.rules=q;var H=function(){function t(i,r,n){o(this,t),this.options=i,this.element=r.toLowerCase(),this.type=t.toDashed(n),this.Type=e[n],this.mutationsObserved=!1,this.isObservable=!!e.MutationObserver,t.domReady(this.traverse.bind(this))}return F(t,[{key:"isValidNode",value:function(e){return!(!e.tagName||e.tagName.toLowerCase()!==this.element||e.getAttribute("data-type")!==this.type)}},{key:"traverse",value:function(){for(var t=document.getElementsByTagName(this.element),i=0,r=t.length;i=e.barWidth&&(e.barStrokeWidth=K(e.barWidth/2)),e.hasLeft=O("right",e),e.hasRight=O("left",e),i(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e))}return r(n,e),F(n,[{key:"draw",value:function(){try{var e=this.canvas,i=[-e.drawX,-e.drawY,e.drawWidth,e.drawHeight],r=i[0],o=i[1],a=i[2],l=i[3],s=this.options;if(!e.elementClone.initialized){var d=e.contextClone;d.clearRect(r,o,a,l),d.save(),this.drawBox=k(d,s,r,o,a,l),W.apply(void 0,[d,s].concat(t(this.drawBox))),e.context.barDimensions=d.barDimensions,M(d,s),C(d,s),P(d,s),E(d,s),D(d,s),A(d,s),e.elementClone.initialized=!0}this.canvas.commit(),e.context.clearRect(r,o,a,l),e.context.save(),e.context.drawImage(e.elementClone,r,o,a,l),e.context.save(),B.apply(void 0,[e.context,s].concat(t(this.drawBox))),R(e.context,s),Y.apply(void 0,[e.context,s,s.animatedValue?this.options.value:this.value].concat(t(this.drawBox))),z(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"draw",this).call(this)}catch(e){ie.verifyError(e)}return this}}]),n}(te);"undefined"!=typeof e&&(e.LinearGauge=oe),te.initialize("LinearGauge",re),"undefined"!=typeof module&&Object.assign(e,{Collection:l,GenericOptions:Z,Animation:U,BaseGauge:te,drawings:ie,SmartCanvas:J,vendorize:n})}("undefined"!=typeof module?module.exports:window);