1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('chart.js')) :
|
3 | typeof define === 'function' && define.amd ? define('primeng/chart', ['exports', '@angular/core', '@angular/common', 'chart.js'], factory) :
|
4 | (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.chart = {}), global.ng.core, global.ng.common, global.Chart));
|
5 | }(this, (function (exports, core, common, Chart) { 'use strict';
|
6 |
|
7 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
8 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
9 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
10 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
11 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
12 | };
|
13 | var UIChart = (function () {
|
14 | function UIChart(el) {
|
15 | this.el = el;
|
16 | this.options = {};
|
17 | this.plugins = [];
|
18 | this.responsive = true;
|
19 | this.onDataSelect = new core.EventEmitter();
|
20 | }
|
21 | Object.defineProperty(UIChart.prototype, "data", {
|
22 | get: function () {
|
23 | return this._data;
|
24 | },
|
25 | set: function (val) {
|
26 | this._data = val;
|
27 | this.reinit();
|
28 | },
|
29 | enumerable: true,
|
30 | configurable: true
|
31 | });
|
32 | UIChart.prototype.ngAfterViewInit = function () {
|
33 | this.initChart();
|
34 | this.initialized = true;
|
35 | };
|
36 | UIChart.prototype.onCanvasClick = function (event) {
|
37 | if (this.chart) {
|
38 | var element = this.chart.getElementAtEvent(event);
|
39 | var dataset = this.chart.getDatasetAtEvent(event);
|
40 | if (element && element[0] && dataset) {
|
41 | this.onDataSelect.emit({ originalEvent: event, element: element[0], dataset: dataset });
|
42 | }
|
43 | }
|
44 | };
|
45 | UIChart.prototype.initChart = function () {
|
46 | var opts = this.options || {};
|
47 | opts.responsive = this.responsive;
|
48 |
|
49 | if (opts.responsive && (this.height || this.width)) {
|
50 | opts.maintainAspectRatio = false;
|
51 | }
|
52 | this.chart = new Chart(this.el.nativeElement.children[0].children[0], {
|
53 | type: this.type,
|
54 | data: this.data,
|
55 | options: this.options,
|
56 | plugins: this.plugins
|
57 | });
|
58 | };
|
59 | UIChart.prototype.getCanvas = function () {
|
60 | return this.el.nativeElement.children[0].children[0];
|
61 | };
|
62 | UIChart.prototype.getBase64Image = function () {
|
63 | return this.chart.toBase64Image();
|
64 | };
|
65 | UIChart.prototype.generateLegend = function () {
|
66 | if (this.chart) {
|
67 | return this.chart.generateLegend();
|
68 | }
|
69 | };
|
70 | UIChart.prototype.refresh = function () {
|
71 | if (this.chart) {
|
72 | this.chart.update();
|
73 | }
|
74 | };
|
75 | UIChart.prototype.reinit = function () {
|
76 | if (this.chart) {
|
77 | this.chart.destroy();
|
78 | this.initChart();
|
79 | }
|
80 | };
|
81 | UIChart.prototype.ngOnDestroy = function () {
|
82 | if (this.chart) {
|
83 | this.chart.destroy();
|
84 | this.initialized = false;
|
85 | this.chart = null;
|
86 | }
|
87 | };
|
88 | UIChart.ctorParameters = function () { return [
|
89 | { type: core.ElementRef }
|
90 | ]; };
|
91 | __decorate([
|
92 | core.Input()
|
93 | ], UIChart.prototype, "type", void 0);
|
94 | __decorate([
|
95 | core.Input()
|
96 | ], UIChart.prototype, "options", void 0);
|
97 | __decorate([
|
98 | core.Input()
|
99 | ], UIChart.prototype, "plugins", void 0);
|
100 | __decorate([
|
101 | core.Input()
|
102 | ], UIChart.prototype, "width", void 0);
|
103 | __decorate([
|
104 | core.Input()
|
105 | ], UIChart.prototype, "height", void 0);
|
106 | __decorate([
|
107 | core.Input()
|
108 | ], UIChart.prototype, "responsive", void 0);
|
109 | __decorate([
|
110 | core.Output()
|
111 | ], UIChart.prototype, "onDataSelect", void 0);
|
112 | __decorate([
|
113 | core.Input()
|
114 | ], UIChart.prototype, "data", null);
|
115 | UIChart = __decorate([
|
116 | core.Component({
|
117 | selector: 'p-chart',
|
118 | template: "\n <div style=\"position:relative\" [style.width]=\"responsive && !width ? null : width\" [style.height]=\"responsive && !height ? null : height\">\n <canvas [attr.width]=\"responsive && !width ? null : width\" [attr.height]=\"responsive && !height ? null : height\" (click)=\"onCanvasClick($event)\"></canvas>\n </div>\n ",
|
119 | changeDetection: core.ChangeDetectionStrategy.Default
|
120 | })
|
121 | ], UIChart);
|
122 | return UIChart;
|
123 | }());
|
124 | var ChartModule = (function () {
|
125 | function ChartModule() {
|
126 | }
|
127 | ChartModule = __decorate([
|
128 | core.NgModule({
|
129 | imports: [common.CommonModule],
|
130 | exports: [UIChart],
|
131 | declarations: [UIChart]
|
132 | })
|
133 | ], ChartModule);
|
134 | return ChartModule;
|
135 | }());
|
136 |
|
137 | exports.ChartModule = ChartModule;
|
138 | exports.UIChart = UIChart;
|
139 |
|
140 | Object.defineProperty(exports, '__esModule', { value: true });
|
141 |
|
142 | })));
|
143 |
|