SUPPORT-8717: setting default label color
This commit is contained in:
parent
b8f8c9d734
commit
ccdfdd40c8
2 changed files with 31 additions and 27 deletions
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue