SUPPORT-8931: 1) Added calc fix font size 2) Check min fix font size
This commit is contained in:
parent
87126cb65a
commit
c7ca5b36cd
1 changed files with 16 additions and 6 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import {
|
||||
AdvancedProperty,
|
||||
AnalyticalScope,
|
||||
Behavior,
|
||||
ChartFontFamily,
|
||||
|
|
@ -18,9 +19,12 @@ export class BarDataLabelChartPlugin extends Behavior implements ChartPlugin {
|
|||
|
||||
public labelAxis = 'y';
|
||||
|
||||
public weight: number = 500;
|
||||
public size: number = 12;
|
||||
public family: ChartFontFamily = ChartFontFamily.SANS_SERIF;
|
||||
@AdvancedProperty()
|
||||
public defaultFontFamily: string = ChartFontFamily.SANS_SERIF;
|
||||
@AdvancedProperty()
|
||||
public defaultFontWeight: string = '500';
|
||||
@AdvancedProperty()
|
||||
public defaultFontSize: number = 14;
|
||||
|
||||
public useStaticColor: boolean = true;
|
||||
@Visible('useStaticColor == true')
|
||||
|
|
@ -31,11 +35,17 @@ export class BarDataLabelChartPlugin extends Behavior implements ChartPlugin {
|
|||
afterDatasetDraw(chart: Chart, args: { index: number; meta: ChartMeta }): void {
|
||||
let ctx = chart.ctx;
|
||||
let data = chart.data.datasets[args.index];
|
||||
|
||||
const fixRatio = window.devicePixelRatio;
|
||||
const textFontSize = () => {
|
||||
return fixRatio > 1 ? Math.round(this.defaultFontSize / fixRatio) : this.defaultFontSize;
|
||||
}
|
||||
|
||||
args.meta.data.forEach((datapoint: any, i) => {
|
||||
ctx.font = ChartUtils.getFont({
|
||||
family: this.family,
|
||||
weight: String(this.weight),
|
||||
size: this.size
|
||||
family: this.defaultFontFamily,
|
||||
weight: String(this.defaultFontWeight),
|
||||
size: textFontSize()
|
||||
});
|
||||
ctx.textAlign = 'center';
|
||||
ctx.fillStyle = this.useStaticColor ? this.color : datapoint.options.backgroundColor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue