Skip to content

Commit 7fbf52f

Browse files
authored
perf: remove rBush logic from element picking mechanism (#2031)
* perf: remove rBush logic from element picking mechanism * chore: fix lint error * chore: add changeset * chore: update test case * fix: the element picking range includes the element border
1 parent 6a7c5bc commit 7fbf52f

19 files changed

Lines changed: 938 additions & 218 deletions

File tree

.changeset/metal-kiwis-nail.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@antv/g-plugin-canvas-picker': minor
3+
'@antv/g-lite': minor
4+
---
5+
6+
perf: remove rBush logic from element picking mechanism
File renamed without changes.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Layout manager for arranging examples in a grid
3+
*/
4+
export class ExampleLayoutManager {
5+
private regionWidth: number;
6+
private regionHeight: number;
7+
private padding: number;
8+
private columns: number;
9+
private currentIndex: number;
10+
11+
constructor(
12+
regionWidth: number = 200,
13+
regionHeight: number = 150,
14+
padding: number = 30,
15+
columns: number = 3,
16+
) {
17+
this.regionWidth = regionWidth;
18+
this.regionHeight = regionHeight;
19+
this.padding = padding;
20+
this.columns = columns;
21+
this.currentIndex = 0;
22+
}
23+
24+
/**
25+
* Get the next position for an example
26+
* @returns Object containing x and y coordinates
27+
*/
28+
getNextPosition(): { x: number; y: number } {
29+
const row = Math.floor(this.currentIndex / this.columns);
30+
const col = this.currentIndex % this.columns;
31+
this.currentIndex++;
32+
33+
return {
34+
x: this.padding + col * (this.regionWidth + this.padding),
35+
y: this.padding + row * (this.regionHeight + this.padding),
36+
};
37+
}
38+
39+
/**
40+
* Reset the index to start from the beginning
41+
*/
42+
reset(): void {
43+
this.currentIndex = 0;
44+
}
45+
46+
/**
47+
* Get region dimensions
48+
*/
49+
getRegionDimensions(): { width: number; height: number } {
50+
return {
51+
width: this.regionWidth,
52+
height: this.regionHeight,
53+
};
54+
}
55+
}

0 commit comments

Comments
 (0)