Skip to content

Commit

Permalink
fix: fix bug of setDimensionIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
xile611 committed May 17, 2024
1 parent 9950dec commit f859e4b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
6 changes: 4 additions & 2 deletions packages/vchart/src/component/crosshair/cartesian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,17 @@ export class CartesianCrossHair<T extends ICartesianCrosshairSpec = ICartesianCr
if (tooltipData && tooltipData.length) {
if (activeType === 'dimension') {
const dimensionInfo = (tooltipData as IDimensionInfo[])[0];
const dimensionData = dimensionInfo.data[0];
const pos = dimensionData.series.dataToPosition(dimensionData.datum[0]);

const isY = isValid(dimensionInfo.dimType)
? dimensionInfo.dimType === 'y'
: isYAxis(dimensionInfo?.axis?.getOrient() as IOrientType);

if (isY) {
y = dimensionInfo.position;
y = pos.y;
} else {
x = dimensionInfo.position;
x = pos.x;
}
} else if (activeType === 'mark') {
const dimensionData = (tooltipData as IDimensionData[])[0];
Expand Down
21 changes: 15 additions & 6 deletions packages/vchart/src/event/events/dimension/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { getPolarDimensionInfo } from './util/polar';
import { getCartesianDimensionInfo, getDimensionInfoByValue } from './util/cartesian';
import type { Maybe } from '../../../typings';
import { isDiscrete } from '@visactor/vscale';
import { isXAxis } from '../../../component/axis/cartesian/util';
import type { IOrientType } from '@visactor/vrender-components';

export class DimensionEvent implements IComposedEvent {
protected _eventDispatcher: IEventDispatcher;
Expand Down Expand Up @@ -56,21 +58,28 @@ export class DimensionEvent implements IComposedEvent {

dispatch(v: unknown, opt: { filter?: (axis: IAxis) => boolean }) {
// get all enable axis
const axis = this.chart?.getAllComponents().filter(c => {
const axes = this.chart?.getAllComponents().filter(c => {
if (c.specKey !== 'axes') {
return false;
}
const scale = (<IAxis>c).getScale();
if (!isDiscrete(scale.type)) {
return false;
}
if (opt?.filter) {
return opt.filter(<IAxis>c);
}
return true;
}) as IAxis[];

const discreteAxes = axes.filter(axis => {
const scale = (<IAxis>axis).getScale();
return isDiscrete(scale.type);
});
const dimAxes = discreteAxes.length
? discreteAxes
: axes.filter(axis => {
const orient = axis.getOrient();
return isXAxis(orient as IOrientType) || orient === 'angle';
});
const dimensionInfo: IDimensionInfo[] = [];
axis.forEach(a => {
dimAxes.forEach(a => {
const info = getDimensionInfoByValue(a as unknown as any, v);
if (info) {
dimensionInfo.push(info);
Expand Down

0 comments on commit f859e4b

Please sign in to comment.