@lxlib/chart
Version:
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.
302 lines (296 loc) • 8.62 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, NgZone, Input, NgModule } from '@angular/core';
import { Chart } from '@antv/g2';
import { InputNumber, InputBoolean, LxlibUtilModule } from '@lxlib/util';
import { CommonModule } from '@angular/common';
/**
* @fileoverview added by tsickle
* Generated from: mini-area.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @record
*/
function G2MiniAreaData() { }
if (false) {
/** @type {?} */
G2MiniAreaData.prototype.x;
/** @type {?} */
G2MiniAreaData.prototype.y;
/* Skipping unhandled member: [key: string]: any;*/
}
class G2MiniAreaComponent {
// #endregion
/**
* @param {?} el
* @param {?} ngZone
*/
constructor(el, ngZone) {
this.el = el;
this.ngZone = ngZone;
// #region fields
this.delay = 0;
this.color = 'rgba(24, 144, 255, 0.2)';
this.borderColor = '#1890FF';
this.borderWidth = 2;
this.height = 56;
this.fit = true;
this.line = false;
this.animate = true;
this.padding = [8, 8, 8, 8];
this.data = [];
this.yTooltipSuffix = '';
this.tooltipType = 'default';
}
/**
* @private
* @return {?}
*/
install() {
const { el, fit, height, padding, xAxis, yAxis, yTooltipSuffix, tooltipType, line } = this;
/** @type {?} */
const chart = (this.chart = new Chart({
container: el.nativeElement,
autoFit: fit,
height,
padding,
}));
if (!xAxis && !yAxis) {
chart.axis(false);
}
if (xAxis) {
chart.axis('x', xAxis);
}
else {
chart.axis('x', false);
}
if (yAxis) {
chart.axis('y', yAxis);
}
else {
chart.axis('y', false);
}
chart.legend(false);
/** @type {?} */
const tooltipOption = {
showTitle: false,
showMarkers: true,
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
.area()
.position('x*y')
.tooltip('x*y', (/**
* @param {?} x
* @param {?} y
* @return {?}
*/
(x, y) => ({ name: x, value: y + yTooltipSuffix })))
.shape('smooth');
if (line) {
chart.line().position('x*y').shape('smooth').tooltip(false);
}
chart.render();
this.attachChart();
}
/**
* @private
* @return {?}
*/
attachChart() {
const { chart, line, fit, height, animate, padding, data, color, borderColor, borderWidth } = this;
if (!chart || !data || data.length <= 0) {
return;
}
/** @type {?} */
const geoms = chart.geometries;
geoms.forEach((/**
* @param {?} g
* @return {?}
*/
g => g.color(color)));
if (line) {
geoms[1].color(borderColor).size(borderWidth);
}
chart.autoFit = fit;
chart.height = height;
chart.animate(animate);
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()));
}
}
}
G2MiniAreaComponent.decorators = [
{ type: Component, args: [{
selector: 'g2-mini-area',
exportAs: 'g2MiniArea',
template: ``,
host: {
'[style.height.px]': 'height',
},
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
}] }
];
/** @nocollapse */
G2MiniAreaComponent.ctorParameters = () => [
{ type: ElementRef },
{ type: NgZone }
];
G2MiniAreaComponent.propDecorators = {
delay: [{ type: Input }],
color: [{ type: Input }],
borderColor: [{ type: Input }],
borderWidth: [{ type: Input }],
height: [{ type: Input }],
fit: [{ type: Input }],
line: [{ type: Input }],
animate: [{ type: Input }],
xAxis: [{ type: Input }],
yAxis: [{ type: Input }],
padding: [{ type: Input }],
data: [{ type: Input }],
yTooltipSuffix: [{ type: Input }],
tooltipType: [{ type: Input }]
};
__decorate([
InputNumber(),
__metadata("design:type", Object)
], G2MiniAreaComponent.prototype, "delay", void 0);
__decorate([
InputNumber(),
__metadata("design:type", Object)
], G2MiniAreaComponent.prototype, "borderWidth", void 0);
__decorate([
InputNumber(),
__metadata("design:type", Object)
], G2MiniAreaComponent.prototype, "height", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], G2MiniAreaComponent.prototype, "fit", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], G2MiniAreaComponent.prototype, "line", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], G2MiniAreaComponent.prototype, "animate", void 0);
if (false) {
/**
* @type {?}
* @private
*/
G2MiniAreaComponent.prototype.chart;
/** @type {?} */
G2MiniAreaComponent.prototype.delay;
/** @type {?} */
G2MiniAreaComponent.prototype.color;
/** @type {?} */
G2MiniAreaComponent.prototype.borderColor;
/** @type {?} */
G2MiniAreaComponent.prototype.borderWidth;
/** @type {?} */
G2MiniAreaComponent.prototype.height;
/** @type {?} */
G2MiniAreaComponent.prototype.fit;
/** @type {?} */
G2MiniAreaComponent.prototype.line;
/** @type {?} */
G2MiniAreaComponent.prototype.animate;
/** @type {?} */
G2MiniAreaComponent.prototype.xAxis;
/** @type {?} */
G2MiniAreaComponent.prototype.yAxis;
/** @type {?} */
G2MiniAreaComponent.prototype.padding;
/** @type {?} */
G2MiniAreaComponent.prototype.data;
/** @type {?} */
G2MiniAreaComponent.prototype.yTooltipSuffix;
/** @type {?} */
G2MiniAreaComponent.prototype.tooltipType;
/**
* @type {?}
* @private
*/
G2MiniAreaComponent.prototype.el;
/**
* @type {?}
* @private
*/
G2MiniAreaComponent.prototype.ngZone;
}
/**
* @fileoverview added by tsickle
* Generated from: mini-area.module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const COMPONENTS = [G2MiniAreaComponent];
class G2MiniAreaModule {
}
G2MiniAreaModule.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-area.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { G2MiniAreaComponent, G2MiniAreaModule };
//# sourceMappingURL=mini-area.js.map