UNPKG

@lxlib/chart

Version:

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.

345 lines (339 loc) 9.77 kB
import { __decorate, __metadata, __spread } from 'tslib'; import { Component, ChangeDetectionStrategy, ViewEncapsulation, NgZone, ViewChild, Input, NgModule } from '@angular/core'; import { Chart } from '@antv/g2'; import { InputNumber, InputBoolean, LxlibUtilModule } from '@lxlib/util'; import { fromEvent } from 'rxjs'; import { filter, debounceTime } from 'rxjs/operators'; import { CommonModule } from '@angular/common'; import { NzOutletModule } from 'ng-zorro-antd/core/outlet'; /** * @fileoverview added by tsickle * Generated from: bar.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var TITLE_HEIGHT = 41; /** * @record */ function G2BarData() { } if (false) { /** @type {?} */ G2BarData.prototype.x; /** @type {?} */ G2BarData.prototype.y; /** @type {?|undefined} */ G2BarData.prototype.color; /* Skipping unhandled member: [key: string]: any;*/ } var G2BarComponent = /** @class */ (function () { // #endregion function G2BarComponent(ngZone) { this.ngZone = ngZone; // #region fields this.delay = 0; this.color = 'rgba(24, 144, 255, 0.85)'; this.height = 0; this.padding = 'auto'; this.data = []; this.autoLabel = true; this.interaction = 'none'; } /** * @private * @return {?} */ G2BarComponent.prototype.getHeight = /** * @private * @return {?} */ function () { return this.title ? this.height - TITLE_HEIGHT : this.height; }; /** * @private * @return {?} */ G2BarComponent.prototype.install = /** * @private * @return {?} */ function () { var _this = this; var _a = this, node = _a.node, padding = _a.padding, interaction = _a.interaction; /** @type {?} */ var container = (/** @type {?} */ (node.nativeElement)); /** @type {?} */ var chart = (this.chart = new Chart({ container: container, autoFit: true, height: this.getHeight(), padding: padding, })); this.updatelabel(); chart.axis('y', { title: null, line: null, tickLine: null, }); chart.scale({ x: { type: 'cat', }, y: { min: 0, }, }); chart.tooltip({ showTitle: false, }); if (interaction !== 'none') { chart.interaction(interaction); } chart.legend(false); chart .interval() .position('x*y') .color('x*y', (/** * @param {?} x * @param {?} y * @return {?} */ function (x, y) { /** @type {?} */ var colorItem = _this.data.find((/** * @param {?} w * @return {?} */ function (w) { return w.x === x && w.y === y; })); return colorItem && colorItem.color ? colorItem.color : _this.color; })) .tooltip('x*y', (/** * @param {?} x * @param {?} y * @return {?} */ function (x, y) { return ({ name: x, value: y }); })); this.attachChart(); }; /** * @private * @return {?} */ G2BarComponent.prototype.attachChart = /** * @private * @return {?} */ function () { var _a = this, chart = _a.chart, padding = _a.padding, data = _a.data; if (!chart || !data || data.length <= 0) return; this.installResizeEvent(); /** @type {?} */ var height = this.getHeight(); if (chart.height !== height) { chart.height = height; } chart.padding = padding; chart.data(data); chart.render(); }; /** * @private * @return {?} */ G2BarComponent.prototype.updatelabel = /** * @private * @return {?} */ function () { var _a = this, node = _a.node, data = _a.data, chart = _a.chart; /** @type {?} */ var canvasWidth = node.nativeElement.clientWidth; /** @type {?} */ var minWidth = data.length * 30; chart.axis('x', canvasWidth > minWidth).render(); }; /** * @private * @return {?} */ G2BarComponent.prototype.installResizeEvent = /** * @private * @return {?} */ function () { var _this = this; if (!this.autoLabel || this.resize$) return; this.resize$ = fromEvent(window, 'resize') .pipe(filter((/** * @return {?} */ function () { return !!_this.chart; })), debounceTime(200)) .subscribe((/** * @return {?} */ function () { return _this.ngZone.runOutsideAngular((/** * @return {?} */ function () { return _this.updatelabel(); })); })); }; /** * @return {?} */ G2BarComponent.prototype.ngOnInit = /** * @return {?} */ function () { var _this = this; this.ngZone.runOutsideAngular((/** * @return {?} */ function () { return setTimeout((/** * @return {?} */ function () { return _this.install(); }), _this.delay); })); }; /** * @return {?} */ G2BarComponent.prototype.ngOnChanges = /** * @return {?} */ function () { var _this = this; this.ngZone.runOutsideAngular((/** * @return {?} */ function () { return _this.attachChart(); })); }; /** * @return {?} */ G2BarComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { var _this = this; if (this.resize$) { this.resize$.unsubscribe(); } if (this.chart) { this.ngZone.runOutsideAngular((/** * @return {?} */ function () { return _this.chart.destroy(); })); } }; G2BarComponent.decorators = [ { type: Component, args: [{ selector: 'g2-bar', exportAs: 'g2Bar', template: "<ng-container *nzStringTemplateOutlet=\"title\">\n <h4 style=\"margin-bottom:20px\">{{title}}</h4>\n</ng-container>\n<div #container></div>\n", host: { '[style.height.px]': 'height', }, preserveWhitespaces: false, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }] } ]; /** @nocollapse */ G2BarComponent.ctorParameters = function () { return [ { type: NgZone } ]; }; G2BarComponent.propDecorators = { node: [{ type: ViewChild, args: ['container', { static: true },] }], delay: [{ type: Input }], title: [{ type: Input }], color: [{ type: Input }], height: [{ type: Input }], padding: [{ type: Input }], data: [{ type: Input }], autoLabel: [{ type: Input }], interaction: [{ type: Input }] }; __decorate([ InputNumber(), __metadata("design:type", Object) ], G2BarComponent.prototype, "delay", void 0); __decorate([ InputNumber(), __metadata("design:type", Object) ], G2BarComponent.prototype, "height", void 0); __decorate([ InputBoolean(), __metadata("design:type", Object) ], G2BarComponent.prototype, "autoLabel", void 0); return G2BarComponent; }()); if (false) { /** * @type {?} * @private */ G2BarComponent.prototype.resize$; /** * @type {?} * @private */ G2BarComponent.prototype.chart; /** * @type {?} * @private */ G2BarComponent.prototype.node; /** @type {?} */ G2BarComponent.prototype.delay; /** @type {?} */ G2BarComponent.prototype.title; /** @type {?} */ G2BarComponent.prototype.color; /** @type {?} */ G2BarComponent.prototype.height; /** @type {?} */ G2BarComponent.prototype.padding; /** @type {?} */ G2BarComponent.prototype.data; /** @type {?} */ G2BarComponent.prototype.autoLabel; /** @type {?} */ G2BarComponent.prototype.interaction; /** * @type {?} * @private */ G2BarComponent.prototype.ngZone; } /** * @fileoverview added by tsickle * Generated from: bar.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var COMPONENTS = [G2BarComponent]; var G2BarModule = /** @class */ (function () { function G2BarModule() { } G2BarModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, LxlibUtilModule, NzOutletModule], declarations: __spread(COMPONENTS), exports: __spread(COMPONENTS), },] } ]; return G2BarModule; }()); /** * @fileoverview added by tsickle * Generated from: public_api.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * Generated from: bar.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { G2BarComponent, G2BarModule }; //# sourceMappingURL=bar.js.map