Merge remote-tracking branch 'origin/test/SUPPORT-8732' into ervu/tmp_makets

This commit is contained in:
Foat Saliakhov 2024-12-16 16:19:17 +03:00
commit 5655e7d461
13 changed files with 137 additions and 126 deletions

View file

@ -19,7 +19,7 @@ import {
} from "@webbpm/base-package";
import {ChartLegendSettings} from "./model/ChartLegendSettings";
import {ChartBarSettings} from "./model/ChartBarSettings";
import {DatasetsCommon} from "./model/DatasetsCommon";
import {Options} from "./model/Options";
import {ChartPlugin} from "./plugin/ChartPlugin";
import {ChartUtils} from "./ChartUtils";
@ -45,7 +45,7 @@ export class ErvuChartV2 extends Control implements Filterable {
public scales: ChartScaleSettings[];
public bars: ChartBarSettings;
public datasetsCommon: DatasetsCommon;
public options: Options;
@NotNull()
public loadOnStart: boolean = true;
@ -219,14 +219,19 @@ export class ErvuChartV2 extends Control implements Filterable {
chartOptions.plugins.title = this.title;
}
if (this.addDataSetsVisibilityToggleDataset && chartConfig.data.datasets &&
chartConfig.data.datasets.length > 0) {
let datasetLength = chartConfig.data.datasets.length;
chartConfig.data.datasets.push({
label: this.hideAllDatasetsLabel,
xAxisID: {display: false},
yAxisID: {display: false}
});
let datasets;
let datasetsLength: number = 0;
if (chartConfig.data && chartConfig.data.datasets && chartConfig.data.datasets.length > 0) {
datasets = chartConfig.data.datasets;
datasetsLength = datasets.length;
}
if (this.addDataSetsVisibilityToggleDataset && datasetsLength > 0) {
datasets.push({
label: this.hideAllDatasetsLabel,
xAxisID: {display: false},
yAxisID: {display: false}
});
chartOptions.plugins.legend.onClick = (e, legendItem, legend) => {
const index = legendItem.datasetIndex;
@ -234,12 +239,12 @@ export class ErvuChartV2 extends Control implements Filterable {
let datasetMeta = chartObj.getDatasetMeta(index);
if (datasetLength == index) {
if (datasetsLength == index) {
let showAll = datasetMeta.label == this.showAllDatasetsLabel;
chartObj.data.datasets[index].label =
showAll ? this.hideAllDatasetsLabel : this.showAllDatasetsLabel;
for (let i = 0; i < datasetLength; i++) {
for (let i = 0; i < datasetsLength; i++) {
chartObj.setDatasetVisibility(i, showAll);
}
chartObj.update();
@ -257,8 +262,8 @@ export class ErvuChartV2 extends Control implements Filterable {
};
}
if (chartConfig.data.datasets) { // remove it after change type of ChartDataSetDto.backgroundColor
chartConfig.data.datasets.forEach(dataset => {
if (datasetsLength > 0) { // remove it after change type of ChartDataSetDto.backgroundColor
datasets.forEach(dataset => {
if (dataset.backgroundColors) dataset.backgroundColor = dataset.backgroundColors;
});
}
@ -280,55 +285,16 @@ export class ErvuChartV2 extends Control implements Filterable {
chartOptions.scales.x = this.bars.x;
chartOptions.scales.y = this.bars.y;
// shadow bar treatment must be before border radius treatment
if (this.bars.shadowBar && chartConfig.data.datasets &&
chartConfig.data.datasets.length > 0) {
const shadowBarStack: string = this.bars.shadowBar;
let datasets = chartConfig.data.datasets;
const shadowBarIndex = datasets.findIndex(element => element.stack === shadowBarStack);
if (shadowBarIndex > -1) {
const shadowBar = datasets[shadowBarIndex];
const stacks: string[] = [];
datasets.forEach((element, index) => {
let stack: string = element.stack;
if (stack) {
if (stack !== shadowBarStack && stacks.includes(stack)) {
stacks.push(stack);
}
}
else {
stack = shadowBarStack + index;
element.stack = stack;
stacks.push(stack);
}
});
datasets.splice(shadowBarIndex, 1);
stacks.forEach(value => {
const cloneShadowBar = {...shadowBar};
cloneShadowBar.stack = value;
datasets.push(cloneShadowBar);
});
}
// shadow bar treatment
if (this.bars.shadowBar && datasetsLength > 0) {
this.initShadowBar(datasets);
}
}
if (this.datasetsCommon && chartConfig.data.datasets &&
chartConfig.data.datasets.length > 0) {
// border radius treatment
if (this.datasetsCommon.borderRadiusNumber
|| (this.datasetsCommon.borderRadius &&
(this.datasetsCommon.borderRadius.topLeft ||
this.datasetsCommon.borderRadius.topRight ||
this.datasetsCommon.borderRadius.bottomLeft ||
this.datasetsCommon.borderRadius.bottomRight))) {
const borderRadiusNumber: number = this.datasetsCommon.borderRadiusNumber;
chartConfig.data.datasets.forEach(dataset => dataset.borderRadius =
borderRadiusNumber ? borderRadiusNumber : this.datasetsCommon.borderRadius);
if (this.options) {
if (this.options.borderRadiusNumber || this.options.borderRadius) {
// border radius treatment
this.initBorderRadius(chartOptions);
}
}
@ -346,6 +312,51 @@ export class ErvuChartV2 extends Control implements Filterable {
this.chartConfig = chartConfig;
}
private initBorderRadius(options) {
if (this.options.borderRadiusNumber
|| (this.options.borderRadius &&
(this.options.borderRadius.topLeft ||
this.options.borderRadius.topRight ||
this.options.borderRadius.bottomLeft ||
this.options.borderRadius.bottomRight))) {
const borderRadiusNumber: number = this.options.borderRadiusNumber;
options.borderRadius = borderRadiusNumber ? borderRadiusNumber : this.options.borderRadius;
}
}
private initShadowBar(datasets) {
const shadowBarStack: string = this.bars.shadowBar;
const shadowBarIndex = datasets.findIndex(element => element.stack === shadowBarStack);
if (shadowBarIndex > -1) {
const shadowBar = datasets[shadowBarIndex];
const stacks: string[] = [];
datasets.forEach((element, index) => {
let stack: string = element.stack;
if (stack) {
if (stack !== shadowBarStack && !stacks.includes(stack)) {
stacks.push(stack);
}
}
else {
stack = shadowBarStack + index;
element.stack = stack;
stacks.push(stack);
}
});
datasets.splice(shadowBarIndex, 1);
stacks.forEach(value => {
const cloneShadowBar = {...shadowBar};
cloneShadowBar.stack = value;
datasets.push(cloneShadowBar);
});
}
}
private repaint(chartData) {
if (this.chart) {
this.chart.destroy();

View file

@ -1,7 +1,7 @@
import {Visible} from "@webbpm/base-package";
import {BorderRadius} from "./BorderRadius";
export class DatasetsCommon {
export class Options {
public borderRadiusNumber: number;
@Visible("borderRadiusNumber == null")
public borderRadius: BorderRadius;

View file

@ -3237,7 +3237,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>

View file

@ -2184,7 +2184,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>

View file

@ -4735,7 +4735,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -5990,7 +5990,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -7353,7 +7353,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>

View file

@ -5289,7 +5289,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -7205,7 +7205,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>

View file

@ -3151,7 +3151,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -4608,7 +4608,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -6387,7 +6387,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -9175,7 +9175,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -11581,7 +11581,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -13056,7 +13056,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -14835,7 +14835,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -17613,7 +17613,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -19073,7 +19073,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -21637,7 +21637,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -26167,7 +26167,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -27688,7 +27688,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -29866,7 +29866,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -32239,7 +32239,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -34632,7 +34632,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -36094,7 +36094,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -37872,7 +37872,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -40643,7 +40643,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -42105,7 +42105,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -43888,7 +43888,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>

View file

@ -2866,7 +2866,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -4603,7 +4603,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -6366,7 +6366,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -7315,7 +7315,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -10436,7 +10436,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -14550,7 +14550,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -18525,7 +18525,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -20047,7 +20047,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -21615,7 +21615,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -25527,7 +25527,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -26884,7 +26884,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -28545,7 +28545,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>

View file

@ -3309,7 +3309,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -6898,7 +6898,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -8977,7 +8977,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -10591,7 +10591,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -15195,7 +15195,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -16879,7 +16879,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -20272,7 +20272,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -22227,7 +22227,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>

View file

@ -4009,7 +4009,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -7863,7 +7863,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -9210,7 +9210,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -10721,7 +10721,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>

View file

@ -17069,7 +17069,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>

View file

@ -4960,7 +4960,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -6614,7 +6614,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -10685,7 +10685,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -14220,7 +14220,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -15873,7 +15873,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -18079,7 +18079,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -19761,7 +19761,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -23668,7 +23668,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>

View file

@ -6213,7 +6213,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -10714,7 +10714,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -13227,7 +13227,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -16441,7 +16441,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>
@ -18371,7 +18371,7 @@
</value>
</entry>
<entry>
<key>datasetsCommon</key>
<key>options</key>
<value>
<complex>
<entry>