Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
El detector de eventos de arrastre d3 js no está recibiendo el evento - (d3, reaccionar)

Estoy tratando de agregar un evento de arrastre a mi diseño de fuerza d3, pero por alguna razón, el attr del evento no está definido, por lo que no sucede nada. Sé que hubo cambios en el nuevo documento de d3-drag y seguí estas instrucciones.

aquí está mi código:

 const node = svg .selectAll("circle") .data(nodes) .enter() .append("circle") .attr("r", 35) // radius field, so width and height 80X80 .attr("stroke", "lightgray") .attr("stroke-width", 0.5) .style("fill", "lightgray") .call(handler .on('start', dragstarted) .on('drag', dragged) .on('end', dragended)

el evento funciona:

 const dragstarted = (event: any, d: any) => { console.log(' dragged d', d); console.log('event', event); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore if (!event.active) { simulation.alphaTarget(0.3).restart(); } d.fx = dx; d.fy = dy; } // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const dragged = (event: any, d: any) => { console.log(' dragged d', d); console.log('event', event); d.fx = event.x; d.fy = event.y; } // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const dragended = (event: any, d: any) => { console.log(' dragended d', d); console.log('event', event); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore if (event.active) { simulation.alphaTarget(0); } d.fx = null; d.fy = null; }

el ejemplo de los documentos:

 d3.drag() .on("start", (event, d) => circle.filter(p => p === d).raise().attr("stroke", "black")) .on("drag", (event, d) => (dx = event.x, dy = event.y)) .on("end", (event, d) => circle.filter(p => p === d).attr("stroke", null))

y esto es lo que obtengo:

 Uncaught TypeError: Cannot read properties of undefined (reading 'document') at nodrag.js:5

Agregué capturas de pantalla del lugar donde no se pudo obtener el evento.

el evento que no esta ahi

el error

No entiendo lo que hago mal aquí, gracias por la ayuda.

EDITAR el ejemplo completo con el código: https://stackblitz.com/edit/react-saqrv9?file=src%2Fgraph.tsx

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

observe que la nueva API no usa d3.event pero el evento pasó al detector de eventos.

fragmento actualizado, por ejemplo, para cualquiera que esté interesado, sé que no hay muchos ejemplos, así que diviértanse

https://stackblitz.com/edit/react-saqrv9?file=src%2Fgraph.tsx

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!