Skip to content

Instantly share code, notes, and snippets.

@tcash21
Created May 6, 2017 20:03
Show Gist options
  • Save tcash21/447044c53b5c680796f0f3eb31f1120b to your computer and use it in GitHub Desktop.
Save tcash21/447044c53b5c680796f0f3eb31f1120b to your computer and use it in GitHub Desktop.
d3.csv("../data/imdb.csv", function(data) {
dataset = data
});
offset = 2
circles = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height)
.selectAll("circle")
.data(dataset)
.enter().append("circle")
function getRandomOffset() {
return (((Math.random() * 2 * offset) - offset) * 400);
}
dataset.forEach(d => {
d.cx =+ Math.abs(getRandomOffset());
d.cy =+ Math.abs(getRandomOffset());
d.r =+ d.score;
})
circles.attr("r", function(d) {
return d.r;
} ).attr("cx", function(d) {
return d.cx;
}).attr("cy", function(d) {
return d.cy;
}).attr("fill", "green")
@hrbrmstr
Copy link

hrbrmstr commented May 6, 2017

var dataset;
var width = 960, height = 500;

function getRandomOffset() {
  return(((Math.random() * 2 * offset) - offset)  * 400);
}

function do_vis(data) {

  var offset = 2

  var circles = d3.select("body")
        .append("svg")
        .attr("width", width)
        .attr("height", height)
        .selectAll("circle")
        .data(data)
        .enter().append("circle")

  data.forEach(d => {
    d.cx =+ Math.abs(getRandomOffset());
    d.cy =+ Math.abs(getRandomOffset());
    d.r =+ d.score;
  })

  circles.attr("r", d => d.r)
    .attr("cx", d => d.cx)
    .attr("cy", d => d.cy)
    .attr("fill", "green")  

}

d3.csv("../data/imdb.csv", function(data) {
  dataset = data;
  do_vis(data);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment