Skip to content

Commit 37c75ff

Browse files
authored
Merge pull request #4291 from VisActor/fix/hide-tooltip-when-setdimensionIndex-match-empty
fix: fix the issue of setDimensionIndex
2 parents 6efcd0c + 2f34af1 commit 37c75ff

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,12 +1396,18 @@ export class BaseChart<T extends IChartSpec> extends CompilableBase implements I
13961396
});
13971397
const isUnableValue =
13981398
isNil(value) || !dimensionInfo || dimensionInfo.every(d => isDiscrete(d.axis.getScale().type) && isNil(d.index));
1399+
1400+
const isUnableTooltip =
1401+
// 如果数据本身不可用
1402+
isUnableValue ||
1403+
// 或者数据为空
1404+
dimensionInfo.every(d => isDiscrete(d.axis.getScale().type) && d.data.every(_data => _data.datum.length === 0));
13991405
// tooltip
14001406
if (opt.tooltip !== false) {
14011407
const tooltip = this.getComponentsByType(ComponentTypeEnum.tooltip)[0] as unknown as ITooltip;
14021408

14031409
if (tooltip?.getVisible()) {
1404-
if (isUnableValue) {
1410+
if (isUnableValue || isUnableTooltip) {
14051411
(<any>tooltip).hideTooltip?.();
14061412
} else {
14071413
const dataFilter: { [key: string]: any } = {};
@@ -1431,6 +1437,27 @@ export class BaseChart<T extends IChartSpec> extends CompilableBase implements I
14311437
}
14321438
}
14331439

1440+
showCrosshair(cb: (axis: IAxis) => false | string | number) {
1441+
const crosshair =
1442+
this.getComponentsByType(ComponentTypeEnum.cartesianCrosshair)[0] ??
1443+
this.getComponentsByType(ComponentTypeEnum.polarCrosshair)[0];
1444+
if (!crosshair) {
1445+
return;
1446+
}
1447+
const axes = this.getComponentsByKey('axes') as IAxis[];
1448+
const dimInfo: { axis: IAxis; value: string | number }[] = [];
1449+
axes.forEach(axis => {
1450+
const value = cb(axis);
1451+
if (value !== false) {
1452+
dimInfo.push({
1453+
axis,
1454+
value
1455+
});
1456+
}
1457+
});
1458+
(crosshair as ICrossHair).showCrosshair(dimInfo);
1459+
}
1460+
14341461
getColorScheme() {
14351462
return this._option.getTheme?.('colorScheme');
14361463
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import type { DataView } from '@visactor/vdataset';
3232
import type { IGlobalScale } from '../../scale/interface';
3333
import type { IMorphConfig } from '../../animation/spec';
3434
import type { IMarkGraphic } from '../../mark/interface/common';
35+
import type { IAxis } from '../../component/axis/interface';
3536

3637
export type DimensionIndexOption = {
3738
filter?: (cmp: IComponent) => boolean;
@@ -217,6 +218,12 @@ export interface IChart extends ICompilable {
217218
getSeriesData: (id: StringOrNumber | undefined, index: number | undefined) => DataView | undefined;
218219
// setDimensionIndex
219220
setDimensionIndex: (value: StringOrNumber, opt: DimensionIndexOption) => void;
221+
/**
222+
* 显示交叉线
223+
* @since 2.0.9
224+
*/
225+
showCrosshair: (cb: (axis: IAxis) => false | string | number) => void;
226+
220227
/**
221228
* 根据数据筛选图元
222229
* @since 1.13.9

packages/vchart/src/core/vchart.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,10 @@ export class VChart implements IVChart {
19081908
return this._chart?.setDimensionIndex(value, opt);
19091909
}
19101910

1911+
showCrosshair(cb: (axis: IAxis) => false | string | number) {
1912+
this._chart?.showCrosshair(cb);
1913+
}
1914+
19111915
/** 停止正在进行的所有动画 */
19121916
stopAnimation() {
19131917
(this.getStage() as any)?.stopAnimation(true);

0 commit comments

Comments
 (0)