diff --git a/common/changes/@visactor/vchart/feat-support-componentShowContent-in-initOption_2025-12-02-08-02.json b/common/changes/@visactor/vchart/feat-support-componentShowContent-in-initOption_2025-12-02-08-02.json new file mode 100644 index 0000000000..c4e783f75f --- /dev/null +++ b/common/changes/@visactor/vchart/feat-support-componentShowContent-in-initOption_2025-12-02-08-02.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "feat: support componentShowContent in initOption\n\n", + "type": "none", + "packageName": "@visactor/vchart" + } + ], + "packageName": "@visactor/vchart", + "email": "lixuef1313@163.com" +} \ No newline at end of file diff --git a/packages/vchart/src/chart/base/base-chart.ts b/packages/vchart/src/chart/base/base-chart.ts index 1f3149189e..cc4d9638c2 100644 --- a/packages/vchart/src/chart/base/base-chart.ts +++ b/packages/vchart/src/chart/base/base-chart.ts @@ -220,6 +220,7 @@ export class BaseChart extends CompilableBase implements I globalScale: this._globalScale, onError: this._option?.onError, disableTriggerEvent: this._option?.disableTriggerEvent === true, + componentShowContent: this._option?.componentShowContent, getSeriesData: this._chartData.getSeriesData.bind(this._chartData), // @ts-ignore dispatchEvent: (eType, params) => this._option.globalInstance.event.emit(eType, params) diff --git a/packages/vchart/src/chart/interface/common.ts b/packages/vchart/src/chart/interface/common.ts index 231e4a4822..0759c74f05 100644 --- a/packages/vchart/src/chart/interface/common.ts +++ b/packages/vchart/src/chart/interface/common.ts @@ -4,7 +4,7 @@ import type { IModelOption, IModelSpecInfo } from '../../model/interface'; import type { IBoundsLike } from '@visactor/vutils'; import type { ISeriesSpecInfo } from '../../series/interface'; import type { IRegionSpecInfo } from '../../region/interface'; -import type { IPerformanceHook } from '../../typings'; +import type { IPerformanceHook, TooltipActiveType } from '../../typings'; export interface IChartOption extends Omit< @@ -29,6 +29,21 @@ export interface IChartOption * 是否关闭交互效果 */ disableTriggerEvent?: boolean; + + /** + * 组件内容展示配置 + * @since 2.0.11 + */ + componentShowContent?: { + /** + * tooltip 是否关闭内容展示 + * @default false + */ + tooltip?: boolean | Partial>; + // crosshair 组件是否展示 + crosshair?: boolean; + }; + /** * 性能相关的钩子 */ diff --git a/packages/vchart/src/component/crosshair/base.ts b/packages/vchart/src/component/crosshair/base.ts index fc9716d7bc..4f3b91dbd4 100644 --- a/packages/vchart/src/component/crosshair/base.ts +++ b/packages/vchart/src/component/crosshair/base.ts @@ -247,6 +247,11 @@ export abstract class BaseCrossHair implements ITooltip { isClick: boolean, useCache?: boolean ): boolean => { + if (this._option?.componentShowContent) { + // 全局关闭 tooltip + if (this._option.componentShowContent.tooltip === false) { + return false; + } + // 单独关闭 tooltip + if ( + isObject(this._option.componentShowContent.tooltip) && + this._option.componentShowContent.tooltip[activeType] === false + ) { + return false; + } + } + const processor = this.processor[activeType]; // 判断是否应该触发 tooltip if (!processor.shouldHandleTooltip(params, mouseEventData.tooltipInfo[activeType])) { diff --git a/packages/vchart/src/core/vchart.ts b/packages/vchart/src/core/vchart.ts index ebcc222ce1..89a545d361 100644 --- a/packages/vchart/src/core/vchart.ts +++ b/packages/vchart/src/core/vchart.ts @@ -2247,7 +2247,8 @@ export class VChart implements IVChart { layout: this._option.layout, onError: this._onError, - disableTriggerEvent: this._option.disableTriggerEvent === true + disableTriggerEvent: this._option.disableTriggerEvent === true, + componentShowContent: this._option.componentShowContent }; } } diff --git a/packages/vchart/src/model/interface.ts b/packages/vchart/src/model/interface.ts index f09072e200..b58520721f 100644 --- a/packages/vchart/src/model/interface.ts +++ b/packages/vchart/src/model/interface.ts @@ -186,6 +186,21 @@ export interface IModelOption extends ICompilableInitOption { * 是否关闭交互效果 */ disableTriggerEvent?: boolean; + + /** + * 组件内容展示配置 + * @since 2.0.11 + */ + componentShowContent?: { + /** + * tooltip 是否关闭内容展示 + * @default false + */ + tooltip?: boolean | Partial>; + // crosshair 组件是否展示 + crosshair?: boolean; + }; + getDimensionInfo?: (chart: IChart | undefined, pos: ILayoutPoint, isTooltip?: boolean) => IDimensionInfo[] | null; getDimensionInfoByValue?: (axis: IAxis, value: any) => IDimensionInfo | null; getRectByDimensionData?: (dimensionData: IDimensionData, layoutStartPoint: ILayoutPoint) => any; diff --git a/packages/vchart/src/typings/spec/common.ts b/packages/vchart/src/typings/spec/common.ts index 14364e5600..03f904d6dd 100644 --- a/packages/vchart/src/typings/spec/common.ts +++ b/packages/vchart/src/typings/spec/common.ts @@ -54,6 +54,7 @@ import type { IColor, ICustomPath2D, IGraphic, IOption3D, IRichTextCharacter } f import type { ICommonAxisSpec } from '../../component/axis/interface'; import type { IMediaQuerySpec } from './media-query'; import type { IModelSpec } from '../../model/interface'; +import type { TooltipActiveType } from '../tooltip/handler'; export type IChartPadding = ILayoutOrientPadding | number; @@ -107,6 +108,21 @@ export interface IInitOption extends Omit { * @default false */ disableTriggerEvent?: boolean; + + /** + * 组件内容展示配置 + * @since 2.0.11 + */ + componentShowContent?: { + /** + * tooltip 是否关闭内容展示 + * @default false + */ + tooltip?: boolean | Partial>; + // crosshair 组件是否展示 + crosshair?: boolean; + }; + /** * 当自动响应容器resize 事件时,触发resize 的间隔时长,单位毫秒 * @since 1.12.5