Merge branch 'feature/SUPPORT-8717_default_label_color' into develop
This commit is contained in:
commit
4fab653f25
5 changed files with 55 additions and 32 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 {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';
|
||||
|
||||
public formatters: ChartLabelFormatter[] = [];
|
||||
|
||||
@ColorEditor()
|
||||
public defaultColor: string = 'rgb(0, 0, 0)';
|
||||
@AdvancedProperty()
|
||||
public defaultFontFamily: string = ChartFontFamily.SANS_SERIF;
|
||||
@AdvancedProperty()
|
||||
public defaultFontWeight: string = '500';
|
||||
@AdvancedProperty()
|
||||
public defaultFontSize: number = 14;
|
||||
|
||||
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,19 @@ 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.defaultFontFamily;
|
||||
label.font.weight = label.font.weight ? label.font.weight : this.defaultFontWeight;
|
||||
label.font.size = label.font.size ? label.font.size : this.defaultFontSize;
|
||||
}
|
||||
else {
|
||||
label.font = DoughnutCenterLabelsPlugin.DEFAULTS.font
|
||||
label.font = {
|
||||
family: this.defaultFontFamily,
|
||||
weight: this.defaultFontWeight,
|
||||
size: this.defaultFontSize
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
import {
|
||||
ChartLabelModel
|
||||
} from "../../../../../generated/ervu_business_metrics/model/chart/round/label/ChartLabelModel";
|
||||
import {FormatterUtils} from "../../../../formatter/FormatterUtils";
|
||||
import {ChartLabelFormatter} from "./ChartLabelFormatter";
|
||||
|
||||
export class NumberToLocalStringLabelFormatter implements ChartLabelFormatter {
|
||||
format(label: ChartLabelModel, labels?: ChartLabelModel[], index?: number): void {
|
||||
label.text = FormatterUtils.toLocalString(label.text);
|
||||
}
|
||||
}
|
||||
|
|
@ -60,4 +60,11 @@ export class FormatterUtils {
|
|||
return formattedValue;
|
||||
}
|
||||
|
||||
}
|
||||
public static toLocalString(value: string): string {
|
||||
if (!value) {
|
||||
return value;
|
||||
}
|
||||
const numberValue = Number(value);
|
||||
return numberValue ? numberValue.toLocaleString() : value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
import {TextFormatter} from "@webbpm/base-package";
|
||||
import {FormatterUtils} from "./FormatterUtils";
|
||||
|
||||
export class NumberToLocalStringFormatter implements TextFormatter {
|
||||
format(value: string): string {
|
||||
if (!value) {
|
||||
return value;
|
||||
}
|
||||
const numberValue = Number(value);
|
||||
return numberValue ? numberValue.toLocaleString() : value;
|
||||
return FormatterUtils.toLocalString(value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue