SUPPORT-8717: setting default label color

This commit is contained in:
Рауф Латыпов 2024-12-28 01:41:35 +03:00
parent b8f8c9d734
commit ccdfdd40c8
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 abstract class AbstractRoundLabelConfiguration implements RoundLabelConfiguration {
public Font font = Font.of("sans-serif", "500", 14); public Font font;
@ColorEditor @ColorEditor
public String color = "#FFFFFF"; public String color;
@Override @Override
public ChartLabelModel getLabelModel(LoadOptions loadOptions) { 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 {Chart} from "chart.js";
import { import {
ChartLabelModel ChartLabelModel
} from "../../../../generated/ervu_business_metrics/model/chart/round/label/ChartLabelModel"; } from "../../../../generated/ervu_business_metrics/model/chart/round/label/ChartLabelModel";
import {ChartUtils} from "../ChartUtils"; import {Font} from "../../../../generated/ervu_business_metrics/model/Font";
import {AnalyticalScope, Behavior, ChartFontFamily, Visible} from "@webbpm/base-package";
import {ErvuChartV2} from "../ErvuChartV2";
import {ChartLabelFormatter} from "./formatters/ChartLabelFormatter"; import {ChartLabelFormatter} from "./formatters/ChartLabelFormatter";
import {ChartPlugin} from "./ChartPlugin";
import {ChartUtils} from "../ChartUtils";
import {ErvuChartV2} from "../ErvuChartV2";
@AnalyticalScope(ErvuChartV2) @AnalyticalScope(ErvuChartV2)
export class DoughnutCenterLabelsPlugin extends Behavior implements ChartPlugin { 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') @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[] = []; public formatters: ChartLabelFormatter[] = [];
beforeDatasetsDraw(chart: Chart, args?: { cancellable: true }, options?: any): void { 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; return;
} }
@ -101,18 +108,15 @@ export class DoughnutCenterLabelsPlugin extends Behavior implements ChartPlugin
formatter.format(label, labels, index); 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) { if (label.font) {
label.font.family = label.font.family = label.font.family ? label.font.family : this.defaultFont.family;
label.font.family ? label.font.family : DoughnutCenterLabelsPlugin.DEFAULTS.font.family; label.font.weight = label.font.weight ? label.font.weight : this.defaultFont.weight;
label.font.weight = label.font.size = label.font.size ? label.font.size : this.defaultFont.size;
label.font.weight ? label.font.weight : DoughnutCenterLabelsPlugin.DEFAULTS.font.weight;
label.font.size =
label.font.size ? label.font.size : DoughnutCenterLabelsPlugin.DEFAULTS.font.size;
} }
else { else {
label.font = DoughnutCenterLabelsPlugin.DEFAULTS.font label.font = this.defaultFont;
} }
}); });
} }