Skip to content

Feat/theme support tooltip crosshair trigger #3958

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

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": "feat: support tooltip.trigger and crosshair.trigger in theme",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
5 changes: 5 additions & 0 deletions packages/vchart/src/component/crosshair/interface/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ export interface ICrosshairTheme extends ICommonCrosshairSpec {
yField?: Partial<ICartesianCrosshairSpec['yField']>;
categoryField?: Partial<IPolarCrosshairSpec['categoryField']>;
valueField?: Partial<IPolarCrosshairSpec['valueField']>;
/**
* crosshair trigger配置
*/
trigger?: ICommonCrosshairSpec['trigger'];
triggerOff?: ICommonCrosshairSpec['triggerOff'];
}
16 changes: 11 additions & 5 deletions packages/vchart/src/component/crosshair/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export function getDatumByValue(data: Datum[], value: number, startField: string

export const getCartesianCrosshairTheme = (chartTheme: ITheme, chartSpec: any): ICrosshairTheme => {
const axes: ICartesianAxisCommonSpec[] = array(chartSpec.axes ?? []);
const { bandField, linearField, xField, yField } =
getComponentThemeFromOption(ComponentTypeEnum.crosshair, chartTheme) ?? {};
const crosshairTheme = getComponentThemeFromOption(ComponentTypeEnum.crosshair, chartTheme) ?? {};
const { bandField, linearField, xField, yField, trigger, triggerOff } = crosshairTheme;

const xAxis = axes.find(axis => isXAxis(axis.orient));
let newXField;
Expand All @@ -93,15 +93,18 @@ export const getCartesianCrosshairTheme = (chartTheme: ITheme, chartSpec: any):
newYField = yField;
}

// 返回主题配置,包括交互相关配置
return {
xField: newXField,
yField: newYField
yField: newYField,
trigger,
triggerOff
};
};

export const getPolarCrosshairTheme = (chartTheme: ITheme, chartSpec: any): ICrosshairTheme => {
const axes: IPolarAxisCommonSpec[] = array(chartSpec.axes ?? []);
const { bandField, linearField, categoryField, valueField } =
const { bandField, linearField, categoryField, valueField, trigger, triggerOff } =
getComponentThemeFromOption(ComponentTypeEnum.crosshair, chartTheme) ?? {};

const angleAxis = axes.find(axis => axis.orient === 'angle');
Expand All @@ -120,8 +123,11 @@ export const getPolarCrosshairTheme = (chartTheme: ITheme, chartSpec: any): ICro
newRadiusField = valueField;
}

// 返回主题配置,包括交互相关配置
return {
categoryField: newAngleField,
valueField: newRadiusField
valueField: newRadiusField,
trigger,
triggerOff
};
};
11 changes: 11 additions & 0 deletions packages/vchart/src/component/tooltip/interface/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ITextAttribute } from '@visactor/vrender-core';
import type { ILayoutNumber, ITooltipShapePattern, StringOrNumber, TextAlign, TextBaseLine } from '../../../typings';
import type { Padding } from '@visactor/vrender-components';
import type { ITokenKey } from '../../../theme/token/interface';
import type { ITooltipSpec } from './spec';

export interface ITooltipTextTheme<ColorType = string> {
/**
Expand Down Expand Up @@ -126,4 +127,14 @@ export interface ITooltipTheme<ColorType = string> {
* @since 1.11.5
*/
align?: 'left' | 'right';
/**
* tooltip触发方式
* (*会影响自定义handler)
*/
trigger?: ITooltipSpec['trigger'];
/**
* 隐藏tooltip的触发方式(目前仅支持和trigger一致的设置以及none)
* (*会影响自定义handler)
*/
triggerOff?: ITooltipSpec['triggerOff'];
}
7 changes: 7 additions & 0 deletions packages/vchart/src/component/tooltip/tooltip-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ export class TooltipSpecTransformer extends BaseComponentSpecTransformer<any> {

protected _initTheme(spec: any, chartSpec: any): { spec: any; theme: any } {
const { spec: newSpec, theme } = super._initTheme(spec, chartSpec);

// 合并样式和配置
newSpec.style = mergeSpec({}, this._theme, newSpec.style);
newSpec.offset = mergeSpec({}, theme.offset, spec.offset);
newSpec.transitionDuration = spec.transitionDuration ?? theme.transitionDuration;

// 合并交互相关配置
newSpec.trigger = spec.trigger ?? theme.trigger;
newSpec.triggerOff = spec.triggerOff ?? theme.triggerOff;

return { spec: newSpec, theme };
}

Expand Down