Built with blockbuilder.org
Last active
June 27, 2018 18:24
-
-
Save ojassvi/8bbeb409f701303c30a5c0e60d42a14c to your computer and use it in GitHub Desktop.
cluster draft 3
This file contains 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
license: mit |
This file contains 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
{ | |
"clusters": [ | |
{ | |
"id": "1", | |
"cluster": "a", | |
"asset": "ojassvi" | |
}, | |
{ | |
"id": "2", | |
"cluster": "a", | |
"asset": "mohan" | |
}, | |
{ | |
"id": "3", | |
"cluster": "b", | |
"asset": "linli" | |
}, | |
{ | |
"id": "4", | |
"cluster": "a", | |
"asset": "trupti" | |
}, | |
{ | |
"id": "5", | |
"cluster": "b", | |
"asset": "niranjan" | |
}, | |
{ | |
"id": "6", | |
"cluster": "c", | |
"asset": "rohan" | |
}, | |
{ | |
"id": "7", | |
"cluster": "a", | |
"asset": "jeff" | |
}, | |
{ | |
"id": "8", | |
"cluster": "b", | |
"asset": "hazim" | |
}, | |
{ | |
"id": "9", | |
"cluster": "c", | |
"asset": "m4" | |
}, | |
{ | |
"id": "10", | |
"cluster": "c", | |
"asset": "rick" | |
} | |
] | |
} |
This file contains 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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
svg {border: 1px solid} | |
circle { | |
/* fill: none; | |
stroke: black; */ | |
} | |
</style> | |
<svg width="500" height="400"></svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script> | |
var svg = d3.select("svg"), | |
width = svg.attr("width"), | |
height = svg.attr("height"); | |
var x = d3.scaleLinear().rangeRound([0, width]); | |
var g = svg.append("g"); | |
const smallRadius = 5; | |
const innerPadding = 1; | |
console.log('yo'); | |
d3.json("cluster.json", type, function(error, data) { | |
console.log(error); | |
if (error) throw error; | |
console.log(data); | |
var simulation = d3.forceSimulation(data) | |
.force("x", d3.forceX(function(d) { return width / 2 })) | |
.force("y", d3.forceY(height / 2)) | |
.force("collide", d3.forceCollide(smallRadius + innerPadding)) | |
.stop(); | |
for (var i = 0; i < 100; ++i) simulation.tick(); | |
var cell = g.selectAll("circle") | |
.data(data) | |
.enter() | |
.append("circle") | |
.attr("r", smallRadius) | |
.attr("cx", function(d) { return d.x; }) | |
.attr("cy", function(d) { return d.y; }); | |
g.append("circle") | |
.attr("r", getOuterRadius(data.length)) | |
.attr("cx", function(d) { return width/2 }) | |
.attr("cy", function(d) { return height/2 }) | |
.attr("fill", "none") | |
.attr("stroke", "blue"); | |
}); | |
function type(d) { | |
if (!d.value) return; | |
d.value = +d.value; | |
return d; | |
} | |
function getOuterRadius(nodes) { | |
return 6 * smallRadius; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment