[ Launch: cluster basics ] 6864037 by Y4suyuki
-
-
Save Y4suyuki/6864037 to your computer and use it in GitHub Desktop.
cluster basics
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":"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"} |
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
{ | |
"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} | |
] | |
} | |
] | |
} | |
] | |
} |
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: #ccc; | |
stroke-width: 1.5px; | |
} | |
.node circle { | |
fill: none; | |
stroke: steelblue; | |
stroke-width: 2.5px; | |
} |
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 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