Skip to content

Commit dda14e4

Browse files
committed
fix: fix crosshair when has innerOffser, fix #4338
1 parent 81ea1ff commit dda14e4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

packages/vchart/src/component/axis/cartesian/axis.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ export abstract class CartesianAxis<T extends ICartesianAxisCommonSpec = ICartes
116116
left: 0,
117117
right: 0
118118
};
119+
getInnerOffset() {
120+
return this._innerOffset;
121+
}
119122

120123
constructor(spec: T, options: IComponentOption) {
121124
super(spec, options);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,19 +441,21 @@ export abstract class BaseCrossHair<T extends ICartesianCrosshairSpec | IPolarCr
441441
let x2 = -Infinity;
442442
let y2 = -Infinity;
443443
const { x: sx, y: sy } = this.getLayoutStartPoint();
444+
444445
bindingAxesIndex.forEach(idx => {
445446
(x1 = Infinity), (y1 = Infinity), (x2 = -Infinity), (y2 = -Infinity);
446447
const axis = axesComponents.find(axis => axis.getSpecIndex() === idx);
447448
if (!axis) {
448449
return;
449450
}
451+
const innerOffset = (axis as any).getInnerOffset?.() || { left: 0, right: 0, top: 0, bottom: 0 };
450452
const regions = axis.getRegions();
451453
regions.forEach(r => {
452454
const { x: regionStartX, y: regionStartY } = r.getLayoutStartPoint();
453-
x1 = Math.min(x1, regionStartX - sx);
454-
y1 = Math.min(y1, regionStartY - sy);
455-
x2 = Math.max(x2, regionStartX + r.getLayoutRect().width - sx);
456-
y2 = Math.max(y2, regionStartY + r.getLayoutRect().height - sy);
455+
x1 = Math.min(x1, regionStartX - sx + innerOffset.left);
456+
y1 = Math.min(y1, regionStartY - sy + innerOffset.top);
457+
x2 = Math.max(x2, regionStartX + r.getLayoutRect().width - sx - innerOffset.right);
458+
y2 = Math.max(y2, regionStartY + r.getLayoutRect().height - sy - innerOffset.bottom);
457459
});
458460
map.set(idx, { x1, y1, x2, y2, axis: axis as unknown as T });
459461
});

0 commit comments

Comments
 (0)