[ Launch: hammer nodes ] 9727634 by DeBraid
-
-
Save DeBraid/9727634 to your computer and use it in GitHub Desktop.
hammer nodes - test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"hammer nodes - test","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true,"thumbnail":"http://i.imgur.com/DKKeipj.png"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var links = [ | |
{source: "Education", target: "City of Hamilton"}, | |
{source: "Industry", target: "City of Hamilton"}, | |
{source: "Health", target: "City of Hamilton"}, | |
{source: "Hamilton Community Foundation", target: "Health"}, | |
{source: "International Airport", target: "Industry"}, | |
{source: "Port Authority", target: "Industry"}, | |
{source: "McMaster", target: "Education"}, | |
{source: "Mac Innovation Park", target: "McMaster"}, | |
{source: "Mohawk", target: "Education"}, | |
{source: "Hamilton Health Science", target: "Health"}, | |
{source: "Redeemer", target: "Education"} | |
]; | |
var nodes = {}; | |
// Compute the distinct nodes from the links. | |
links.forEach(function(link) { | |
link.source = nodes[link.source] || (nodes[link.source] = {name: link.source}); | |
link.target = nodes[link.target] || (nodes[link.target] = {name: link.target}); | |
}); | |
var width = 960, | |
height = 500; | |
var force = d3.layout.force() | |
.nodes(d3.values(nodes)) | |
.links(links) | |
.size([width, height]) | |
.linkDistance(134) | |
.charge(-474) | |
.on("tick", tick) | |
.start(); | |
var svg = d3.select("svg") | |
.attr("width", width) | |
.attr("height", height); | |
var link = svg.selectAll(".link") | |
.data(force.links()) | |
.enter().append("line") | |
.attr("class", "link"); | |
var node = svg.selectAll(".node") | |
.data(force.nodes()) | |
.enter().append("g") | |
.attr("class", "node") | |
.on("mouseover", mouseover) | |
.on("mouseout", mouseout) | |
.call(force.drag); | |
node.append("circle") | |
.attr("r", 8); | |
node.append("text") | |
.attr("x", 12) | |
.attr("dy", ".35em") | |
.text(function(d) { return d.name; }); | |
function tick() { | |
link | |
.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; }); | |
node | |
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); | |
} | |
function mouseover() { | |
d3.select(this).select("circle").transition() | |
.duration(750) | |
.attr("r", 16); | |
colorChange(); | |
} | |
function mouseout() { | |
d3.select(this).select("circle").transition() | |
.duration(750) | |
.attr("r", 8); | |
} | |
function colorChange() { | |
console.log(this); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.link { | |
fill: none; | |
stroke: white; | |
stroke-width: 0.5px; | |
} | |
.node circle { | |
fill: #ccc; | |
stroke: #fff; | |
stroke-width: 1.5px; | |
} | |
text { | |
font: 10px sans-serif; | |
pointer-events: none; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment