D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
fogonwater
Full window
Github gist
forceRadial tests II
Mucking about with
d3.forceRadial()
. idk anymore
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <meta charset="utf-8"> <svg width="960" height="600" viewBox="-480 -300 960 600"> </svg> <style> body {background-color:#222; margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> var nodes = [].concat( d3.range(1086).map(function() { return {type: "a", offset:(Math.random() * 20) - 10}; }), d3.range(1645).map(function() { return {type: "b", offset:(Math.random() * 20) - 10}; }) ) var colorScale1 = d3.scaleSequential(d3.interpolateRainbow) .domain([300, 660]), colorScale2 = d3.scaleSequential(d3.interpolateRainbow) .domain([660, 300]) var node = d3.select("svg") .append("g") .selectAll("circle") .data(nodes) .enter().append("circle") .attr("r", 2.5) //.attr("fill", function(d) { return d.type === "b" ? '#F24236' : '#5BC0EB'; }) .style("fill", function(d) { return d.col; }) var simulation = d3.forceSimulation(nodes) .force("charge", d3.forceCollide().radius(function(d) { return d.type === "a" ? 3.4 : 6; })) .force("r", d3.forceRadial(function(d) { return d.type === "a" ? 60 : 200; })) .on("tick", ticked); function ticked() { node .attr("cx", function(d) { return d.x; }) .attr("cy", function(d) { return d.y; }) .style("fill", function(d){ return d.type === "b" ? colorScale1(d.x + d.offset) : colorScale2(d.y + d.offset); }) } </script> </body>
https://d3js.org/d3.v4.min.js