Skip to content
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,11 @@
{
"changes": [
{
"comment": "feat: support componentShowContent in initOption\n\n",
"type": "none",
"packageName": "@visactor/vchart"
}
],
"packageName": "@visactor/vchart",
"email": "lixuef1313@163.com"
}
1 change: 1 addition & 0 deletions packages/vchart/src/chart/base/base-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class BaseChart<T extends IChartSpec> 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)
Expand Down
17 changes: 16 additions & 1 deletion packages/vchart/src/chart/interface/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand All @@ -29,6 +29,21 @@ export interface IChartOption
* 是否关闭交互效果
*/
disableTriggerEvent?: boolean;

/**
* 组件内容展示配置
* @since 2.0.11
*/
componentShowContent?: {
/**
* tooltip 是否关闭内容展示
* @default false
*/
tooltip?: boolean | Partial<Record<TooltipActiveType, boolean>>;
// crosshair 组件是否展示
crosshair?: boolean;
};

/**
* 性能相关的钩子
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/vchart/src/component/crosshair/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ export abstract class BaseCrossHair<T extends ICartesianCrosshairSpec | IPolarCr
}

private _registerEvent(eventName: EventType | EventType[], isOut?: boolean, click?: boolean) {
// 关闭还是正常关闭
if (!isOut && this._option.componentShowContent?.crosshair === false) {
return;
}

const handler = isOut ? this._handleOutEvent : click ? this._handleClickInEvent : this._handleHoverInEvent;
const cfg = isOut ? { level: Event_Bubble_Level.chart } : { source: Event_Source_Type.chart };

Expand Down
14 changes: 14 additions & 0 deletions packages/vchart/src/component/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,20 @@ export class Tooltip extends BaseComponent<any> 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])) {
Expand Down
3 changes: 2 additions & 1 deletion packages/vchart/src/core/vchart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
}
Expand Down
15 changes: 15 additions & 0 deletions packages/vchart/src/model/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ export interface IModelOption extends ICompilableInitOption {
* 是否关闭交互效果
*/
disableTriggerEvent?: boolean;

/**
* 组件内容展示配置
* @since 2.0.11
*/
componentShowContent?: {
/**
* tooltip 是否关闭内容展示
* @default false
*/
tooltip?: boolean | Partial<Record<TooltipActiveType, boolean>>;
// 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;
Expand Down
16 changes: 16 additions & 0 deletions packages/vchart/src/typings/spec/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -107,6 +108,21 @@ export interface IInitOption extends Omit<IRenderOption, 'pluginList'> {
* @default false
*/
disableTriggerEvent?: boolean;

/**
* 组件内容展示配置
* @since 2.0.11
*/
componentShowContent?: {
/**
* tooltip 是否关闭内容展示
* @default false
*/
tooltip?: boolean | Partial<Record<TooltipActiveType, boolean>>;
// crosshair 组件是否展示
crosshair?: boolean;
};

/**
* 当自动响应容器resize 事件时,触发resize 的间隔时长,单位毫秒
* @since 1.12.5
Expand Down
Loading