Skip to content

Instantly share code, notes, and snippets.

@Y4suyuki
Created October 7, 2013 07:54
Show Gist options
  • Save Y4suyuki/6864037 to your computer and use it in GitHub Desktop.
Save Y4suyuki/6864037 to your computer and use it in GitHub Desktop.
cluster basics
{"description":"cluster basics","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"flare.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.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,"thumbnail":"http://i.imgur.com/KKztdwo.png"}
{
"name": "flare",
"children": [
{
"name": "analytics",
"children": [
{
"name": "cluster",
"children": [
{"name": "AgglomerativeCluster", "size": 3938},
{"name": "CommunityStructure", "size": 3812},
{"name": "MergeEdge", "size": 743}
]
},
{
"name": "graph",
"children": [
{"name": "BetweennessCentrality", "size": 3534},
{"name": "LinkDistance", "size": 5731}
]
}
]
}
]
}
.link {
fill: none;
stroke: #ccc;
stroke-width: 1.5px;
}
.node circle {
fill: none;
stroke: steelblue;
stroke-width: 2.5px;
}
var svg = d3.select("svg")
var flare_d = tributary.flare;
var cluster = d3.layout.cluster()
.size([435,263]);
var diagonal = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x]; });
var nodes = cluster.nodes(flare_d),
links = cluster.links(nodes);
console.log(nodes);
var link = svg.selectAll(".link")
.data(links)
.enter().append("path")
.attr("class", "link")
.attr("d", diagonal);
var node = svg.selectAll(".node")
.data(nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.y + ", " + d.x + ")"});
node.append("circle")
.attr("r", 4.5)
.on("mouseover", function() {
d3.select(this).attr("fill", "steelblue");
});
node.append("text")
.attr("dx", function(d) { return d.childlen ? -8 : 8; })
.attr("dy", function(d) { return 3; })
.style("textanchor", function(d) { return d.children ? "end" : "start"; })
.text(function(d) { return d.size ? d.name + ": " + d.size : d.name; })
function toggle(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
}
function toggleRoot() {
toggle(flare_d);
console.log(flare_d);
nodes = cluster.nodes(flare_d);
console.log(nodes);
}
toggleRoot();
toggleRoot();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment