ng-canvas-gauges
Version:
Angular 6+ component wrapper for the canvas-gauges lib written by @Mikhus
2 lines • 3.97 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("rx-dom-html"),require("@angular/core"),require("canvas-gauges")):"function"==typeof define&&define.amd?define("ng-canvas-gauges",["exports","rx-dom-html","@angular/core","canvas-gauges"],t):t(e["ng-canvas-gauges"]={},e.Rx,e.ng.core,e.CanvasGauges)}(this,function(e,t,r,p){"use strict";var i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function o(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var c=function(e){return e.replace(/(\-\w)/g,function(e){return e[1].toUpperCase()})},n=function(){function e(e,t){this.el=e,this.zone=t,this.isInited=!1}return Object.defineProperty(e.prototype,"options",{get:function(){var e,t,n={};n.renderTo=this.canvas.nativeElement;try{for(var r=function s(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}(this.el.nativeElement.attributes),i=r.next();!i.done;i=r.next()){var o=i.value;n[a=c(o.name)]=p.DomObserver.parse(o.value)}}catch(u){e={error:u}}finally{try{i&&!i.done&&(t=r["return"])&&t.call(r)}finally{if(e)throw e.error}}for(var a in this.preInitOptions)n[a]=this.preInitOptions[a];return this.isInited&&(this.preInitOptions=null),n},set:function(e){this.isInited?this.update(e):this.preInitOptions=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{set:function(e){var t=this;this.isInited?this.zone.runOutsideAngular(function(){t.gauge.value=e}):this.preInitValue=e},enumerable:!0,configurable:!0}),e.prototype.update=function(e){if(e)for(var t in e){var n=e[t].toString();if("value"===t)this.value=p.DomObserver.parse(n);else{var r=t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();this.el.nativeElement.setAttribute(r,n)}}},e.prototype.ngAfterViewInit=function(){this.initGauge(),this.listenForDOMEvents(),this.isInited=!0},e.prototype.listenForDOMEvents=function(){var n=this;this.domListener=t.DOM.fromMutationObserver(this.el.nativeElement,{attributes:!0}).subscribe(function(e){var t={};e.forEach(function(e){"attributes"===e.type&&(t[c(e.attributeName)]=p.DomObserver.parse(n.el.nativeElement.getAttribute(e.attributeName)))}),n.basicUpdate(t)})},e.prototype.stopListeningForDOMEvents=function(){this.domListener&&(this.domListener.disconnect(),this.domListener=null)},e.prototype.initGauge=function(){var e=this.options;this.preInitValue&&(e.value=this.preInitValue),e.hasOwnProperty("renderTo")&&e.renderTo||(e.renderTo=this.canvas.nativeElement),this.basicUpdate(e)},e.prototype.basicUpdate=function(e){"number"==typeof e.value&&(this.value=e.value,delete e.value),Object.keys(e).length&&this.gauge.update(e)},e.propDecorators={canvas:[{type:r.ViewChild,args:["gauge"]}],options:[{type:r.Input}],value:[{type:r.Input}]},e}(),a=function(n){function e(e,t){return n.call(this,e,t)||this}return o(e,n),e.prototype.ngOnInit=function(){this.gauge=new p.LinearGauge(this.options).draw()},e.decorators=[{type:r.Component,args:[{selector:"linear-gauge",template:"<canvas #gauge></canvas>"}]}],e.ctorParameters=function(){return[{type:r.ElementRef},{type:r.NgZone}]},e}(n),s=function(n){function e(e,t){return n.call(this,e,t)||this}return o(e,n),e.prototype.ngOnInit=function(){this.gauge=new p.RadialGauge(this.options).draw()},e.decorators=[{type:r.Component,args:[{selector:"radial-gauge",template:"<canvas #gauge></canvas>"}]}],e.ctorParameters=function(){return[{type:r.ElementRef},{type:r.NgZone}]},e}(n),u=function(){function e(){}return e.decorators=[{type:r.NgModule,args:[{declarations:[a,s],imports:[],exports:[a,s]}]}],e}();e.GaugesModule=u,e.LinearGauge=a,e.RadialGauge=s,e.ɵa=n,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=ng-canvas-gauges.umd.min.js.map