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

347
Views
¿Es posible obtener una lista de las fuerzas actualmente activas en una simulación de fuerza D3?

Solo diga que tengo una simulación d3-force , y agrego algunas fuerzas como esta:

 const simulation = d3 .forceSimulation() .nodes(dots) .force("charge", d3.forceManyBody()) .force("link", d3.forceLink(links)) .force("center", d3.forceCenter()); .on("tick", tick)

¿Es posible enumerar todas esas fuerzas? ¿Algo así como un método de simulation.getForces() por ejemplo? Y haz que regrese ["charge", "link", "center"] .

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Me temo que no. Desde la fuente , parece que el mapa de forces no está expuesto en absoluto al exterior. La única solución que se me ocurre es envolver el objeto de simulation.force y almacenar su propio registro (lo cual es un truco), o mantener una matriz de todos los valores posibles y ver si simulation.force(name) devuelve algo:

 const width = 600, height = 600; const svg = d3.select("body") .append("svg") .attr("viewBox", [-width / 2, -height / 2, width, height]); const g = svg.append("g"); const nodes = Array .from({ length: 20 }) .map(() => { const [x, y] = d3.pointRadial(2 * Math.PI * Math.random(), 200); return { id: Math.random(), x, y }; }); simulation = d3.forceSimulation() .force("collide", d3.forceCollide().radius(20)) .force("manyBody", d3.forceManyBody().strength(30)) .force("center", d3.forceCenter().strength(0.01)) .alpha(0.1) .alphaDecay(0) .nodes(nodes) .on("tick", () => { g.selectAll("circle:not(.exit)") .data(simulation.nodes(), d => d.id) .join( enter => enter.append("circle") .attr("fill", d => d3.interpolateSinebow(d.id)) .attr("r", 1) .transition() .duration(2000) .attr("r", 19) .selection(), update => update .attr("cx", d => dx) .attr("cy", d => dy), exit => exit .classed("exit", true) .transition() .duration(2000) .attr("fill", "#eee") .attr("r", 1) .remove() ); }); const allPossibleForces = [ "x", "y", "manyBody", "collide", "center" ]; const allForces = allPossibleForces.filter(v => simulation.force(v) !== undefined); console.log(allForces);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/6.2.0/d3.min.js"></script>

about 4 years ago · Juan Pablo Isaza 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!