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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vchart",
"comment": "fix: add inverse crosshair when set axes inverse",
"type": "none"
}
],
"packageName": "@visactor/vchart"
}
8 changes: 7 additions & 1 deletion packages/vchart/src/component/crosshair/utils/cartesian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getAxisLabelOffset } from '../../axis/util';
import { isValid } from '@visactor/vutils';
import type { IAxis, ILinearAxis } from '../../axis';
import { getFormatFunction } from '../../util';
import { ComponentTypeEnum } from '../../interface';

export const layoutByValue = (
stateByField: CrossHairStateByField,
Expand Down Expand Up @@ -63,7 +64,7 @@ export const layoutByValue = (
if (newCacheInfo) {
newCacheInfo._isCache = useCache;
}
let bandSize;
let bandSize: number = 0;
let offsetSize: number = 0;

// 计算x轴和y轴的数据,只允许最多一对x和一对y
Expand All @@ -87,6 +88,10 @@ export const layoutByValue = (
bandSize = Math.abs(
startX - (field === 'xField' ? series.dataToPositionX1(datum) : series.dataToPositionY1(datum))
);
// cartesian 线性 axies 轴反向时需要同步反向
if (axis.getInverse() && axis.type === ComponentTypeEnum.cartesianLinearAxis) {
bandSize = -bandSize;
}
value = `${datum[field1]} ~ ${datum[field2]}`;
} else {
bandSize = 1;
Expand All @@ -95,6 +100,7 @@ export const layoutByValue = (
}
niceLabelFormatter = (axis as ILinearAxis).niceLabelFormatter;
}

if (newCacheInfo && attributes.label?.visible && !useCache) {
const labelOffset = getAxisLabelOffset(axis.getSpec());
const axisOrient = axis.getOrient();
Expand Down
Loading