@lxlib/chart
Version:
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.
299 lines (293 loc) • 8.43 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, NgZone, Input, NgModule } from '@angular/core';
import { registerShape, Chart } from '@antv/g2';
import { InputNumber, LxlibUtilModule } from '@lxlib/util';
import { CommonModule } from '@angular/common';
/**
* @fileoverview added by tsickle
* Generated from: gauge.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class G2GaugeComponent {
// #endregion
/**
* @param {?} el
* @param {?} ngZone
*/
constructor(el, ngZone) {
this.el = el;
this.ngZone = ngZone;
// #region fields
this.delay = 0;
this.color = '#2f9cff';
this.bgColor = '#f0f2f5';
this.padding = [10, 10, 30, 10];
}
/**
* @private
* @return {?}
*/
install() {
// 自定义Shape 部分
registerShape('point', 'pointer', {
/**
* @param {?} cfg
* @param {?} container
* @return {?}
*/
draw(cfg, container) {
/** @type {?} */
const group = container.addGroup({});
// 获取极坐标系下画布中心点
/** @type {?} */
const center = ((/** @type {?} */ (this))).parsePoint({ x: 0, y: 0 });
// 绘制指针
group.addShape('line', {
attrs: {
x1: center.x,
y1: center.y,
x2: cfg.x,
y2: cfg.y,
stroke: cfg.color,
lineWidth: 2.5,
lineCap: 'round',
},
});
group.addShape('circle', {
attrs: {
x: center.x,
y: center.y,
r: 5.75,
stroke: cfg.color,
lineWidth: 2,
fill: '#fff',
},
});
return group;
},
});
const { el, height, padding, format } = this;
/** @type {?} */
const chart = (this.chart = new Chart({
container: el.nativeElement,
autoFit: true,
height,
padding,
}));
chart.legend(false);
chart.animate(false);
chart.tooltip(false);
chart.coordinate('polar', {
startAngle: (-9 / 8) * Math.PI,
endAngle: (1 / 8) * Math.PI,
radius: 0.75,
});
chart.scale('value', {
min: 0,
max: 100,
nice: true,
tickCount: 6,
});
chart.axis('1', false);
chart.axis('value', {
line: null,
label: {
offset: -12,
formatter: format,
},
tickLine: null,
grid: null,
});
chart.point().position('value*1').shape('pointer');
this.attachChart();
}
/**
* @private
* @return {?}
*/
attachChart() {
const { chart, percent, color, bgColor, title } = this;
if (!chart)
return;
/** @type {?} */
const data = [{ name: title, value: percent }];
/** @type {?} */
const val = data[0].value;
chart.annotation().clear(true);
chart.geometries[0].color(color);
// 绘制仪表盘背景
chart.annotation().arc({
top: false,
start: [0, 0.95],
end: [100, 0.95],
style: {
stroke: bgColor,
lineWidth: 12,
lineDash: null,
},
});
chart.annotation().arc({
start: [0, 0.95],
end: [data[0].value, 0.95],
style: {
stroke: color,
lineWidth: 12,
lineDash: null,
},
});
// 绘制指标数字
chart.annotation().text({
position: ['50%', '85%'],
content: title,
style: {
fontSize: 12,
fill: 'rgba(0, 0, 0, 0.43)',
textAlign: 'center',
},
});
chart.annotation().text({
position: ['50%', '90%'],
content: `${val} %`,
style: {
fontSize: 24,
fill: 'rgba(0, 0, 0, 0.85)',
textAlign: 'center',
},
offsetY: 15,
});
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()));
}
}
}
G2GaugeComponent.decorators = [
{ type: Component, args: [{
selector: 'g2-gauge',
exportAs: 'g2Gauge',
template: ``,
host: {
'[class.g2-gauge]': 'true',
},
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
}] }
];
/** @nocollapse */
G2GaugeComponent.ctorParameters = () => [
{ type: ElementRef },
{ type: NgZone }
];
G2GaugeComponent.propDecorators = {
delay: [{ type: Input }],
title: [{ type: Input }],
height: [{ type: Input }],
color: [{ type: Input }],
bgColor: [{ type: Input }],
format: [{ type: Input }],
percent: [{ type: Input }],
padding: [{ type: Input }]
};
__decorate([
InputNumber(),
__metadata("design:type", Object)
], G2GaugeComponent.prototype, "delay", void 0);
__decorate([
InputNumber(),
__metadata("design:type", Number)
], G2GaugeComponent.prototype, "height", void 0);
__decorate([
InputNumber(),
__metadata("design:type", Number)
], G2GaugeComponent.prototype, "percent", void 0);
if (false) {
/**
* @type {?}
* @private
*/
G2GaugeComponent.prototype.chart;
/** @type {?} */
G2GaugeComponent.prototype.delay;
/** @type {?} */
G2GaugeComponent.prototype.title;
/** @type {?} */
G2GaugeComponent.prototype.height;
/** @type {?} */
G2GaugeComponent.prototype.color;
/** @type {?} */
G2GaugeComponent.prototype.bgColor;
/** @type {?} */
G2GaugeComponent.prototype.format;
/** @type {?} */
G2GaugeComponent.prototype.percent;
/** @type {?} */
G2GaugeComponent.prototype.padding;
/**
* @type {?}
* @private
*/
G2GaugeComponent.prototype.el;
/**
* @type {?}
* @private
*/
G2GaugeComponent.prototype.ngZone;
}
/**
* @fileoverview added by tsickle
* Generated from: gauge.module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const COMPONENTS = [G2GaugeComponent];
class G2GaugeModule {
}
G2GaugeModule.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: gauge.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { G2GaugeComponent, G2GaugeModule };
//# sourceMappingURL=gauge.js.map