UNPKG

@ohayojp/chart

Version:

Cache the dictionary, city data etc.

303 lines (297 loc) 8.88 kB
import { __decorate, __metadata } from 'tslib'; import { Platform } from '@angular/cdk/platform'; import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, NgZone, Input, Output, NgModule } from '@angular/core'; import { Chart } from '@antv/g2'; import { OhayoConfigService, InputNumber, OhayoUtilModule } from '@ohayojp/util'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * Generated from: mini-bar.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,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;*/ } /** * @record */ function G2MiniBarClickItem() { } if (false) { /** @type {?} */ G2MiniBarClickItem.prototype.item; /** @type {?} */ G2MiniBarClickItem.prototype.ev; } class G2MiniBarComponent { // #endregion /** * @param {?} el * @param {?} ngZone * @param {?} configSrv * @param {?} platform */ constructor(el, ngZone, configSrv, platform) { this.el = el; this.ngZone = ngZone; this.platform = platform; // #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'; this.clickItem = new EventEmitter(); configSrv.attachKey(this, 'chart', 'theme'); } /** * @return {?} */ get chart() { return this._chart; } /** * @private * @return {?} */ install() { const { el, height, padding, yTooltipSuffix, tooltipType, theme } = this; /** @type {?} */ const chart = (this._chart = new Chart({ container: el.nativeElement, autoFit: true, height, padding, theme, })); 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.on(`interval:click`, (/** * @param {?} ev * @return {?} */ (ev) => { this.ngZone.run((/** * @return {?} */ () => { var _a; return this.clickItem.emit({ item: (_a = ev.data) === null || _a === void 0 ? void 0 : _a.data, ev }); })); })); 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); _chart.render(); } /** * @return {?} */ ngOnInit() { if (!this.platform.isBrowser) { return; } 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 }, { type: OhayoConfigService }, { type: Platform } ]; 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 }], theme: [{ type: Input }], clickItem: [{ type: Output }] }; __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 {?} */ G2MiniBarComponent.ngAcceptInputType_delay; /** @type {?} */ G2MiniBarComponent.ngAcceptInputType_height; /** @type {?} */ G2MiniBarComponent.ngAcceptInputType_borderWidth; /** * @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 {?} */ G2MiniBarComponent.prototype.theme; /** @type {?} */ G2MiniBarComponent.prototype.clickItem; /** * @type {?} * @private */ G2MiniBarComponent.prototype.el; /** * @type {?} * @private */ G2MiniBarComponent.prototype.ngZone; /** * @type {?} * @private */ G2MiniBarComponent.prototype.platform; } /** * @fileoverview added by tsickle * Generated from: mini-bar.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const COMPONENTS = [G2MiniBarComponent]; class G2MiniBarModule { } G2MiniBarModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, OhayoUtilModule], declarations: [...COMPONENTS], exports: [...COMPONENTS], },] } ]; /** * @fileoverview added by tsickle * Generated from: public_api.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * Generated from: mini-bar.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { G2MiniBarComponent, G2MiniBarModule }; //# sourceMappingURL=mini-bar.js.map