peltier_jacket/gauge.min.js
2016-10-14 00:58:31 +02:00

26 lines
29 KiB
JavaScript

/*!
* The MIT License (MIT)
*
* Copyright (c) 2016 Mykhailo Stadnyk <mikhus@gmail.com>
*
* 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);t<e.length;t++)i[t]=e[t];return i}return Array.from(e)}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if(t||(t="undefined"==typeof window?global:window),"undefined"!=typeof t[e])return t[e];for(var i=["webkit","moz","ms","o"],r=0,o=i.length,n=e.charAt(0).toUpperCase()+e.substr(1);r<o;r++){var a=t[i[r]+n];if("undefined"!=typeof a)return a}return null}function a(e,t,i,r,o,n,l){if("function"!=typeof r)throw new TypeError("Invalid animation rule:",r);var s=e-i,d=s/o;d>1&&(d=1),t&&t(1===d?d:r(d)),s<o?l.frame=G(function(e){return a(e,t,i,r,o,n,l)}):n&&n()}function l(){Array.prototype.constructor.apply(this,arguments)}function s(e){if(!(e instanceof DOMException&&2152923147===e.result))throw e}function d(e){return e.majorTicks instanceof Array||(e.majorTicks=e.majorTicks?[e.majorTicks]:[]),e.majorTicks.length||(e.majorTicks.push(ie.formatMajorTickNumber(e.minValue,e)),e.majorTicks.push(ie.formatMajorTickNumber(e.maxValue,e))),["right"!==e.tickSide,"left"!==e.tickSide]}function h(e,t,i,r,o,n){e.beginPath(),e.moveTo(t+n,i),e.lineTo(t+r-n,i),e.quadraticCurveTo(t+r,i,t+r,i+n),e.lineTo(t+r,i+o-n),e.quadraticCurveTo(t+r,i+o,t+r-n,i+o),e.lineTo(t+n,i+o),e.quadraticCurveTo(t,i+o,t,i+o-n),e.lineTo(t,i+n),e.quadraticCurveTo(t,i,t+n,i),e.closePath()}function u(e,t){var i=t.valueDec,r=t.valueInt,o=0,n=void 0,a=void 0,l=void 0;if(e=parseFloat(e),l=e<0,e=Math.abs(e),i>0){for(a=e.toFixed(i).toString().split("."),n=r-a[0].length;o<n;++o)a[0]="0"+a[0];a=(l?"-":"")+a[0]+"."+a[1]}else{for(a=Math.round(e).toString(),n=r-a.length;o<n;++o)a="0"+a;a=(l?"-":"")+a}return a}function c(e,t){var i=void 0,r=!1;return i=0===t.majorTicksDec?Math.round(e).toString():e.toFixed(t.majorTicksDec),t.majorTicksInt>1?(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();m<g;m++){var W=t.highlights[m],O=u*Q(W.from)/w,B=u*Q((W.to-W.from)/w);e.beginPath(),e.fillStyle=W.color,r?(v&&e.rect(y-x,k-O,T,-B),b&&e.rect(y+S,k-O,T,-B)):(v&&e.rect(y+O,k-x,B,T),b&&e.rect(y+O,k+S,B,T)),e.fill(),e.closePath()}}}function V(e,t,i,r,o){e.beginPath(),e.moveTo(t,i),e.lineTo(r,o),e.stroke(),e.closePath(),e.save()}function j(e,t,i,r,o,n,a,l){var s=e.barDimensions,d=s.isVertical,h=s.length,u=s.barWidth,c=s.barOffset,f=s.barMargin,v=s.pixelRatio,b=s.width,m=s.X,g=s.Y,p=s.ticksLength,w=s.ticksPadding,y=(b-u)/2,T=void 0,k=void 0,x=0,S=l*b,W=y-w*b,O=y+u+S+w*b,B=p/(i-r),M=t instanceof Array?t:new Array(i).fill(t);for(e.lineWidth=a*v,e.save();x<i;x++)e.strokeStyle=M[x],d?(k=g+h-f-c-x*B,o&&(T=m+W,V(e,T,k,K(T-S),k)),n&&(T=m+O,V(e,T,k,K(T-S),k))):(T=m+f+c+x*B,o&&(k=g+W,V(e,T,k,T,K(k-S))),n&&(k=g+O,V(e,T,K(k),T,k-S)))}function P(e,t){var i=ie.prepareTicks(t),r=_(i,2),o=r[0],n=r[1],a=2,l=t.colorMajorTicks instanceof Array?t.colorMajorTicks:new Array(t.colorMajorTicks.length).fill(t.colorMajorTicks);if(j(e,t.colorMajorTicks,t.majorTicks.length,1,o,n,a,t.ticksWidth/100),t.strokeTicks){var s=e.barDimensions,d=s.isVertical,h=s.length,u=s.width,c=s.barWidth,f=s.barMargin,v=s.barOffset,b=s.X,m=s.Y,g=s.ticksLength,p=s.pixelRatio,w=s.ticksPadding,y=(u-c)/2+c+w*u,T=(u-c)/2-w*u,k=void 0,x=void 0,S=void 0,W=void 0;e.strokeStyle=l[0],a*=p,d?(x=m+h-f-v+a/2,W=x-g-a,o&&(S=k=K(b+T),N(e,k,x,S,W)),n&&(S=k=K(b+y),N(e,k,x,S,W))):(k=b+f+v-a/2,S=k+g+a,o&&(W=x=K(m+T),N(e,k,x,S,W)),n&&(W=x=K(m+y),N(e,k,x,S,W)))}}function N(e,t,i,r,o){e.beginPath(),e.moveTo(t,i),e.lineTo(r,o),e.stroke(),e.closePath()}function C(e,t){var i=ie.prepareTicks(t),r=_(i,2),o=r[0],n=r[1];j(e,t.colorMinorTicks,t.minorTicks*(t.majorTicks.length-1),0,o,n,1,t.ticksWidthMinor/100)}function E(e,t){var i=e.barDimensions,r=i.isVertical,o=i.length,n=i.width,a=i.barWidth,l=i.barMargin,s=i.barOffset,d=i.X,h=i.Y,u=i.ticksLength,c=i.ticksPadding,f=t.majorTicks.length,v="right"!==t.numberSide,b="left"!==t.numberSide,m=t.fontNumbersSize*n/200,g=0,p=(t.ticksWidth/100+2*c)*n,w=(n-a)/2-p,y=(n-a)/2+a+p,T=void 0,k=void 0,x=void 0,S=void 0,W=void 0,O=t.colorNumbers instanceof Array?t.colorNumbers:new Array(f).fill(t.colorNumbers);for(e.font=ie.font(t,"Numbers",n/200),e.lineWidth=0,e.textAlign="center";g<f;g++)e.fillStyle=O[g],W=t.majorTicks[g],S=g*u/(f-1),r?(k=h+o-l-s-S+m/3,v&&(e.textAlign="right",e.fillText(W,d+w,k)),b&&(e.textAlign="left",e.fillText(W,d+y,k))):(x=e.measureText(W).width,T=d+l+s+S,v&&e.fillText(W,T,h+w),b&&e.fillText(W,T,h+y+m))}function D(e,t){if(t.title){var i=e.barDimensions,r=i.isVertical,o=i.width,n=i.length,a=i.baseX,l=i.baseY,s=i.titleMargin,d=t.fontTitleSize*o/200,h=K(a+(r?o:n)/2),u=K(l+s/2-(r?d:d/2)-.025*(r?n:o));e.save(),e.textAlign="center",e.fillStyle=t.colorTitle,e.font=ie.font(t,"Title",o/200),e.lineWidth=0,e.fillText(t.title,h,u,r?o:n)}}function A(e,t){if(t.units){var i=e.barDimensions,r=i.isVertical,o=i.width,n=i.length,a=i.baseX,l=i.baseY,s=i.unitsMargin,d=t.fontUnitsSize*o/200,h=K(a+(r?o:n)/2),u=K(l+(r?n:o)+s/2-d/2);e.save(),e.textAlign="center",e.fillStyle=t.colorTitle,e.font=ie.font(t,"Units",o/200),e.lineWidth=0,e.fillText(t.units,h,u,r?o:n)}}function R(e,t){if(t.needle){var i=e.barDimensions,r=i.isVertical,o=i.width,n=i.length,a=i.barWidth,l=i.barOffset,s=i.barMargin,d=i.ticksLength,h=i.X,u=i.Y,c=i.ticksPadding,f="right"!==t.needleSide,v="left"!==t.needleSide,b=d*(t.value-t.minValue)/(t.maxValue-t.minValue),m=(t.ticksWidth/100+c)*o,g=a/2+m,p=g*(t.needleEnd/100),w=void 0,y=void 0,T=void 0,k=void 0,x="arrow"===t.needleType.toLowerCase()?X:L,S=(o-a)/2,W=g*(t.needleStart/100),O=S-m-W,B=S+a+m+W;e.save(),ie.drawNeedleShadow(e,t),r?(T=K(u+n-s-l-b),f&&(w=K(h+O),y=w+p,x(e,t,w,T,y,T,p)),v&&(w=K(h+B),y=w-p,x(e,t,w,T,y,T,p,!0))):(w=K(h+s+l+b),f&&(T=K(u+O),k=T+p,x(e,t,w,T,w,k,p)),v&&(T=K(u+B),k=T-p,x(e,t,w,T,w,k,p,!0))),e.restore()}}function I(e,t,i,r){return t.colorNeedleEnd?ie.linearGradient(e,r?t.colorNeedleEnd:t.colorNeedle,r?t.colorNeedle:t.colorNeedleEnd,i,!e.barDimensions.isVertical):t.colorNeedle}function L(e,t,i,r,o,n,a,l){e.lineWidth=t.needleWidth,e.strokeStyle=I(e,t,a,l),e.beginPath(),e.moveTo(i,r),e.lineTo(o,n),e.stroke(),e.closePath()}function X(e,t,i,r,o,n,a,l){var s=K(.4*a),d=a-s,h=i===o,u=t.needleWidth/2;e.fillStyle=I(e,t,a,l),e.beginPath(),h?(r>n&&(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<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}();Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(void 0===e||null===e)throw new TypeError("Cannot convert first argument to object");for(var i=Object(e),r=1;r<arguments.length;r++){var o=arguments[r];if(void 0!==o&&null!==o)for(var n=Object.keys(Object(o)),a=0,l=n.length;a<l;a++){var s=n[a],d=Object.getOwnPropertyDescriptor(o,s);void 0!==d&&d.enumerable&&(i[s]=o[s])}}return i}}),Array.prototype.indexOf||(Array.prototype.indexOf=function(e,t){var i;if(null===this)throw new TypeError('"this" is null or not defined');var r=Object(this),o=r.length>>>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<o;){if(i in r&&r[i]===e)return i;i++}return-1}),Array.prototype.fill||(Array.prototype.fill=function(e){if(null===this)throw new TypeError("this is null or not defined");for(var t=Object(this),i=t.length>>>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<s;)t[n]=e,n++;return t});var G=n("requestAnimationFrame")||function(e){return setTimeout(function(){return e((new Date).getTime())},1e3/60)},q={linear:function(e){return e},quad:function(e){return Math.pow(e,2)},dequad:function(e){return 1-q.quad(1-e)},quint:function(e){return Math.pow(e,5)},dequint:function(e){return 1-Math.pow(1-e,5)},cycle:function(e){return 1-Math.sin(Math.acos(e))},decycle:function(e){return Math.sin(Math.acos(1-e))},bounce:function(e){return 1-q.debounce(1-e)},debounce:function(e){for(var t=0,i=1;1;t+=i,i/=2)if(e>=(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<r;i++)this.process(t[i]);this.isObservable&&!this.mutationsObserved&&(new e.MutationObserver(this.observe.bind(this)).observe(document.body,{childList:!0,subtree:!0,attributes:!0,characterData:!0,attributeOldValue:!0,characterDataOldValue:!0}),this.mutationsObserved=!0)}},{key:"observe",value:function(e){for(var t=0,i=e.length;t<i;t++){var r=e[t];if("attributes"===r.type&&"data-type"===r.attributeName&&this.isValidNode(r.target)&&r.oldValue!==this.type)setTimeout(this.process.bind(this,r.target));else if(r.addedNodes&&r.addedNodes.length)for(var o=0,n=r.addedNodes.length;o<n;o++)setTimeout(this.process.bind(this,r.addedNodes[o]))}}},{key:"process",value:function(i){var r=this;if(!this.isValidNode(i))return null;var o=void 0,n=JSON.parse(JSON.stringify(this.options)),a=null;for(o in n)if(n.hasOwnProperty(o)){var l=t.toAttributeName(o),s=t.parse(i.getAttribute(l));null!==s&&void 0!==s&&(n[o]=s)}return n.renderTo=i,a=new this.Type(n),a.draw&&a.draw(),this.isObservable?(a.observer=new e.MutationObserver(function(e){e.forEach(function(e){if("attributes"===e.type){var o=e.attributeName.toLowerCase(),n=i.getAttribute(o).toLowerCase();if("data-type"===o&&n&&n!==r.type)a.observer.disconnect(),delete a.observer,a.destroy&&a.destroy();else if("data-"===o.substr(0,5)){var l=o.substr(5).split("-").map(function(e,t){return t?e.charAt(0).toUpperCase()+e.substr(1):e}).join(""),s={};s[l]=t.parse(i.getAttribute(e.attributeName)),a.update&&a.update(s)}}})}),a.observer.observe(i,{attributes:!0}),a):a}}],[{key:"parse",value:function(e){if("true"===e)return!0;if("false"===e)return!1;if("undefined"!==e){if("null"===e)return null;if(/^[-+#.\w\d\s]+(?:,[-+#.\w\d\s]*)+$/.test(e))return e.split(",");try{return JSON.parse(e)}catch(e){}return e}}},{key:"toDashed",value:function(e){for(var t=e.split(/(?=[A-Z])/),i=1,r=t.length,o=t[0].toLowerCase();i<r;i++)o+="-"+t[i].toLowerCase();return o}},{key:"toAttributeName",value:function(e){return"data-"+t.toDashed(e)}},{key:"domReady",value:function(t){return/comp|inter|loaded/.test((e.document||{}).readyState+"")?t():void(e.addEventListener?e.addEventListener("DOMContentLoaded",t,!1):e.attachEvent&&e.attachEvent("onload",t))}}]),t}(),J=function(){function t(e,i,r){o(this,t),t.collection.push(this),this.width=i||0,this.height=r||0,this.element=e,this.init()}return F(t,[{key:"init",value:function(){var e=t.pixelRatio;this.element.width=this.width*e,this.element.height=this.height*e,this.element.style.width=this.width+"px",this.element.style.height=this.height+"px",this.elementClone=this.element.cloneNode(!0),this.context=this.element.getContext("2d"),this.contextClone=this.elementClone.getContext("2d"),this.drawWidth=this.element.width,this.drawHeight=this.element.height,this.drawX=this.drawWidth/2,this.drawY=this.drawHeight/2,this.minSide=this.drawX<this.drawY?this.drawX:this.drawY,this.elementClone.initialized=!1,this.contextClone.translate(this.drawX,this.drawY),this.contextClone.save(),this.context.translate(this.drawX,this.drawY),this.context.save(),this.context.max=this.contextClone.max=this.minSide,this.context.maxRadius=this.contextClone.maxRadius=null}},{key:"destroy",value:function(){var e=t.collection.indexOf(this);~e&&t.collection.splice(e,1),this.context.clearRect(-this.drawX,-this.drawY,this.drawWidth,this.drawHeight),this.context.max=null,delete this.context.max,this.context.maxRadius=null,delete this.context.maxRadius,this.context=null,this.contextClone=null,this.elementClone=null,this.element=null,this.onRedraw=null}},{key:"commit",value:function(){var e=t.pixelRatio;return 1!==e&&(this.contextClone.scale(e,e),this.contextClone.save()),this}},{key:"redraw",value:function(){return this.init(),this.onRedraw&&this.onRedraw(),this}}],[{key:"redraw",value:function(){for(var e=0,i=t.collection.length;e<i;e++)t.collection[e].redraw()}},{key:"pixelRatio",get:function(){return e.devicePixelRatio||1}}]),t}();J.collection=[],e.matchMedia&&e.matchMedia("screen and (min-resolution: 2dppx)").addListener(J.redraw);var Z={renderTo:null,width:0,height:0,minValue:0,maxValue:100,value:0,units:!1,majorTicks:[0,20,40,60,80,100],minorTicks:10,strokeTicks:!0,animatedValue:!1,animateOnInit:!1,title:!1,borders:!0,valueInt:3,valueDec:2,majorTicksInt:1,majorTicksDec:0,animation:!0,animationDuration:500,animationRule:"cycle",colorPlate:"#fff",colorPlateEnd:"",colorMajorTicks:"#444",colorMinorTicks:"#666",colorTitle:"#888",colorUnits:"#888",colorNumbers:"#444",colorNeedle:"rgba(240,128,128,1)",colorNeedleEnd:"rgba(255,160,122,.9)",colorValueText:"#444",colorValueTextShadow:"rgba(0,0,0,0.3)",colorBorderShadow:"rgba(0,0,0,0.5)",colorBorderOuter:"#ddd",colorBorderOuterEnd:"#aaa",colorBorderMiddle:"#eee",colorBorderMiddleEnd:"#f0f0f0",colorBorderInner:"#fafafa",colorBorderInnerEnd:"#ccc",colorValueBoxRect:"#888",colorValueBoxRectEnd:"#666",colorValueBoxBackground:"#babab2",colorValueBoxShadow:"rgba(0,0,0,1)",colorNeedleShadowUp:"rgba(2,255,255,0.2)",colorNeedleShadowDown:"rgba(188,143,143,0.45)",fontNumbers:"Arial",fontTitle:"Arial",fontUnits:"Arial",fontValue:"Arial",fontNumbersSize:20,fontTitleSize:24,fontUnitsSize:22,fontValueSize:40,fontNumbersStyle:"normal",fontTitleStyle:"normal",fontUnitsStyle:"normal",fontValueStyle:"normal",fontNumbersWeight:"normal",fontTitleWeight:"normal",fontUnitsWeight:"normal",fontValueWeight:"normal",needle:!0,needleShadow:!0,needleType:"arrow",needleStart:5,needleEnd:85,needleWidth:4,borderOuterWidth:3,borderMiddleWidth:3,borderInnerWidth:3,borderShadowWidth:3,valueBox:!0,valueBoxStroke:5,valueBoxWidth:0,valueText:"",valueTextShadow:!0,valueBoxBorderRadius:2.5,highlights:[{from:20,to:60,color:"#eee"},{from:60,to:80,color:"#ccc"},{from:80,to:100,color:"#999"}],highlightsWidth:15};l.prototype=Object.create(Array.prototype),l.prototype.constructor=l,l.prototype.get=function(e){if("string"==typeof e)for(var t=0,i=this.length;t<i;t++){var r=this[t].options.renderTo.tagName?this[t].options.renderTo:document.getElementById(this[t].options.renderTo||"");if(r.getAttribute("id")===e)return this[t]}else if("number"==typeof e)return this[e];return null};var $="2.0.9",K=Math.round,Q=Math.abs,ee=new l;ee.version=$;var te=function(){function t(i){o(this,t);var r=this.constructor.name;if("BaseGauge"===r)throw new TypeError("Attempt to instantiate abstract class!");if(ee.push(this),this.version=$,this.type=e[r],this.initialized=!1,i.minValue=parseFloat(i.minValue),i.maxValue=parseFloat(i.maxValue),i.value=parseFloat(i.value)||0,i.borders||(i.borderInnerWidth=i.borderMiddleWidth=i.borderOuterWidth=0),!i.renderTo)throw TypeError("Canvas element was not specified when creating the Gauge object!");var n=i.renderTo.tagName?i.renderTo:document.getElementById(i.renderTo);if(!(n instanceof HTMLCanvasElement))throw TypeError("Given gauge canvas element is invalid!");i.width=parseFloat(i.width)||0,i.height=parseFloat(i.height)||0,i.width&&i.height||(i.width||(i.width=n.parentNode?n.parentNode.offsetWidth:n.offsetWidth),i.height||(i.height=n.parentNode?n.parentNode.offsetHeight:n.offsetHeight)),this.options=i||{},this.options.animateOnInit&&(this._value=this.options.value,this.options.value=this.options.minValue),this.canvas=new J(n,i.width,i.height),this.canvas.onRedraw=this.draw.bind(this),this.animation=new U(i.animationRule,i.animationDuration)}return F(t,[{key:"update",value:function(e){return Object.assign(this.options,e||{}),this.canvas.width=this.options.width,this.canvas.height=this.options.height,this.animation.rule=this.options.animationRule,this.animation.duration=this.options.animationDuration,this.canvas.redraw(),this}},{key:"destroy",value:function(){var e=ee.indexOf(this);~e&&ee.splice(e,1),this.canvas.destroy(),this.canvas=null,this.animation.destroy(),this.animation=null}},{key:"draw",value:function(){this.options.animateOnInit&&!this.initialized&&(this.value=this._value,this.initialized=!0)}},{key:"value",set:function(e){var t=this;e=parseFloat(e),!isNaN(e)&&isFinite(e)||(e=this.options.minValue);var i=this.options.value;e!==this.options.value&&(this.options.animation?(this._value=e,this.animation.animate(function(r){t.options.value=i+(e-i)*r,t.draw()},function(){t.options.value=e,delete t._value,t.draw()})):(this.options.value=e,this.draw()))},get:function(){return"undefined"==typeof this._value?this.options.value:this._value}}],[{key:"initialize",value:function(e,t){new H(t,"canvas",e)}},{key:"version",get:function(){return $}}]),t}();"undefined"!=typeof e&&(e.BaseGauge=te,(e.document||e).gauges=ee);var ie={roundRect:h,padValue:u,formatMajorTickNumber:c,radians:f,radialPoint:v,linearGradient:b,drawNeedleShadow:g,drawValueBox:w,verifyError:s,prepareTicks:d,drawShadow:m,font:p},re=Object.assign({},Z,{borderRadius:0,barBeginCircle:30,barWidth:20,barStrokeWidth:0,barProgress:!0,colorBarStroke:"#222",colorBar:"#ccc",colorBarEnd:"",colorBarProgress:"#888",colorBarProgressEnd:"",needleWidth:6,tickSide:"both",needleSide:"both",numberSide:"both",ticksWidth:10,ticksWidthMinor:5,ticksPadding:5,barLength:85,fontTitleSize:26,highlightsWidth:10}),oe=function(e){function n(e){return o(this,n),e=Object.assign({},re,e||{}),e.barStrokeWidth>=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);