Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support inside-middle label position in area chart #3545

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 117 additions & 117 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

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
8 changes: 4 additions & 4 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"@visactor/vchart-theme": "~1.6.6",
"@visactor/vmind": "1.2.4-alpha.5",
"@visactor/vutils": "~0.19.2",
"@visactor/vrender": "0.21.1",
"@visactor/vrender-kits": "0.21.1",
"@visactor/vgrammar": "0.15.0",
"@visactor/vrender": "0.21.2",
"@visactor/vrender-kits": "0.21.2",
"@visactor/vgrammar": "0.15.1",
"@visactor/vtable": "1.12.0",
"@visactor/vtable-editors": "1.12.0",
"@visactor/vtable-gantt": "1.12.0",
Expand Down Expand Up @@ -59,4 +59,4 @@
"react-device-detect": "^2.2.2",
"minimist": "1.2.8"
}
}
}
8 changes: 4 additions & 4 deletions packages/openinula-vchart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"dependencies": {
"@visactor/vchart": "workspace:1.13.0",
"@visactor/vutils": "~0.19.2",
"@visactor/vrender-core": "0.21.1",
"@visactor/vrender-kits": "0.21.1",
"@visactor/vgrammar-core": "0.15.0",
"@visactor/vrender-core": "0.21.2",
"@visactor/vrender-kits": "0.21.2",
"@visactor/vgrammar-core": "0.15.1",
"react-is": "^18.2.0"
},
"devDependencies": {
Expand Down Expand Up @@ -79,4 +79,4 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
}
8 changes: 4 additions & 4 deletions packages/react-vchart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"dependencies": {
"@visactor/vchart": "workspace:1.13.0",
"@visactor/vutils": "~0.19.2",
"@visactor/vrender-core": "0.21.1",
"@visactor/vrender-kits": "0.21.1",
"@visactor/vgrammar-core": "0.15.0",
"@visactor/vrender-core": "0.21.2",
"@visactor/vrender-kits": "0.21.2",
"@visactor/vgrammar-core": "0.15.1",
"react-is": "^18.2.0"
},
"devDependencies": {
Expand Down Expand Up @@ -83,4 +83,4 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
}
10 changes: 5 additions & 5 deletions packages/vchart-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"start": "ts-node __tests__/runtime/browser/scripts/initVite.ts && vite serve __tests__/runtime/browser"
},
"dependencies": {
"@visactor/vrender-core": "0.21.1",
"@visactor/vrender-kits": "0.21.1",
"@visactor/vrender-components": "0.21.1",
"@visactor/vgrammar-core": "0.15.0",
"@visactor/vrender-core": "0.21.2",
"@visactor/vrender-kits": "0.21.2",
"@visactor/vrender-components": "0.21.2",
"@visactor/vgrammar-core": "0.15.1",
"@visactor/vutils": "~0.19.2",
"@visactor/vdataset": "~0.19.2",
"@visactor/vchart": "workspace:1.13.0"
Expand Down Expand Up @@ -60,4 +60,4 @@
"registry": "https://registry.npmjs.org/"
},
"license": "MIT"
}
}
4 changes: 2 additions & 2 deletions packages/vchart/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"comment": "feat: support max height of tooltip, by percent value , close #2675\n\n"
},
{
"comment": "fix: upgrade vrender to 0.21.1, vgrammar to 0.15.0\n\n"
"comment": "fix: upgrade vrender to 0.21.2, vgrammar to 0.15.1\n\n"
}
]
}
Expand Down Expand Up @@ -3489,4 +3489,4 @@
}
}
]
}
}
24 changes: 12 additions & 12 deletions packages/vchart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,21 @@
"@visactor/vutils": "~0.19.2",
"@visactor/vdataset": "~0.19.2",
"@visactor/vscale": "~0.19.2",
"@visactor/vrender-core": "0.21.1",
"@visactor/vrender-kits": "0.21.1",
"@visactor/vrender-components": "0.21.1",
"@visactor/vgrammar-core": "0.15.0",
"@visactor/vgrammar-projection": "0.15.0",
"@visactor/vgrammar-wordcloud": "0.15.0",
"@visactor/vgrammar-wordcloud-shape": "0.15.0",
"@visactor/vgrammar-hierarchy": "0.15.0",
"@visactor/vgrammar-sankey": "0.15.0",
"@visactor/vgrammar-venn": "0.15.0",
"@visactor/vgrammar-util": "0.15.0",
"@visactor/vrender-core": "0.21.2",
"@visactor/vrender-kits": "0.21.2",
"@visactor/vrender-components": "0.21.2",
"@visactor/vgrammar-core": "0.15.1",
"@visactor/vgrammar-projection": "0.15.1",
"@visactor/vgrammar-wordcloud": "0.15.1",
"@visactor/vgrammar-wordcloud-shape": "0.15.1",
"@visactor/vgrammar-hierarchy": "0.15.1",
"@visactor/vgrammar-sankey": "0.15.1",
"@visactor/vgrammar-venn": "0.15.1",
"@visactor/vgrammar-util": "0.15.1",
"@visactor/vutils-extension": "workspace:1.13.0"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
}
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
6 changes: 3 additions & 3 deletions packages/vstory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
},
"dependencies": {
"@visactor/vchart": "workspace:1.11.0",
"@visactor/vrender-core": "0.21.1",
"@visactor/vrender-kits": "0.21.1",
"@visactor/vrender-components": "0.21.1",
"@visactor/vrender-core": "0.21.2",
"@visactor/vrender-kits": "0.21.2",
"@visactor/vrender-components": "0.21.2",
"@visactor/vutils": "~0.19.2"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions tools/story-player/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
"vite": "3.2.6"
},
"dependencies": {
"@visactor/vrender-core": "0.21.1",
"@visactor/vrender-kits": "0.21.1",
"@visactor/vrender-core": "0.21.2",
"@visactor/vrender-kits": "0.21.2",
"@visactor/vchart": "workspace:1.13.0",
"@visactor/vrender": "0.21.1",
"@visactor/vrender": "0.21.2",
"@visactor/vutils": "~0.19.2"
}
}
}
Loading