@asoftwareworld/charts
Version:
`ASW Charts` helps you with the Highcharts library comes with all the tools you need to create reliable and secure data visualizations and Built on Angular.
365 lines (358 loc) • 15.2 kB
JavaScript
import * as i0 from '@angular/core';
import { EventEmitter, Component, Input, Output, ViewChild, HostListener, NgModule } from '@angular/core';
import * as i2 from '@asoftwareworld/charts/core';
import { GridOptionsEnum, CurrencyCodeEnum, LegendPositionEnum, ChartLegendTypeEnum, LegendLayoutEnum, AswChartConstants, AswCurrencyPipe } from '@asoftwareworld/charts/core';
import { ObjectUtils } from '@asoftwareworld/charts/utils';
import * as Highcharts from 'highcharts';
import more from 'highcharts/highcharts-more';
import * as i1 from '@angular/common';
import { CommonModule, PercentPipe, CurrencyPipe } from '@angular/common';
/**
* @license
* Copyright ASW (A Software World) All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file
*/
var AswChartTypeEnum;
(function (AswChartTypeEnum) {
AswChartTypeEnum["Line"] = "line";
AswChartTypeEnum["Column"] = "column";
AswChartTypeEnum["Bar"] = "bar";
AswChartTypeEnum["Sankey"] = "sankey";
})(AswChartTypeEnum || (AswChartTypeEnum = {}));
more(Highcharts);
class AswGenericChart {
constructor(currencyPipe, aswCurrencyPipe) {
this.currencyPipe = currencyPipe;
this.aswCurrencyPipe = aswCurrencyPipe;
this.deviceSize = GridOptionsEnum.Large;
this.viewInitialized = false;
this.chartType = AswChartTypeEnum.Line;
this.isLegendSort = true;
this.isLegendDisplay = true;
this.currencyCode = CurrencyCodeEnum.Blank;
this.legendPosition = LegendPositionEnum.Right;
this.legendType = ChartLegendTypeEnum.Both;
this.legendWidthPx = 250;
this.legendLayout = LegendLayoutEnum.Vertical;
this.chartPointClick = new EventEmitter();
}
ngOnChanges() {
if (!this.viewInitialized) {
return;
}
this.initializeChart();
}
ngAfterViewInit() {
this.viewInitialized = true;
this.initializeChart();
}
initializeChart() {
if (this.config) {
this.cloneConfiguration = this.config;
const containerWidth = this.genericChart.nativeElement.clientWidth;
this.deviceSize = ObjectUtils.findDeviceSize(containerWidth);
this.removeChartCredit();
this.setChartTooltip();
const series = this.cloneConfiguration.series;
this.setChartSeriesOptions(series);
if (this.legendLayout === LegendLayoutEnum.Vertical) {
this.setChartLegendOption(this.legendWidthPx);
}
this.clickOnLinePoint();
Highcharts.chart(this.genericChart.nativeElement, this.cloneConfiguration);
}
}
onResize() {
this.initializeChart();
}
removeChartCredit() {
this.cloneConfiguration.credits = {
enabled: false
};
}
setChartTooltip() {
const this$ = this;
this.cloneConfiguration.tooltip = {
useHTML: true,
split: false,
backgroundColor: AswChartConstants.blackColor,
borderColor: AswChartConstants.blackColor,
style: {
color: AswChartConstants.whiteColor,
fontWeight: AswChartConstants.fontWeight
},
borderRadius: 0,
enabled: true,
formatter() {
return `
<div class="row">
<div class="col-md-12 text-end text-right">
<strong>${this.point.category}</strong>
</div>
<div class="col-md-12 text-end text-right">
<span style="color: ${this.point.color}">\u25A0</span>
<strong>${this.point.series.name}</strong>
</div>
<div class="col-md-12 text-end text-right">
${this$.currencyCode === CurrencyCodeEnum.Blank
? this.point.options.y : this$.currencyPipe.transform(this.point.options.y, this$.currencyCode)}
</div>
</div>
`;
}
};
}
clickOnLinePoint() {
if (this.cloneConfiguration.plotOptions) {
// tslint:disable-next-line:no-non-null-assertion
this.cloneConfiguration.plotOptions[this.chartType] = {
point: {
events: {
click: ((event) => {
const pointClickEvent = {
name: event.point.series.name,
index: event.point.index,
value: event.point.options.y,
category: event.point.category
};
this.chartPointClick.emit(pointClickEvent);
})
}
}
};
}
else {
this.cloneConfiguration.plotOptions = {
series: {
point: {
events: {
click: ((event) => {
const pointClickEvent = {
name: event.point.series.name,
index: event.point.index,
value: event.point.options.y,
category: event.point.category
};
this.chartPointClick.emit(pointClickEvent);
})
}
}
}
};
}
}
setChartSeriesOptions(series) {
series.forEach((seriesOption) => {
seriesOption.allowPointSelect = true;
seriesOption.showInLegend = true;
seriesOption.cursor = AswChartConstants.pointer;
const data = seriesOption.data;
// this.handleNegativeSeriesData(data);
// const sortedSeriesOptionData: PointOptionsObject[] = this.isLegendSort ? this.sortSeriesData(data) : data;
// seriesOption.data = sortedSeriesOptionData;
});
}
sortSeriesData(data) {
if (this.legendType === ChartLegendTypeEnum.Default) {
data.sort((a, b) => {
return ('' + a.name).localeCompare(b.name);
});
return data;
}
else {
data.sort((a, b) => {
if (a.y && b.y) {
return a.value - b.value;
}
else {
return 0;
}
});
data.reverse();
return data;
}
}
handleNegativeSeriesData(data) {
data.forEach((element) => {
element.value = element.y;
element.y = element.y ? Math.abs(element.y) : 0.001;
});
}
setChartLegendOption(legendWidthPx) {
const this$ = this;
this.cloneConfiguration.legend = {
useHTML: true,
enabled: this.isLegendDisplay,
floating: false,
align: this.setLegendAlignment(),
layout: 'vertical',
verticalAlign: this.setLegendVerticalAlignment(),
symbolHeight: 10,
symbolWidth: 10,
symbolRadius: 0,
itemMarginTop: 3,
itemMarginBottom: 3,
itemStyle: {
fontSize: this.deviceSize === GridOptionsEnum.ExtraSmall ? '12px' : '14px',
fontWeight: AswChartConstants.fontWeight
},
width: legendWidthPx + 15,
title: {
text: this$.setChartLegendWithHeader(legendWidthPx + 15),
style: {
fontSize: this.deviceSize === GridOptionsEnum.ExtraSmall
? AswChartConstants.fontSize12 : AswChartConstants.fontSize14,
color: '#6c757d',
fontWeight: AswChartConstants.fontWeight,
fontFamily: '500 14px/20px Google Sans Text,Arial,Helvetica,sans-serif'
}
},
labelFormatter() {
const point = this;
const value = point.yData.reduce((acc, cur) => acc + cur, 0);
return this$.setChartLegendWithHeader(legendWidthPx, point.name, value);
}
};
}
setLegendAlignment() {
if (this.deviceSize === GridOptionsEnum.ExtraSmall) {
return 'center';
}
else if (this.legendPosition === LegendPositionEnum.Right) {
return LegendPositionEnum.Right;
}
else if (this.legendPosition === LegendPositionEnum.Left) {
return LegendPositionEnum.Left;
}
else {
return 'center';
}
}
setLegendVerticalAlignment() {
if (this.deviceSize === GridOptionsEnum.ExtraSmall) {
return LegendPositionEnum.Bottom;
}
else if (this.legendPosition === LegendPositionEnum.Right) {
return 'middle';
}
else if (this.legendPosition === LegendPositionEnum.Left) {
return 'middle';
}
else {
return LegendPositionEnum.Bottom;
}
}
setChartLegendWithHeader(legendWidthPx, name, value) {
let legendCategoryWidthPx;
let legendValueWidthPx;
if (this.legendType === ChartLegendTypeEnum.Default) {
return `
<div style="width:${legendWidthPx}px">
<div class="row">
<div class="col-md-12 col-sm-12 col-12">
${name ? name : 'Category'}
</div>
</div>
</div>`;
}
else {
legendCategoryWidthPx = legendWidthPx * 0.5;
legendValueWidthPx = legendWidthPx * 0.5;
return `
<div style="width:${legendCategoryWidthPx + legendValueWidthPx}px">
<div class="row">
<div class="col-md-6 col-sm-6 col-6">
${name ? name : 'Category'}
</div>
<div class="col-md-6 col-sm-6 col-6 text-end text-right">
${value ? this.currencyCode === CurrencyCodeEnum.Blank
? value : this.currencyPipe.transform(value, this.currencyCode, 'symbol', '.2') : 'Total'}
</div>
</div>
</div>`;
}
}
}
AswGenericChart.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: AswGenericChart, deps: [{ token: i1.CurrencyPipe }, { token: i2.AswCurrencyPipe }], target: i0.ɵɵFactoryTarget.Component });
AswGenericChart.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.2", type: AswGenericChart, selector: "asw-generic-chart", inputs: { chartType: "chartType", config: "config", isLegendSort: "isLegendSort", isLegendDisplay: "isLegendDisplay", currencyCode: "currencyCode", legendPosition: "legendPosition", legendType: "legendType", legendWidthPx: "legendWidthPx", legendLayout: "legendLayout" }, outputs: { chartPointClick: "chartPointClick" }, host: { listeners: { "window:resize": "onResize()" } }, viewQueries: [{ propertyName: "genericChart", first: true, predicate: ["genericChart"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: "<div #genericChart></div>" });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: AswGenericChart, decorators: [{
type: Component,
args: [{ selector: 'asw-generic-chart', template: "<div #genericChart></div>" }]
}], ctorParameters: function () { return [{ type: i1.CurrencyPipe }, { type: i2.AswCurrencyPipe }]; }, propDecorators: { chartType: [{
type: Input
}], config: [{
type: Input
}], isLegendSort: [{
type: Input
}], isLegendDisplay: [{
type: Input
}], currencyCode: [{
type: Input
}], legendPosition: [{
type: Input
}], legendType: [{
type: Input
}], legendWidthPx: [{
type: Input
}], legendLayout: [{
type: Input
}], chartPointClick: [{
type: Output
}], genericChart: [{
type: ViewChild,
args: ['genericChart', { static: true }]
}], onResize: [{
type: HostListener,
args: ['window:resize']
}] } });
/**
* @license
* Copyright ASW (A Software World) All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file
*/
class AswGenericChartModule {
}
AswGenericChartModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: AswGenericChartModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
AswGenericChartModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: AswGenericChartModule, declarations: [AswGenericChart], imports: [CommonModule], exports: [AswGenericChart] });
AswGenericChartModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: AswGenericChartModule, providers: [
PercentPipe,
AswCurrencyPipe,
CurrencyPipe
], imports: [[
CommonModule,
]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: AswGenericChartModule, decorators: [{
type: NgModule,
args: [{
declarations: [
AswGenericChart
],
imports: [
CommonModule,
],
exports: [
AswGenericChart
],
providers: [
PercentPipe,
AswCurrencyPipe,
CurrencyPipe
]
}]
}] });
/**
* @license
* Copyright ASW (A Software World) All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file
*/
/**
* Generated bundle index. Do not edit.
*/
export { AswChartTypeEnum, AswGenericChart, AswGenericChartModule };
//# sourceMappingURL=asoftwareworld-charts-generic-chart.mjs.map