Skip to content

Commit 81ea1ff

Browse files
authored
Merge pull request #4334 from VisActor/feat/support-componentShowContent-in-initOption
feat: support componentShowContent in initOption
2 parents 9d01bce + 4d47805 commit 81ea1ff

File tree

8 files changed

+80
-2
lines changed

8 files changed

+80
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "feat: support componentShowContent in initOption\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vchart"
7+
}
8+
],
9+
"packageName": "@visactor/vchart",
10+
"email": "[email protected]"
11+
}

packages/vchart/src/chart/base/base-chart.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export class BaseChart<T extends IChartSpec> extends CompilableBase implements I
220220
globalScale: this._globalScale,
221221
onError: this._option?.onError,
222222
disableTriggerEvent: this._option?.disableTriggerEvent === true,
223+
componentShowContent: this._option?.componentShowContent,
223224
getSeriesData: this._chartData.getSeriesData.bind(this._chartData),
224225
// @ts-ignore
225226
dispatchEvent: (eType, params) => this._option.globalInstance.event.emit(eType, params)

packages/vchart/src/chart/interface/common.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { IModelOption, IModelSpecInfo } from '../../model/interface';
44
import type { IBoundsLike } from '@visactor/vutils';
55
import type { ISeriesSpecInfo } from '../../series/interface';
66
import type { IRegionSpecInfo } from '../../region/interface';
7-
import type { IPerformanceHook } from '../../typings';
7+
import type { IPerformanceHook, TooltipActiveType } from '../../typings';
88

99
export interface IChartOption
1010
extends Omit<
@@ -29,6 +29,21 @@ export interface IChartOption
2929
* 是否关闭交互效果
3030
*/
3131
disableTriggerEvent?: boolean;
32+
33+
/**
34+
* 组件内容展示配置
35+
* @since 2.0.11
36+
*/
37+
componentShowContent?: {
38+
/**
39+
* tooltip 是否关闭内容展示
40+
* @default false
41+
*/
42+
tooltip?: boolean | Partial<Record<TooltipActiveType, boolean>>;
43+
// crosshair 组件是否展示
44+
crosshair?: boolean;
45+
};
46+
3247
/**
3348
* 性能相关的钩子
3449
*/

packages/vchart/src/component/crosshair/base.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ export abstract class BaseCrossHair<T extends ICartesianCrosshairSpec | IPolarCr
247247
}
248248

249249
private _registerEvent(eventName: EventType | EventType[], isOut?: boolean, click?: boolean) {
250+
// 关闭还是正常关闭
251+
if (!isOut && this._option.componentShowContent?.crosshair === false) {
252+
return;
253+
}
254+
250255
const handler = isOut ? this._handleOutEvent : click ? this._handleClickInEvent : this._handleHoverInEvent;
251256
const cfg = isOut ? { level: Event_Bubble_Level.chart } : { source: Event_Source_Type.chart };
252257

packages/vchart/src/component/tooltip/tooltip.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,20 @@ export class Tooltip extends BaseComponent<any> implements ITooltip {
488488
isClick: boolean,
489489
useCache?: boolean
490490
): boolean => {
491+
if (this._option?.componentShowContent) {
492+
// 全局关闭 tooltip
493+
if (this._option.componentShowContent.tooltip === false) {
494+
return false;
495+
}
496+
// 单独关闭 tooltip
497+
if (
498+
isObject(this._option.componentShowContent.tooltip) &&
499+
this._option.componentShowContent.tooltip[activeType] === false
500+
) {
501+
return false;
502+
}
503+
}
504+
491505
const processor = this.processor[activeType];
492506
// 判断是否应该触发 tooltip
493507
if (!processor.shouldHandleTooltip(params, mouseEventData.tooltipInfo[activeType])) {

packages/vchart/src/core/vchart.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,8 @@ export class VChart implements IVChart {
22472247

22482248
layout: this._option.layout,
22492249
onError: this._onError,
2250-
disableTriggerEvent: this._option.disableTriggerEvent === true
2250+
disableTriggerEvent: this._option.disableTriggerEvent === true,
2251+
componentShowContent: this._option.componentShowContent
22512252
};
22522253
}
22532254
}

packages/vchart/src/model/interface.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,21 @@ export interface IModelOption extends ICompilableInitOption {
186186
* 是否关闭交互效果
187187
*/
188188
disableTriggerEvent?: boolean;
189+
190+
/**
191+
* 组件内容展示配置
192+
* @since 2.0.11
193+
*/
194+
componentShowContent?: {
195+
/**
196+
* tooltip 是否关闭内容展示
197+
* @default false
198+
*/
199+
tooltip?: boolean | Partial<Record<TooltipActiveType, boolean>>;
200+
// crosshair 组件是否展示
201+
crosshair?: boolean;
202+
};
203+
189204
getDimensionInfo?: (chart: IChart | undefined, pos: ILayoutPoint, isTooltip?: boolean) => IDimensionInfo[] | null;
190205
getDimensionInfoByValue?: (axis: IAxis, value: any) => IDimensionInfo | null;
191206
getRectByDimensionData?: (dimensionData: IDimensionData, layoutStartPoint: ILayoutPoint) => any;

packages/vchart/src/typings/spec/common.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import type { IColor, ICustomPath2D, IGraphic, IOption3D, IRichTextCharacter } f
5454
import type { ICommonAxisSpec } from '../../component/axis/interface';
5555
import type { IMediaQuerySpec } from './media-query';
5656
import type { IModelSpec } from '../../model/interface';
57+
import type { TooltipActiveType } from '../tooltip/handler';
5758

5859
export type IChartPadding = ILayoutOrientPadding | number;
5960

@@ -107,6 +108,21 @@ export interface IInitOption extends Omit<IRenderOption, 'pluginList'> {
107108
* @default false
108109
*/
109110
disableTriggerEvent?: boolean;
111+
112+
/**
113+
* 组件内容展示配置
114+
* @since 2.0.11
115+
*/
116+
componentShowContent?: {
117+
/**
118+
* tooltip 是否关闭内容展示
119+
* @default false
120+
*/
121+
tooltip?: boolean | Partial<Record<TooltipActiveType, boolean>>;
122+
// crosshair 组件是否展示
123+
crosshair?: boolean;
124+
};
125+
110126
/**
111127
* 当自动响应容器resize 事件时,触发resize 的间隔时长,单位毫秒
112128
* @since 1.12.5

0 commit comments

Comments
 (0)