Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var graph = {
- nodes: [
- <% nodes.forEach(function(a){ %>
- {category: "<%= a.properties.Name %>"},
- <% }); %>
- ],
- links: [
- <% edges.forEach(function(a){ %>
- {"source": <%= a.source %>, "target": <%= a.target %>},
- <% }); %>
- ]
- }
- var graph = {
- nodes: [
- {Name: "b"},
- {Name: "c"},
- {Name: "c"},
- {Name: "c"},
- {Name: "b"},
- {Name: "b"},
- {Name: "c"},
- {Name: "c"},
- {Name: "c"},
- {Name: "b"},
- {Name: "c"},
- {Name: "c"},
- {Name: "d"},
- {Name: "d"},
- {Name: "a"},
- {Name: "c"}
- ],
- links: [
- {source: 8, target: 3},
- {source: 3, target: 5},
- {source: 3, target: 6},
- {source: 3, target: 7},
- {source: 3, target: 11},
- {source: 3, target: 12},
- {source: 8, target: 0},
- {source: 0, target: 13},
- {source: 0, target: 14},
- {source: 8, target: 9},
- {source: 9, target: 17},
- {source: 9, target: 18},
- {source: 14,target: 15},
- {source: 14,target: 16},
- {source: 8, target: 10}
- ]
- }
- var w = 800;
- var h = 400;
- var svg = d3.select("body")
- .append("svg")
- .attr("width", w)
- .attr("height", h)
- var force = d3.forceSimulation(graph.nodes)
- .force("charge", d3.forceManyBody())
- .force("link", d3.forceLink(graph.edges))
- .force("center", d3.forceCenter().x(w/1).y(h/1))
- var edges = svg.selectAll("line")
- .data(graph.edges)
- .enter()
- .append("line")
- .style("stroke", "#ccc")
- .style("stroke-width", 1)
- var nodes = svg.selectAll("circle")
- .data(graph.nodes)
- .enter()
- .append("circle")
- .attr("r", 10)
- nodes.append("title")
- .text(function(d) {
- return d.name
- })
- force.on("tick", function() {
- edges.attr("x1", function(d) { return d.source.x; })
- .attr("y1", function(d) { return d.source.y; })
- .attr("x2", function(d) { return d.target.x; })
- .attr("y2", function(d) { return d.target.y; })
- nodes.attr("cx", function(d) { return d.x; })
- .attr("cy", function(d) { return d.y; })
- })
- var graph = {
- nodes: [
- { name: "Adam" },
- { name: "Bob" },
- { name: "Carrie" },
- { name: "Donovan" },
- { name: "Edward" },
- { name: "Felicity" },
- { name: "George" },
- { name: "Hannah" },
- { name: "Iris" },
- { name: "Jerry" }
- ],
- edges: [
- { source: 0, target: 1 },
- { source: 0, target: 2 },
- { source: 0, target: 3 },
- { source: 0, target: 4 },
- { source: 1, target: 5 },
- { source: 2, target: 5 },
- { source: 2, target: 5 },
- { source: 3, target: 4 },
- { source: 5, target: 8 },
- { source: 5, target: 9 },
- { source: 6, target: 7 },
- { source: 7, target: 8 },
- { source: 8, target: 9 }
- ]
- }
Add Comment
Please, Sign In to add comment