ng4-charts
Version:
Reactive, responsive, beautiful charts for Angular2 based on Chart.js
1 lines • 5.92 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@angular/core")):"function"==typeof define&&define.amd?define(["@angular/core"],e):"object"==typeof exports?exports["ng4-charts.umd.min"]=e(require("@angular/core")):t["ng4-charts.umd.min"]=e(t["@angular/core"])}("undefined"!=typeof self?self:this,function(t){return function(t){function e(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,e),n.l=!0,n.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,o){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="/",e(e.s=0)}([function(t,e,r){"use strict";!function(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}(r(1))},function(t,e,r){"use strict";function o(t,e){return"rgba("+t.concat(e).join(",")+")"}function n(t,e){return Math.floor(Math.random()*(e-t+1))+t}function a(t){return{backgroundColor:o(t,.4),borderColor:o(t,1),pointBackgroundColor:o(t,1),pointBorderColor:"#fff",pointHoverBackgroundColor:"#fff",pointHoverBorderColor:o(t,.8)}}function i(t){return{backgroundColor:o(t,.6),borderColor:o(t,1),hoverBackgroundColor:o(t,.8),hoverBorderColor:o(t,1)}}function s(t){return{backgroundColor:t.map(function(t){return o(t,.6)}),borderColor:t.map(function(){return"#fff"}),pointBackgroundColor:t.map(function(t){return o(t,1)}),pointBorderColor:t.map(function(){return"#fff"}),pointHoverBackgroundColor:t.map(function(t){return o(t,1)}),pointHoverBorderColor:t.map(function(t){return o(t,1)})}}function c(t){return{backgroundColor:t.map(function(t){return o(t,.6)}),borderColor:t.map(function(t){return o(t,1)}),hoverBackgroundColor:t.map(function(t){return o(t,.8)}),hoverBorderColor:t.map(function(t){return o(t,1)})}}function u(){return[n(0,255),n(0,255),n(0,255)]}function p(t){return y.defaultColors[t]||u()}function l(t){for(var e=new Array(t),r=0;r<t;r++)e[r]=y.defaultColors[r]||u();return e}function h(t,e,r){return"pie"===t||"doughnut"===t?s(l(r)):"polarArea"===t?c(l(r)):"line"===t||"radar"===t?a(p(e)):"bar"===t||"horizontalBar"===t?i(p(e)):p(e)}var d=this&&this.__decorate||function(t,e,r,o){var n,a=arguments.length,i=a<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(t,e,r,o);else for(var s=t.length-1;s>=0;s--)(n=t[s])&&(i=(a<3?n(i):a>3?n(e,r,i):n(e,r))||i);return a>3&&i&&Object.defineProperty(e,r,i),i},f=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},g=r(2),y=function(){function t(t){this.labels=[],this.options={},this.chartClick=new g.EventEmitter,this.chartHover=new g.EventEmitter,this.initFlag=!1,this.element=t}return t.prototype.ngOnInit=function(){this.ctx=this.element.nativeElement.getContext("2d"),this.cvs=this.element.nativeElement,this.initFlag=!0,(this.data||this.datasets)&&this.refresh()},t.prototype.ngOnChanges=function(t){if(this.initFlag){var e=!1;(t.hasOwnProperty("data")||t.hasOwnProperty("datasets"))&&(this.chart.data.datasets=this.getDatasets()),t.hasOwnProperty("labels")&&(this.chart.data.labels=this.labels),t.hasOwnProperty("options")&&(this.chart.options=this.options,e=!0),e?this.refresh():this.chart.update()}},t.prototype.ngOnDestroy=function(){this.chart&&(this.chart.destroy(),this.chart=void 0)},t.prototype.getChartBuilder=function(t){var e=this,r=this.getDatasets(),o=Object.assign({},this.options);!1===this.legend&&(o.legend={display:!1}),o.hover=o.hover||{},o.hover.onHover||(o.hover.onHover=function(t){t&&!t.length||e.chartHover.emit({active:t})}),o.onClick||(o.onClick=function(t,r){e.chartClick.emit({event:t,active:r})});var n={type:this.chartType,data:{labels:this.labels,datasets:r},options:o};if("undefined"==typeof Chart)throw new Error("ng2-charts configuration issue: Embedding Chart.js lib is mandatory");return new Chart(t,n)},t.prototype.getDatasets=function(){var t=this,e=void 0;if((!this.datasets||!this.datasets.length&&this.data&&this.data.length)&&(e=Array.isArray(this.data[0])?this.data.map(function(e,r){return{data:e,label:t.labels[r]||"Label "+r}}):[{data:this.data,label:"Label 0"}]),(this.datasets&&this.datasets.length||e&&e.length)&&(e=(this.datasets||e).map(function(e,r){var o=Object.assign({},e);return t.colors&&t.colors.length?Object.assign(o,t.colors[r]):Object.assign(o,h(t.chartType,r,o.data.length)),o})),!e)throw new Error("ng-charts configuration error,\n data or datasets field are required to render char "+this.chartType);return e},t.prototype.refresh=function(){this.ngOnDestroy(),this.chart=this.getChartBuilder(this.ctx)},t}();y.defaultColors=[[255,99,132],[54,162,235],[255,206,86],[231,233,237],[75,192,192],[151,187,205],[220,220,220],[247,70,74],[70,191,189],[253,180,92],[148,159,177],[77,83,96]],d([g.Input(),f("design:type",Array)],y.prototype,"data",void 0),d([g.Input(),f("design:type",Array)],y.prototype,"datasets",void 0),d([g.Input(),f("design:type",Array)],y.prototype,"labels",void 0),d([g.Input(),f("design:type",Object)],y.prototype,"options",void 0),d([g.Input(),f("design:type",String)],y.prototype,"chartType",void 0),d([g.Input(),f("design:type",Array)],y.prototype,"colors",void 0),d([g.Input(),f("design:type",Boolean)],y.prototype,"legend",void 0),d([g.Output(),f("design:type",g.EventEmitter)],y.prototype,"chartClick",void 0),d([g.Output(),f("design:type",g.EventEmitter)],y.prototype,"chartHover",void 0),y=d([g.Directive({selector:"canvas[baseChart]",exportAs:"base-chart"}),f("design:paramtypes",[g.ElementRef])],y),e.BaseChartDirective=y;var v=function(){function t(){}return t}();v=d([g.NgModule({declarations:[y],exports:[y],imports:[]})],v),e.ChartsModule=v},function(e,r){e.exports=t}])});