canvas.document.elementsFromPoint返回的数据可能不对
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 230
- PR merge metrics
- No merged PRs in 30d
Description
> 我感觉可能不是bug,但是确实是和document的方法返回的结果不太一样
## 依赖版本
```json
"@antv/g": "^6.3.1",
"@antv/g-canvas": "^2.2.0",
"@antv/g-svg": "^2.1.1",
"@antv/g-webgl": "^2.1.1",
```
## 实现的代码
```ts
const canvas = new Canvas({
container: document.getElementById("container"),
width: 800,
height: 600,
renderer: new Renderer(), // select a renderer
});
// create a circle
const circle = new Circle({
style: {
cx: 100,
cy: 100,
r: 50,
fill: "linear-gradient(90deg, green, red)",
stroke: "blue",
lineWidth: 5,
cursor: "pointer",
},
});
const circle2 = new Circle({
style: {
cx: 120,
cy: 100,
r: 50,
fill: "linear-gradient(-180deg, yellow, red)",
stroke: "blue",
lineWidth: 5,
cursor: "pointer",
},
});
// circle2.("data-id","circle2")
circle.addEventListener("click", (e) => {
console.log("click", e);
});
const line = new Line({
style: {
x1: 30,
y1: 100,
x2: 400,
y2: 100,
stroke: "linear-gradient(green 0%,red 50%,blue 60%)",
lineWidth: 5,
cursor: "pointer",
},
});
await canvas.ready;
// append to canvas
canvas.appendChild(circle);
canvas.appendChild(circle2);
canvas.appendChild(line); // 我最后append的是线
hitElements.set(line, { value: "line" });
hitElements.set(circle, { value: "circle" });
hitElements.set(circle2, { value: "circle2" });
const result = await canvas.document.elementsFromPoint(120, 100);
console.log(
"log--------------------",
result,
result.map((item) => hitElements.get(item)?.value),
document.elementsFromPoint(120, 100),
);
```
Contributor guide
Research direction
Reproduce the report from the TypeScript example using canvas.document.elementsFromPoint(120, 100) with the two overlapping circles and the appended line. Compare its result and ordering with document.elementsFromPoint and the hitElements map; done means the canvas method's returned elements are consistent with the documented or intended behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 42/100