UNPKG

@lxlib/chart

Version:

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

344 lines (338 loc) 10 kB
import { __decorate, __metadata } from 'tslib'; import { Component, ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, NgZone, ViewChild, Input, NgModule } from '@angular/core'; import { Chart } from '@antv/g2'; import { InputNumber, InputBoolean, LxlibUtilModule } from '@lxlib/util'; import { CommonModule } from '@angular/common'; import { NzOutletModule } from 'ng-zorro-antd/core/outlet'; import { NzGridModule } from 'ng-zorro-antd/grid'; /** * @fileoverview added by tsickle * Generated from: radar.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function G2RadarData() { } if (false) { /** @type {?} */ G2RadarData.prototype.name; /** @type {?} */ G2RadarData.prototype.label; /** @type {?} */ G2RadarData.prototype.value; /* Skipping unhandled member: [key: string]: any;*/ } class G2RadarComponent { // #endregion /** * @param {?} cdr * @param {?} ngZone */ constructor(cdr, ngZone) { this.cdr = cdr; this.ngZone = ngZone; this.legendData = []; // #region fields this.delay = 0; this.height = 0; this.padding = [44, 30, 16, 30]; this.hasLegend = true; this.tickCount = 4; this.data = []; this.colors = ['#1890FF', '#FACC14', '#2FC25B', '#8543E0', '#F04864', '#13C2C2', '#fa8c16', '#a0d911']; } /** * @private * @return {?} */ getHeight() { return this.height - (this.hasLegend ? 80 : 22); } /** * @private * @return {?} */ install() { const { node, padding } = this; /** @type {?} */ const chart = (this.chart = new Chart({ container: node.nativeElement, autoFit: true, height: this.getHeight(), padding, })); chart.coordinate('polar'); chart.legend(false); chart.axis('label', { line: null, label: { offset: 8, style: { fill: 'rgba(0, 0, 0, .65)', }, }, grid: { line: { style: { stroke: '#e9e9e9', lineWidth: 1, lineDash: [0, 0], }, }, }, }); chart.axis('value', { grid: { line: { type: 'polygon', style: { stroke: '#e9e9e9', lineWidth: 1, lineDash: [0, 0], }, }, }, label: { style: { fill: 'rgba(0, 0, 0, .65)', }, }, }); chart.filter('name', (/** * @param {?} name * @return {?} */ (name) => { /** @type {?} */ const legendItem = this.legendData.find((/** * @param {?} w * @return {?} */ w => w.name === name)); return legendItem ? legendItem.checked !== false : true; })); chart.line().position('label*value'); chart.point().position('label*value').shape('circle').size(3); chart.render(); this.attachChart(); } /** * @private * @return {?} */ attachChart() { const { chart, padding, data, colors, tickCount } = this; if (!chart || !data || data.length <= 0) return; chart.height = this.getHeight(); chart.padding = padding; chart.scale({ value: { min: 0, tickCount, }, }); chart.geometries.forEach((/** * @param {?} g * @return {?} */ g => g.color('name', colors))); chart.changeData(data); this.ngZone.run((/** * @return {?} */ () => this.genLegend())); } /** * @private * @return {?} */ genLegend() { const { hasLegend, cdr, chart } = this; if (!hasLegend) return; this.legendData = chart.geometries[0].dataArray.map((/** * @param {?} item * @return {?} */ item => { /** @type {?} */ const origin = item[0]._origin; /** @type {?} */ const result = { name: origin.name, color: item[0].color, checked: true, value: item.reduce((/** * @param {?} p * @param {?} n * @return {?} */ (p, n) => p + n._origin.value), 0), }; return result; })); cdr.detectChanges(); } /** * @param {?} i * @return {?} */ _click(i) { const { legendData, chart } = this; legendData[i].checked = !legendData[i].checked; chart.render(); } /** * @return {?} */ ngOnInit() { this.ngZone.runOutsideAngular((/** * @return {?} */ () => setTimeout((/** * @return {?} */ () => this.install()), this.delay))); } /** * @return {?} */ ngOnChanges() { this.legendData.forEach((/** * @param {?} i * @return {?} */ i => (i.checked = true))); this.ngZone.runOutsideAngular((/** * @return {?} */ () => this.attachChart())); } /** * @return {?} */ ngOnDestroy() { if (this.chart) { this.ngZone.runOutsideAngular((/** * @return {?} */ () => this.chart.destroy())); } } } G2RadarComponent.decorators = [ { type: Component, args: [{ selector: 'g2-radar', exportAs: 'g2Radar', template: "<ng-container *nzStringTemplateOutlet=\"title\">\n <h4>{{title}}</h4>\n</ng-container>\n<div #container></div>\n<div nz-row\n class=\"g2-radar__legend\"\n *ngIf=\"hasLegend\">\n <div nz-col\n [nzSpan]=\"24 / legendData.length\"\n *ngFor=\"let i of legendData; let idx = index\"\n (click)=\"_click(idx)\"\n class=\"g2-radar__legend-item\">\n <i class=\"g2-radar__legend-dot\"\n [ngStyle]=\"{'background-color': !i.checked ? '#aaa' : i.color}\"></i>\n {{i.name}}\n <h6 class=\"g2-radar__legend-title\">{{i.value}}</h6>\n </div>\n</div>\n", host: { '[style.height.px]': 'height', '[class.g2-radar]': 'true', }, preserveWhitespaces: false, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }] } ]; /** @nocollapse */ G2RadarComponent.ctorParameters = () => [ { type: ChangeDetectorRef }, { type: NgZone } ]; G2RadarComponent.propDecorators = { node: [{ type: ViewChild, args: ['container', { static: true },] }], delay: [{ type: Input }], title: [{ type: Input }], height: [{ type: Input }], padding: [{ type: Input }], hasLegend: [{ type: Input }], tickCount: [{ type: Input }], data: [{ type: Input }], colors: [{ type: Input }] }; __decorate([ InputNumber(), __metadata("design:type", Object) ], G2RadarComponent.prototype, "delay", void 0); __decorate([ InputNumber(), __metadata("design:type", Object) ], G2RadarComponent.prototype, "height", void 0); __decorate([ InputBoolean(), __metadata("design:type", Object) ], G2RadarComponent.prototype, "hasLegend", void 0); __decorate([ InputNumber(), __metadata("design:type", Object) ], G2RadarComponent.prototype, "tickCount", void 0); if (false) { /** * @type {?} * @private */ G2RadarComponent.prototype.node; /** * @type {?} * @private */ G2RadarComponent.prototype.chart; /** @type {?} */ G2RadarComponent.prototype.legendData; /** @type {?} */ G2RadarComponent.prototype.delay; /** @type {?} */ G2RadarComponent.prototype.title; /** @type {?} */ G2RadarComponent.prototype.height; /** @type {?} */ G2RadarComponent.prototype.padding; /** @type {?} */ G2RadarComponent.prototype.hasLegend; /** @type {?} */ G2RadarComponent.prototype.tickCount; /** @type {?} */ G2RadarComponent.prototype.data; /** @type {?} */ G2RadarComponent.prototype.colors; /** * @type {?} * @private */ G2RadarComponent.prototype.cdr; /** * @type {?} * @private */ G2RadarComponent.prototype.ngZone; } /** * @fileoverview added by tsickle * Generated from: radar.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const COMPONENTS = [G2RadarComponent]; class G2RadarModule { } G2RadarModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, LxlibUtilModule, NzGridModule, NzOutletModule], declarations: [...COMPONENTS], exports: [...COMPONENTS], },] } ]; /** * @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: radar.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { G2RadarComponent, G2RadarModule }; //# sourceMappingURL=radar.js.map