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/label animate config #3206

Merged
merged 3 commits into from
Sep 9, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vchart",
"comment": " fix: `animationUpdate` should also control labels animation",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
8 changes: 5 additions & 3 deletions packages/vchart/src/component/label/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface ILabelFormatMethodContext {
series?: ISeries;
}

export interface ILabelSpec extends IComponentSpec {
export interface ILabelSpec extends IComponentSpec, ILabelAnimationSpec {
/** 默认不显示标签 */
visible?: boolean;
/**
Expand Down Expand Up @@ -46,8 +46,6 @@ export interface ILabelSpec extends IComponentSpec {
overlap?: BaseLabelAttrs['overlap'];
/** 标签智能反色配置 */
smartInvert?: BaseLabelAttrs['smartInvert'];
/** 动画配置 */
animation?: BaseLabelAttrs['animation'];
/**
* 堆积数据过滤类型
* @since 1.12.0
Expand Down Expand Up @@ -79,6 +77,10 @@ export interface ILabelSpec extends IComponentSpec {
syncState?: boolean;
}

export type ILabelAnimationSpec = Pick<
BaseLabelAttrs,
'animation' | 'animationEnter' | 'animationUpdate' | 'animationExit'
>;
export type IMultiLabelSpec<T extends Omit<ILabelSpec, 'position'>> = T | T[];

type LabelStateStyle<T> = {
Expand Down
18 changes: 15 additions & 3 deletions packages/vchart/src/series/base/base-series-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class BaseSeriesSpecTransformer<T extends ISeriesSpec, K> extends BaseMod
markName: SeriesMarkNameEnum,
labelSpecKey: keyof T = 'label' as any,
styleHandlerName: keyof V = 'initLabelMarkStyle',
hasAnimation?: boolean,
hasAnimation: boolean = true,
head?: boolean
): void {
if (!spec) {
Expand All @@ -100,12 +100,24 @@ export class BaseSeriesSpecTransformer<T extends ISeriesSpec, K> extends BaseMod
labels.forEach(labelSpec => {
if (labelSpec && labelSpec.visible) {
// animation config priority: option.animation > spec.animation > spec.label.animation
const animationEnabled = this._option?.animation ?? spec.animation ?? labelSpec.animation ?? true;
const {
animation = true,
animationUpdate: labelAnimationUpdate = true,
animationEnter: labelAnimationEnter = true,
animationExit: labelAnimationExit = true
} = labelSpec;
const { animationUpdate = true, animationEnter = true, animationExit = true } = spec as any;
const animationEnabled = this._option?.animation ?? spec.animation ?? labelSpec.animation;
const labelAnimationEnabled = !!animationEnabled && !!hasAnimation;

this.addLabelSpec(
markName,
{
...labelSpec,
animation: animationEnabled && hasAnimation,
animation: labelAnimationEnabled ? animation : false,
animationUpdate: labelAnimationEnabled && animationUpdate && labelAnimationUpdate ? animationUpdate : false,
animationEnter: labelAnimationEnabled && animationEnter && labelAnimationEnter ? animationEnter : false,
animationExit: labelAnimationEnabled && animationEnter && labelAnimationExit ? animationExit : false,
getStyleHandler: (series: V) => (series[styleHandlerName] as any)?.bind(series)
} as TransformedLabelSpec,
head
Expand Down
Loading