Merge branch 'feature/SUPPORT-8717_default_label_color' into test/SUPPORT-8717_default_label_color

This commit is contained in:
Рауф Латыпов 2024-12-28 01:44:58 +03:00
commit f8052d675a
2 changed files with 31 additions and 27 deletions

View file

@ -11,10 +11,10 @@ import ru.cg.webbpm.modules.standard_annotations.editor.ColorEditor;
*/
public abstract class AbstractRoundLabelConfiguration implements RoundLabelConfiguration {
public Font font = Font.of("sans-serif", "500", 14);
public Font font;
@ColorEditor
public String color = "#FFFFFF";
public String color;
@Override
public ChartLabelModel getLabelModel(LoadOptions loadOptions) {

View file

@ -1,32 +1,39 @@
import {ChartPlugin} from "./ChartPlugin";
import {
AdvancedProperty,
AnalyticalScope,
Behavior,
ChartFontFamily,
ColorEditor,
Visible
} from "@webbpm/base-package";
import {Chart} from "chart.js";
import {
ChartLabelModel
} from "../../../../generated/ervu_business_metrics/model/chart/round/label/ChartLabelModel";
import {ChartUtils} from "../ChartUtils";
import {AnalyticalScope, Behavior, ChartFontFamily, Visible} from "@webbpm/base-package";
import {ErvuChartV2} from "../ErvuChartV2";
import {Font} from "../../../../generated/ervu_business_metrics/model/Font";
import {ChartLabelFormatter} from "./formatters/ChartLabelFormatter";
import {ChartPlugin} from "./ChartPlugin";
import {ChartUtils} from "../ChartUtils";
import {ErvuChartV2} from "../ErvuChartV2";
@AnalyticalScope(ErvuChartV2)
export class DoughnutCenterLabelsPlugin extends Behavior implements ChartPlugin {
public static readonly ID = 'doughnut-center-labels';
private static readonly DEFAULTS = {
color: 'rgb(255, 255, 255)',
font: {
family: ChartFontFamily.SANS_SERIF,
weight: '500',
size: 14
}
}
@Visible('false')
public id: string = DoughnutCenterLabelsPlugin.ID;
public id: string = 'doughnut-center-labels';
@ColorEditor()
public defaultColor: string = 'rgb(0, 0, 0)';
@AdvancedProperty()
public defaultFont: Font = {
family: ChartFontFamily.SANS_SERIF,
weight: '500',
size: 14
}
@AdvancedProperty()
public formatters: ChartLabelFormatter[] = [];
beforeDatasetsDraw(chart: Chart, args?: { cancellable: true }, options?: any): void {
if (!chart.data || !chart.data.datasets || !(<any>chart.data).centerLabels || ChartUtils.isEmpty(chart)) {
if (!chart.data || !chart.data.datasets || !(<any>chart.data).centerLabels
|| ChartUtils.isEmpty(chart)) {
return;
}
@ -101,18 +108,15 @@ export class DoughnutCenterLabelsPlugin extends Behavior implements ChartPlugin
formatter.format(label, labels, index);
}
label.color = label.color ? label.color : DoughnutCenterLabelsPlugin.DEFAULTS.color;
label.color = label.color ? label.color : this.defaultColor;
if (label.font) {
label.font.family =
label.font.family ? label.font.family : DoughnutCenterLabelsPlugin.DEFAULTS.font.family;
label.font.weight =
label.font.weight ? label.font.weight : DoughnutCenterLabelsPlugin.DEFAULTS.font.weight;
label.font.size =
label.font.size ? label.font.size : DoughnutCenterLabelsPlugin.DEFAULTS.font.size;
label.font.family = label.font.family ? label.font.family : this.defaultFont.family;
label.font.weight = label.font.weight ? label.font.weight : this.defaultFont.weight;
label.font.size = label.font.size ? label.font.size : this.defaultFont.size;
}
else {
label.font = DoughnutCenterLabelsPlugin.DEFAULTS.font
label.font = this.defaultFont;
}
});
}