Skip to content
Open
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
29 changes: 28 additions & 1 deletion packages/vchart/src/chart/base/base-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1396,12 +1396,18 @@ export class BaseChart<T extends IChartSpec> extends CompilableBase implements I
});
const isUnableValue =
isNil(value) || !dimensionInfo || dimensionInfo.every(d => isDiscrete(d.axis.getScale().type) && isNil(d.index));

const isUnableTooltip =
// 如果数据本身不可用
isUnableValue ||
// 或者数据为空
dimensionInfo.every(d => isDiscrete(d.axis.getScale().type) && d.data.every(_data => _data.datum.length === 0));
// tooltip
if (opt.tooltip !== false) {
const tooltip = this.getComponentsByType(ComponentTypeEnum.tooltip)[0] as unknown as ITooltip;

if (tooltip?.getVisible()) {
if (isUnableValue) {
if (isUnableValue || isUnableTooltip) {
(<any>tooltip).hideTooltip?.();
} else {
const dataFilter: { [key: string]: any } = {};
Expand Down Expand Up @@ -1431,6 +1437,27 @@ export class BaseChart<T extends IChartSpec> extends CompilableBase implements I
}
}

showCrosshair(cb: (axis: IAxis) => false | string | number) {
const crosshair =
this.getComponentsByType(ComponentTypeEnum.cartesianCrosshair)[0] ??
this.getComponentsByType(ComponentTypeEnum.polarCrosshair)[0];
if (!crosshair) {
return;
}
const axes = this.getComponentsByKey('axes') as IAxis[];
const dimInfo: { axis: IAxis; value: string | number }[] = [];
axes.forEach(axis => {
const value = cb(axis);
if (value !== false) {
dimInfo.push({
axis,
value
});
}
});
(crosshair as ICrossHair).showCrosshair(dimInfo);
}

getColorScheme() {
return this._option.getTheme?.('colorScheme');
}
Expand Down
7 changes: 7 additions & 0 deletions packages/vchart/src/chart/interface/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type { DataView } from '@visactor/vdataset';
import type { IGlobalScale } from '../../scale/interface';
import type { IMorphConfig } from '../../animation/spec';
import type { IMarkGraphic } from '../../mark/interface/common';
import type { IAxis } from '../../component/axis/interface';

export type DimensionIndexOption = {
filter?: (cmp: IComponent) => boolean;
Expand Down Expand Up @@ -217,6 +218,12 @@ export interface IChart extends ICompilable {
getSeriesData: (id: StringOrNumber | undefined, index: number | undefined) => DataView | undefined;
// setDimensionIndex
setDimensionIndex: (value: StringOrNumber, opt: DimensionIndexOption) => void;
/**
* 显示交叉线
* @since 2.0.9
*/
showCrosshair: (cb: (axis: IAxis) => false | string | number) => void;

/**
* 根据数据筛选图元
* @since 1.13.9
Expand Down
4 changes: 4 additions & 0 deletions packages/vchart/src/core/vchart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,10 @@ export class VChart implements IVChart {
return this._chart?.setDimensionIndex(value, opt);
}

showCrosshair(cb: (axis: IAxis) => false | string | number) {
this._chart?.showCrosshair(cb);
}

/** 停止正在进行的所有动画 */
stopAnimation() {
(this.getStage() as any)?.stopAnimation(true);
Expand Down
Loading