refactor(视图): 优化视图的默认标签配置

This commit is contained in:
wisonic-s 2024-02-19 13:01:49 +08:00
parent 95dbe4125a
commit 2e88d3cb42
7 changed files with 62 additions and 1 deletions

View File

@ -532,7 +532,7 @@ declare interface ChartLabelAttr {
/**
* 标签格式化设置
*/
labelFormatter: BaseFormatter
labelFormatter: Partial<BaseFormatter>
/**
* 标签保留小数位数
*/

View File

@ -146,6 +146,20 @@ export class Liquid extends G2PlotChartView<LiquidOptions, G2Liquid> {
}
}
setupDefaultOptions(chart: ChartObj): ChartObj {
chart.customAttr.label = {
...chart.customAttr.label,
fontSize: 12,
show: true,
labelFormatter: {
type: 'percent',
thousandSeparator: true,
decimalCount: 2
}
}
return chart
}
protected setupOptions(chart: Chart, options: LiquidOptions): LiquidOptions {
return flow(this.configTheme, this.configMisc, this.configLabel)(chart, options)
}

View File

@ -130,6 +130,10 @@ export class Funnel extends G2PlotChartView<FunnelOptions, G2Funnel> {
if (!['left', 'middle', 'right'].includes(label.position)) {
label.position = 'middle'
}
customAttr.label = {
...label,
show: true
}
return chart
}

View File

@ -248,6 +248,20 @@ export class Gauge extends G2PlotChartView<GaugeOptions, G2Gauge> {
return { ...options, statistic }
}
setupDefaultOptions(chart: ChartObj): ChartObj {
chart.customAttr.label = {
...chart.customAttr.label,
show: true,
labelFormatter: {
type: 'value',
thousandSeparator: true,
decimalCount: 0,
unit: 1
}
}
return chart
}
protected setupOptions(chart: Chart, options: GaugeOptions, ...extra: any[]): GaugeOptions {
return flow(
this.configTheme,

View File

@ -199,6 +199,20 @@ export class Treemap extends G2PlotChartView<TreemapOptions, G2Treemap> {
}
return { ...options, label }
}
setupDefaultOptions(chart: ChartObj): ChartObj {
const customAttr = chart.customAttr
const { label } = customAttr
customAttr.label = {
...label,
show: true,
showDimension: true,
showProportion: true,
reserveDecimalCount: 2
}
return chart
}
protected setupOptions(chart: Chart, options: TreemapOptions): TreemapOptions {
return flow(
this.configTheme,

View File

@ -116,6 +116,7 @@ export class Pie extends G2PlotChartView<PieOptions, G2Pie> {
}
const label = {
type: labelAttr.position === 'outer' ? 'spider' : labelAttr.position,
layout: [{ type: 'limit-in-plot' }],
autoRotate: false,
style: {
fill: labelAttr.color,
@ -222,6 +223,13 @@ export class Pie extends G2PlotChartView<PieOptions, G2Pie> {
if (!['inner', 'outer'].includes(label.position)) {
label.position = 'outer'
}
customAttr.label = {
...label,
show: true,
showDimension: true,
showProportion: true,
reserveDecimalCount: 2
}
return chart
}

View File

@ -208,6 +208,13 @@ export class Rose extends G2PlotChartView<RoseOptions, G2Rose> {
if (!['inner', 'outer'].includes(label.position)) {
label.position = 'outer'
}
customAttr.label = {
...label,
show: true,
showDimension: true,
showProportion: true,
reserveDecimalCount: 2
}
return chart
}