Skip to content

Commit

Permalink
feat: support inside-middle label position in area chart
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoluoHe committed Dec 10, 2024
1 parent 6e1b3bd commit 88eef5b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/assets/option/en/series/area.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Optional string values:
- `'bottom-right'`
- `'bottom-left'`
- `'center'`
- `'inside-middle'` ( Supported since `1.13.1`

{{ use: component-label(
prefix = '#' + ${prefix},
Expand Down
1 change: 1 addition & 0 deletions docs/assets/option/zh/series/area.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ label: {
- `'bottom-right'`
- `'bottom-left'`
- `'center'`
- `'inside-middle'``1.13.1` 版本开始支持)

{{ use: component-label(
prefix = '#' + ${prefix},
Expand Down
12 changes: 7 additions & 5 deletions packages/vchart/src/series/area/area-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ export class AreaSeriesSpecTransformer<
protected _supportStack: boolean = true;

protected _transformLabelSpec(spec: T): void {
super._transformLabelSpec(spec);
const isPointVisible = spec.point?.visible !== false && spec.point?.style?.visible !== false;

this._addMarkLabelSpec(spec, (spec: any) => {
const isAreaMiddle = spec.position === 'inside-middle';
return !isPointVisible || isAreaMiddle ? SeriesMarkNameEnum.area : SeriesMarkNameEnum.point;
});

this._addMarkLabelSpec<AreaSeries>(
spec,
SeriesMarkNameEnum.area,
Expand All @@ -23,10 +29,6 @@ export class AreaSeriesSpecTransformer<
undefined,
true
);
const isPointVisible = spec.point?.visible !== false && spec.point?.style?.visible !== false;
if (!isPointVisible) {
this._addMarkLabelSpec(spec, SeriesMarkNameEnum.area);
}
}

protected _transformSpecAfterMergingTheme(spec: T, chartSpec: any, chartSpecInfo?: IChartSpecInfo) {
Expand Down
17 changes: 16 additions & 1 deletion packages/vchart/src/series/area/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,23 @@ export interface IAreaSeriesSpec
[SeriesMarkNameEnum.area]?: IMarkSpec<IAreaMarkSpec>;
/**
* 标签配置
* @since 1.13.1 新增支持 inside-middle 标签位置
*/
[SeriesMarkNameEnum.label]?: IMultiLabelSpec<ILineLikeLabelSpec>;
[SeriesMarkNameEnum.label]?: IMultiLabelSpec<
Omit<ILineLikeLabelSpec, 'position'> & {
position:
| 'top'
| 'bottom'
| 'left'
| 'right'
| 'top-right'
| 'top-left'
| 'bottom-right'
| 'bottom-left'
| 'center'
| 'inside-middle';
}
>;
/**
* 面积图元标签配置
* @since 1.7.0
Expand Down
6 changes: 3 additions & 3 deletions packages/vchart/src/series/base/base-series-transformer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isBoolean, isNil, isObject } from '@visactor/vutils';
import { isBoolean, isFunction, isNil, isObject } from '@visactor/vutils';
import type { IChartSpecInfo } from '../../chart/interface';
import type { ILabelSpec, TransformedLabelSpec } from '../../component/label';
import { BaseModelSpecTransformer } from '../../model/base-model-transformer';
Expand Down Expand Up @@ -87,7 +87,7 @@ export class BaseSeriesSpecTransformer<T extends ISeriesSpec, K> extends BaseMod

protected _addMarkLabelSpec<V extends ISeries = ISeries>(
spec: T,
markName: SeriesMarkNameEnum,
markName: SeriesMarkNameEnum | ((spec: ILabelSpec) => SeriesMarkNameEnum),
labelSpecKey: keyof T = 'label' as any,
styleHandlerName: keyof V = 'initLabelMarkStyle',
hasAnimation: boolean = true,
Expand All @@ -111,7 +111,7 @@ export class BaseSeriesSpecTransformer<T extends ISeriesSpec, K> extends BaseMod
const labelAnimationEnabled = !!animationEnabled && !!hasAnimation;

this.addLabelSpec(
markName,
isFunction(markName) ? markName(labelSpec) : markName,
{
...labelSpec,
animation: labelAnimationEnabled ? animation : false,
Expand Down

0 comments on commit 88eef5b

Please sign in to comment.