UNPKG

@lxlib/chart

Version:

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

247 lines (241 loc) 6.93 kB
import { __decorate, __metadata } from 'tslib'; import { Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, NgZone, Input, NgModule } from '@angular/core'; import { Chart } from '@antv/g2'; import { InputNumber, LxlibUtilModule } from '@lxlib/util'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * Generated from: mini-bar.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function G2MiniBarData() { } if (false) { /** @type {?} */ G2MiniBarData.prototype.x; /** @type {?} */ G2MiniBarData.prototype.y; /* Skipping unhandled member: [key: string]: any;*/ } class G2MiniBarComponent { // #endregion /** * @param {?} el * @param {?} ngZone */ constructor(el, ngZone) { this.el = el; this.ngZone = ngZone; // #region fields this.delay = 0; this.color = '#1890FF'; this.height = 0; this.borderWidth = 5; this.padding = [8, 8, 8, 8]; this.data = []; this.yTooltipSuffix = ''; this.tooltipType = 'default'; } /** * @private * @return {?} */ install() { const { el, height, padding, yTooltipSuffix, tooltipType } = this; /** @type {?} */ const chart = (this.chart = new Chart({ container: el.nativeElement, autoFit: true, height, padding, })); chart.scale({ x: { type: 'cat', }, y: { min: 0, }, }); chart.legend(false); chart.axis(false); /** @type {?} */ const tooltipOption = { showTitle: false, showMarkers: true, showCrosshairs: false, enterable: true, domStyles: { 'g2-tooltip': { padding: '0px' }, 'g2-tooltip-title': { display: 'none' }, 'g2-tooltip-list-item': { margin: '4px' }, }, }; if (tooltipType === 'mini') { tooltipOption.position = 'top'; (/** @type {?} */ (tooltipOption.domStyles))['g2-tooltip'] = { padding: '0px', backgroundColor: 'transparent', boxShadow: 'none' }; tooltipOption.itemTpl = `<li>{value}</li>`; tooltipOption.offset = 0; } chart.tooltip(tooltipOption); chart .interval() .position('x*y') .tooltip('x*y', (/** * @param {?} x * @param {?} y * @return {?} */ (x, y) => ({ name: x, value: y + yTooltipSuffix }))); chart.render(); this.attachChart(); } /** * @private * @return {?} */ attachChart() { const { chart, height, padding, data, color, borderWidth } = this; if (!chart || !data || data.length <= 0) return; chart.geometries[0].size(borderWidth).color(color); chart.height = height; chart.padding = padding; chart.changeData(data); } /** * @return {?} */ ngOnInit() { this.ngZone.runOutsideAngular((/** * @return {?} */ () => setTimeout((/** * @return {?} */ () => this.install()), this.delay))); } /** * @return {?} */ ngOnChanges() { this.ngZone.runOutsideAngular((/** * @return {?} */ () => this.attachChart())); } /** * @return {?} */ ngOnDestroy() { if (this.chart) { this.ngZone.runOutsideAngular((/** * @return {?} */ () => this.chart.destroy())); } } } G2MiniBarComponent.decorators = [ { type: Component, args: [{ selector: 'g2-mini-bar', exportAs: 'g2MiniBar', template: ``, host: { '[style.height.px]': 'height', }, preserveWhitespaces: false, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }] } ]; /** @nocollapse */ G2MiniBarComponent.ctorParameters = () => [ { type: ElementRef }, { type: NgZone } ]; G2MiniBarComponent.propDecorators = { delay: [{ type: Input }], color: [{ type: Input }], height: [{ type: Input }], borderWidth: [{ type: Input }], padding: [{ type: Input }], data: [{ type: Input }], yTooltipSuffix: [{ type: Input }], tooltipType: [{ type: Input }] }; __decorate([ InputNumber(), __metadata("design:type", Object) ], G2MiniBarComponent.prototype, "delay", void 0); __decorate([ InputNumber(), __metadata("design:type", Object) ], G2MiniBarComponent.prototype, "height", void 0); __decorate([ InputNumber(), __metadata("design:type", Object) ], G2MiniBarComponent.prototype, "borderWidth", void 0); if (false) { /** * @type {?} * @private */ G2MiniBarComponent.prototype.chart; /** @type {?} */ G2MiniBarComponent.prototype.delay; /** @type {?} */ G2MiniBarComponent.prototype.color; /** @type {?} */ G2MiniBarComponent.prototype.height; /** @type {?} */ G2MiniBarComponent.prototype.borderWidth; /** @type {?} */ G2MiniBarComponent.prototype.padding; /** @type {?} */ G2MiniBarComponent.prototype.data; /** @type {?} */ G2MiniBarComponent.prototype.yTooltipSuffix; /** @type {?} */ G2MiniBarComponent.prototype.tooltipType; /** * @type {?} * @private */ G2MiniBarComponent.prototype.el; /** * @type {?} * @private */ G2MiniBarComponent.prototype.ngZone; } /** * @fileoverview added by tsickle * Generated from: mini-bar.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const COMPONENTS = [G2MiniBarComponent]; class G2MiniBarModule { } G2MiniBarModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, LxlibUtilModule], 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: mini-bar.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { G2MiniBarComponent, G2MiniBarModule }; //# sourceMappingURL=mini-bar.js.map