Skip to content

Commit b72c0c3

Browse files
committed
fix: fix crosshair when has innerOffser, fix #4338
1 parent 64387d4 commit b72c0c3

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
@@ -440,19 +440,21 @@ export abstract class BaseCrossHair<T extends ICartesianCrosshairSpec | IPolarCr
440440
let x2 = -Infinity;
441441
let y2 = -Infinity;
442442
const { x: sx, y: sy } = this.getLayoutStartPoint();
443+
443444
bindingAxesIndex.forEach(idx => {
444445
(x1 = Infinity), (y1 = Infinity), (x2 = -Infinity), (y2 = -Infinity);
445446
const axis = axesComponents.find(axis => axis.getSpecIndex() === idx);
446447
if (!axis) {
447448
return;
448449
}
450+
const innerOffset = (axis as any).getInnerOffset?.() || { left: 0, right: 0, top: 0, bottom: 0 };
449451
const regions = axis.getRegions();
450452
regions.forEach(r => {
451453
const { x: regionStartX, y: regionStartY } = r.getLayoutStartPoint();
452-
x1 = Math.min(x1, regionStartX - sx);
453-
y1 = Math.min(y1, regionStartY - sy);
454-
x2 = Math.max(x2, regionStartX + r.getLayoutRect().width - sx);
455-
y2 = Math.max(y2, regionStartY + r.getLayoutRect().height - sy);
454+
x1 = Math.min(x1, regionStartX - sx + innerOffset.left);
455+
y1 = Math.min(y1, regionStartY - sy + innerOffset.top);
456+
x2 = Math.max(x2, regionStartX + r.getLayoutRect().width - sx - innerOffset.right);
457+
y2 = Math.max(y2, regionStartY + r.getLayoutRect().height - sy - innerOffset.bottom);
456458
});
457459
map.set(idx, { x1, y1, x2, y2, axis: axis as unknown as T });
458460
});

0 commit comments

Comments
 (0)