UNPKG

@yelon/chart

Version:

Cache the dictionary, city data etc.

114 lines (109 loc) 5.04 kB
import * as i0 from '@angular/core'; import { EventEmitter, numberAttribute, Output, Input, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule } from '@angular/core'; import { G2BaseComponent, genMiniTooltipOptions } from '@yelon/chart/core'; import { CommonModule } from '@angular/common'; class G2MiniBarComponent extends G2BaseComponent { // #region fields color = '#1890FF'; height = 0; borderWidth = 5; padding = [8, 8, 8, 8]; data = []; yTooltipSuffix = ''; tooltipType = 'default'; clickItem = new EventEmitter(); // #endregion install() { const { el, height, padding, yTooltipSuffix, tooltipType, theme, color, borderWidth } = this; const chart = (this._chart = new this.winG2.Chart({ container: el.nativeElement, autoFit: true, height, padding, theme })); chart.scale({ x: { type: 'cat' }, y: { min: 0 } }); chart.legend(false); chart.axis(false); chart.tooltip(genMiniTooltipOptions(tooltipType, { showCrosshairs: false })); chart .interval() .position('x*y') .color('x*y', (x, y) => { const colorItem = this.data.find(w => w.x === x && w.y === y); return colorItem && colorItem.color ? colorItem.color : color; }) .size(borderWidth) .tooltip('x*y', (x, y) => ({ name: x, value: y + yTooltipSuffix })); chart.on(`interval:click`, (ev) => { this.ngZone.run(() => this.clickItem.emit({ item: ev.data?.data, ev })); }); this.ready.next(chart); this.changeData(); chart.render(); } changeData() { const { _chart, data } = this; if (!_chart || !Array.isArray(data) || data.length <= 0) return; _chart.changeData(data); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: G2MiniBarComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "20.1.3", type: G2MiniBarComponent, isStandalone: true, selector: "g2-mini-bar", inputs: { color: "color", height: ["height", "height", numberAttribute], borderWidth: ["borderWidth", "borderWidth", numberAttribute], padding: "padding", data: "data", yTooltipSuffix: "yTooltipSuffix", tooltipType: "tooltipType" }, outputs: { clickItem: "clickItem" }, host: { properties: { "style.height.px": "height" } }, exportAs: ["g2MiniBar"], usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: G2MiniBarComponent, decorators: [{ type: Component, args: [{ selector: 'g2-mini-bar', exportAs: 'g2MiniBar', template: ``, host: { '[style.height.px]': 'height' }, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }] }], propDecorators: { color: [{ type: Input }], height: [{ type: Input, args: [{ transform: numberAttribute }] }], borderWidth: [{ type: Input, args: [{ transform: numberAttribute }] }], padding: [{ type: Input }], data: [{ type: Input }], yTooltipSuffix: [{ type: Input }], tooltipType: [{ type: Input }], clickItem: [{ type: Output }] } }); const COMPONENTS = [G2MiniBarComponent]; class G2MiniBarModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: G2MiniBarModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.1.3", ngImport: i0, type: G2MiniBarModule, imports: [CommonModule, G2MiniBarComponent], exports: [G2MiniBarComponent] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: G2MiniBarModule, imports: [CommonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: G2MiniBarModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule, ...COMPONENTS], exports: COMPONENTS }] }] }); /** * Generated bundle index. Do not edit. */ export { G2MiniBarComponent, G2MiniBarModule }; //# sourceMappingURL=mini-bar.mjs.map