diff --git a/packages/s2-core/__tests__/unit/interaction/brush-selection/base-brush-selection-spec.ts b/packages/s2-core/__tests__/unit/interaction/brush-selection/base-brush-selection-spec.ts
index 2ca03ad8d0..f5320e24c9 100644
--- a/packages/s2-core/__tests__/unit/interaction/brush-selection/base-brush-selection-spec.ts
+++ b/packages/s2-core/__tests__/unit/interaction/brush-selection/base-brush-selection-spec.ts
@@ -13,6 +13,7 @@ import {
type OriginalEvent,
type S2DataConfig,
type ViewMeta,
+ EventController,
} from '@/index';
import { RootInteraction } from '@/interaction/root';
@@ -61,6 +62,13 @@ describe('Interaction Base Cell Brush Selection Tests', () => {
await s2.render();
mockRootInteraction = new MockRootInteraction(s2);
+ mockRootInteraction.eventController = new EventController(s2);
+ mockRootInteraction.eventController.getViewportPoint = (event) => {
+ return s2.container.client2Viewport({
+ x: event.clientX,
+ y: event.clientY,
+ });
+ };
mockRootInteraction.getBrushSelection = () => {
return {
dataCell: true,
diff --git a/packages/s2-core/__tests__/unit/interaction/brush-selection/col-brush-selection-spec.ts b/packages/s2-core/__tests__/unit/interaction/brush-selection/col-brush-selection-spec.ts
index 99b88feadd..b14452a3de 100644
--- a/packages/s2-core/__tests__/unit/interaction/brush-selection/col-brush-selection-spec.ts
+++ b/packages/s2-core/__tests__/unit/interaction/brush-selection/col-brush-selection-spec.ts
@@ -11,6 +11,7 @@ import {
SpreadSheet,
type OriginalEvent,
type S2DataConfig,
+ EventController,
} from '@/index';
jest.mock('@/interaction/event-controller');
@@ -72,6 +73,13 @@ describe('Interaction Col Cell Brush Selection Tests', () => {
s2.showTooltipWithInfo = jest.fn();
mockRootInteraction = new MockRootInteraction(s2);
+ mockRootInteraction.eventController = new EventController(s2);
+ mockRootInteraction.eventController.getViewportPoint = (event) => {
+ return s2.container.client2Viewport({
+ x: event.clientX,
+ y: event.clientY,
+ });
+ };
s2.getCell = jest.fn(() => startBrushColCell) as any;
mockRootInteraction.getBrushSelection = () => {
return {
@@ -212,7 +220,7 @@ describe('Interaction Col Cell Brush Selection Tests', () => {
expect(brushSelectionFn).toHaveBeenCalledTimes(1);
});
- test('should not emit brush secletion event', () => {
+ test('should not emit brush selection event', () => {
mockRootInteraction.getBrushSelection = () => ({
dataCell: true,
rowCell: true,
diff --git a/packages/s2-core/__tests__/unit/interaction/brush-selection/data-brush-selection-spec.ts b/packages/s2-core/__tests__/unit/interaction/brush-selection/data-brush-selection-spec.ts
index e088960cf2..017d8f5e60 100644
--- a/packages/s2-core/__tests__/unit/interaction/brush-selection/data-brush-selection-spec.ts
+++ b/packages/s2-core/__tests__/unit/interaction/brush-selection/data-brush-selection-spec.ts
@@ -7,19 +7,20 @@ import {
CellType,
DataCellBrushSelection,
FrozenGroupType,
- getScrollOffsetForCol,
- getScrollOffsetForRow,
InteractionBrushSelectionStage,
Node,
PivotSheet,
S2Event,
ScrollDirection,
SpreadSheet,
+ getScrollOffsetForCol,
+ getScrollOffsetForRow,
type LayoutResult,
type OriginalEvent,
type S2DataConfig,
type S2Options,
type ViewMeta,
+ EventController,
} from '@/index';
import { RootInteraction } from '@/interaction/root';
@@ -118,6 +119,13 @@ describe('Interaction Data Cell Brush Selection Tests', () => {
await s2.render();
mockRootInteraction = new MockRootInteraction(s2);
+ mockRootInteraction.eventController = new EventController(s2);
+ mockRootInteraction.eventController.getViewportPoint = (event) => {
+ return s2.container.client2Viewport({
+ x: event.clientX,
+ y: event.clientY,
+ });
+ };
s2.getCell = jest.fn(() => startBrushDataCell) as any;
s2.showTooltipWithInfo = jest.fn();
mockRootInteraction.getSelectedCellHighlight = () => {
diff --git a/packages/s2-core/__tests__/unit/interaction/brush-selection/row-brush-selection-spec.ts b/packages/s2-core/__tests__/unit/interaction/brush-selection/row-brush-selection-spec.ts
index d36a16a44b..568d236cc3 100644
--- a/packages/s2-core/__tests__/unit/interaction/brush-selection/row-brush-selection-spec.ts
+++ b/packages/s2-core/__tests__/unit/interaction/brush-selection/row-brush-selection-spec.ts
@@ -11,6 +11,7 @@ import {
SpreadSheet,
type OriginalEvent,
type S2DataConfig,
+ EventController,
} from '@/index';
jest.mock('@/interaction/event-controller');
@@ -73,6 +74,13 @@ describe('Interaction Row Cell Brush Selection Tests', () => {
s2.showTooltipWithInfo = jest.fn();
s2.getCell = jest.fn(() => startBrushRowCell) as any;
mockRootInteraction = new MockRootInteraction(s2);
+ mockRootInteraction.eventController = new EventController(s2);
+ mockRootInteraction.eventController.getViewportPoint = (event) => {
+ return s2.container.client2Viewport({
+ x: event.clientX,
+ y: event.clientY,
+ });
+ };
mockRootInteraction.getBrushSelection = () => {
return {
dataCell: true,
@@ -259,7 +267,7 @@ describe('Interaction Row Cell Brush Selection Tests', () => {
expect(brushSelectionInstance.brushRangeCells.length).toEqual(8);
});
- test('should not emit brush secletion event', () => {
+ test('should not emit brush selection event', () => {
mockRootInteraction.getBrushSelection = () => ({
dataCell: true,
rowCell: false,
diff --git a/packages/s2-core/__tests__/unit/interaction/event-controller-spec.ts b/packages/s2-core/__tests__/unit/interaction/event-controller-spec.ts
index a884abaad5..57ba406a56 100644
--- a/packages/s2-core/__tests__/unit/interaction/event-controller-spec.ts
+++ b/packages/s2-core/__tests__/unit/interaction/event-controller-spec.ts
@@ -1004,9 +1004,9 @@ describe('Interaction Event Controller Tests', () => {
spreadsheet.on(S2Event.GLOBAL_RESET, reset);
const pointInCanvas = getClientPointOnCanvas(spreadsheet.container, 10, 10);
- const evt = new window.CustomEvent('click');
+ const event = new window.CustomEvent('click');
- Object.defineProperties(evt, {
+ Object.defineProperties(event, {
clientX: {
value: pointInCanvas.clientX,
},
@@ -1014,10 +1014,41 @@ describe('Interaction Event Controller Tests', () => {
value: pointInCanvas.clientY,
},
});
- spreadsheet.getCanvasElement().dispatchEvent(evt);
+ spreadsheet.getCanvasElement().dispatchEvent(event);
expect(eventController.isCanvasEffect).toBe(true);
expect(reset).not.toHaveBeenCalled();
expect(spreadsheet.interaction.reset).not.toHaveBeenCalled();
});
+
+ // https://github.com/antvis/S2/issues/2553
+ test('should use offset point if enable supportsCSSTransform', () => {
+ jest.spyOn(spreadsheet, 'getCanvasConfig').mockImplementationOnce(() => {
+ return {
+ supportsCSSTransform: true,
+ };
+ });
+
+ const event = new MouseEvent('click');
+
+ Object.defineProperties(event, {
+ offsetX: {
+ value: 100,
+ },
+ offsetY: {
+ value: 200,
+ },
+ clientX: {
+ value: 300,
+ },
+ clientY: {
+ value: 400,
+ },
+ });
+
+ expect(eventController.getViewportPoint(event)).toStrictEqual({
+ x: 100,
+ y: 200,
+ });
+ });
});
diff --git a/packages/s2-core/__tests__/util/helpers.ts b/packages/s2-core/__tests__/util/helpers.ts
index 736ba8a3db..3a1f555072 100644
--- a/packages/s2-core/__tests__/util/helpers.ts
+++ b/packages/s2-core/__tests__/util/helpers.ts
@@ -14,7 +14,13 @@ import { omit } from 'lodash';
import * as simpleDataConfig from 'tests/data/simple-data.json';
import * as dataConfig from 'tests/data/mock-dataset.json';
import { Renderer } from '@antv/g-canvas';
-import { getTheme, type BaseDataSet, type Node, Hierarchy } from '../../src';
+import {
+ getTheme,
+ type BaseDataSet,
+ type Node,
+ Hierarchy,
+ EventController,
+} from '../../src';
import { assembleOptions, assembleDataCfg } from '.';
import { RootInteraction } from '@/interaction/root';
@@ -148,6 +154,7 @@ export const createFakeSpreadSheet = (config?: {
[FrozenGroupType.FROZEN_TRAILING_COL]: {},
},
cornerBBox: {},
+ destroy: jest.fn(),
} as unknown as BaseFacet;
s2.container.render = jest.fn();
s2.store = new Store();
@@ -173,6 +180,7 @@ export const createFakeSpreadSheet = (config?: {
s2.facet.getCells = jest.fn().mockReturnValue([]);
s2.getCanvasElement = () =>
s2.container.getContextService().getDomElement() as HTMLCanvasElement;
+ s2.getCanvasConfig = () => s2.container.getConfig();
s2.isCustomHeaderFields = jest.fn(() => false);
s2.isCustomRowFields = jest.fn(() => false);
s2.isCustomColumnFields = jest.fn(() => false);
@@ -193,6 +201,7 @@ export const createFakeSpreadSheet = (config?: {
const interaction = new RootInteraction(s2 as unknown as SpreadSheet);
s2.interaction = interaction;
+ s2.interaction.eventController = new EventController(s2);
return s2;
};
diff --git a/packages/s2-core/src/common/interface/basic.ts b/packages/s2-core/src/common/interface/basic.ts
index 949fdfed92..390db21b39 100644
--- a/packages/s2-core/src/common/interface/basic.ts
+++ b/packages/s2-core/src/common/interface/basic.ts
@@ -1,4 +1,4 @@
-import type { FederatedPointerEvent as Event } from '@antv/g';
+import type { FederatedPointerEvent as Event, PointLike } from '@antv/g';
import type { DataCell, MergedCell } from '../../cell';
import type {
CustomTreeNode,
@@ -507,9 +507,6 @@ export interface GridInfo {
rows: number[];
}
-export interface Point {
- x: number;
- y: number;
-}
+export interface Point extends PointLike {}
export type RowData = Data | CellData[];
diff --git a/packages/s2-core/src/common/interface/tooltip.ts b/packages/s2-core/src/common/interface/tooltip.ts
index a13d672ab8..eec49440ae 100644
--- a/packages/s2-core/src/common/interface/tooltip.ts
+++ b/packages/s2-core/src/common/interface/tooltip.ts
@@ -1,6 +1,6 @@
-import type { FederatedPointerEvent as CanvasEvent } from '@antv/g';
+import type { FederatedPointerEvent as CanvasEvent, PointLike } from '@antv/g';
import type * as CSS from 'csstype';
-import type { Point, S2CellType, ViewMetaData } from '../../common/interface';
+import type { S2CellType, ViewMetaData } from '../../common/interface';
import type { SpreadSheet } from '../../sheet-type';
import type { BaseTooltip } from '../../ui/tooltip';
@@ -66,7 +66,7 @@ export interface TooltipOperatorOptions