| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- 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;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- var __metadata = (this && this.__metadata) || function (k, v) {
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var core_1 = require("@angular/core");
- var common_1 = require("@angular/common");
- var Chart = require("chart.js");
- var UIChart = /** @class */ (function () {
- function UIChart(el) {
- this.el = el;
- this.options = {};
- this.plugins = [];
- this.responsive = true;
- this.onDataSelect = new core_1.EventEmitter();
- }
- Object.defineProperty(UIChart.prototype, "data", {
- get: function () {
- return this._data;
- },
- set: function (val) {
- this._data = val;
- this.reinit();
- },
- enumerable: true,
- configurable: true
- });
- UIChart.prototype.ngAfterViewInit = function () {
- this.initChart();
- this.initialized = true;
- };
- UIChart.prototype.onCanvasClick = function (event) {
- if (this.chart) {
- var element = this.chart.getElementAtEvent(event);
- var dataset = this.chart.getDatasetAtEvent(event);
- if (element && element[0] && dataset) {
- this.onDataSelect.emit({ originalEvent: event, element: element[0], dataset: dataset });
- }
- }
- };
- UIChart.prototype.initChart = function () {
- var opts = this.options || {};
- opts.responsive = this.responsive;
- // allows chart to resize in responsive mode
- if (opts.responsive && (this.height || this.width)) {
- opts.maintainAspectRatio = false;
- }
- this.chart = new Chart(this.el.nativeElement.children[0].children[0], {
- type: this.type,
- data: this.data,
- options: this.options,
- plugins: this.plugins
- });
- };
- UIChart.prototype.getCanvas = function () {
- return this.el.nativeElement.children[0].children[0];
- };
- UIChart.prototype.getBase64Image = function () {
- return this.chart.toBase64Image();
- };
- UIChart.prototype.generateLegend = function () {
- if (this.chart) {
- return this.chart.generateLegend();
- }
- };
- UIChart.prototype.refresh = function () {
- if (this.chart) {
- this.chart.update();
- }
- };
- UIChart.prototype.reinit = function () {
- if (this.chart) {
- this.chart.destroy();
- this.initChart();
- }
- };
- UIChart.prototype.ngOnDestroy = function () {
- if (this.chart) {
- this.chart.destroy();
- this.initialized = false;
- this.chart = null;
- }
- };
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], UIChart.prototype, "type", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], UIChart.prototype, "options", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Array)
- ], UIChart.prototype, "plugins", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], UIChart.prototype, "width", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], UIChart.prototype, "height", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], UIChart.prototype, "responsive", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], UIChart.prototype, "onDataSelect", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object),
- __metadata("design:paramtypes", [Object])
- ], UIChart.prototype, "data", null);
- UIChart = __decorate([
- core_1.Component({
- selector: 'p-chart',
- 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 "
- }),
- __metadata("design:paramtypes", [core_1.ElementRef])
- ], UIChart);
- return UIChart;
- }());
- exports.UIChart = UIChart;
- var ChartModule = /** @class */ (function () {
- function ChartModule() {
- }
- ChartModule = __decorate([
- core_1.NgModule({
- imports: [common_1.CommonModule],
- exports: [UIChart],
- declarations: [UIChart]
- })
- ], ChartModule);
- return ChartModule;
- }());
- exports.ChartModule = ChartModule;
- //# sourceMappingURL=chart.js.map
|