-
Notifications
You must be signed in to change notification settings - Fork 224
Description
'use client';
import { useEffect, useRef, useState } from 'react';
import { Canvas, Circle, CanvasEvent } from '@antv/g';
import { Renderer } from '@antv/g-webgpu';
export default function Fuck() {
const canvasRef = useRef<Canvas | null>(null);
useEffect(() => {
const initCanvas = async () => {
try {
const webgpuRenderer = new Renderer({
shaderCompilerPath: 'https://unpkg.com/@antv/[email protected]/dist/pkg/glsl_wgsl_compiler_bg.wasm',
});
const canvas = new Canvas({
container: 'container',
width: 600,
height: 500,
renderer: webgpuRenderer,
background: "red",
});
canvasRef.current = canvas;
canvas.addEventListener(CanvasEvent.READY, () => {
const circle = new Circle({
style: {
cx: 500 / 2,
cy: 500 / 2,
r: 100,
fill: '#1890FF',
stroke: '#F04864',
lineWidth: 4,
cursor: 'pointer',
},
});
canvas.appendChild(circle);
circle.addEventListener('mouseenter', () => {
circle.attr('fill', '#2FC25B');
});
circle.addEventListener('mouseleave', () => {
circle.attr('fill', '#1890FF');
});
});
} catch (err: any) {
console.error("Canvas initialization error:", err);
}
};
initCanvas();
const handleResize = () => {
if (canvasRef.current) {
canvasRef.current.resize(window.innerWidth, window.innerHeight);
const circle = canvasRef.current.document.getElementsByTagName('circle')[0];
if (circle) {
circle.style.cx = window.innerWidth / 2;
circle.style.cy = window.innerHeight / 2;
}
}
};
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
if (canvasRef.current) {
canvasRef.current.destroy();
}
};
}, []);
return (
<div
className="w-full h-full"
id="container"
/>
);
}DOM interactions are not working at all.
Expected Behavior
Mouse events (mouseenter, mouseleave, click) should fire when interacting with the Circle
The Circle's fill color should change on hover
Console logs should appear when events are triggered
The cursor should change to pointer when hovering over the Circle
Actual Behavior
No mouse events are triggered (no console logs, no visual changes)
Hovering over the Circle does not change the fill color
Clicking the Circle does not trigger any response
The cursor may not change to pointer as expected
DOM interactions appear completely non-functional
Environment Details
Browser: [Specify browser and version, e.g., Chrome 120, Firefox 121, Safari 17]
Operating System: macOS 24.6.0 (darwin)
Framework: Next.js 16.0.1
React Version: 19.2.0
@antv/g Version: 6.1.28
@antv/g-webgpu Version: 2.0.52
@antv/g-plugin-dom-interaction Version: 2.1.27 (installed but may not be registered)