A visualization of fake data that shows connections between points on a map.
forked from mbostock's block: Equirectangular (Plate Carrée)
forked from maureentsakiris's block: Invitations
Built with blockbuilder.org
xxxxxxxxxx
<meta charset="utf-8">
<style>
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #222;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 480,
userColor = "orange",
userSize = 4,
linkColor = "orange";
var projection = d3.geo.equirectangular()
.scale(153)
.translate([width / 2, height / 2])
.precision(.1);
var path = d3.geo.path()
.projection(projection);
var graticule = d3.geo.graticule();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
d3.json("https://gist.githubusercontent.com/mbostock/4090846/raw/d534aba169207548a8a3d670c9c2cc719ff05c47/world-50m.json", function(error, world) {
if (error) throw error;
svg.insert("path", ".graticule")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("d", path);
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("d", path);
d3.csv("invitation_chain.csv", type, function (data){
svg.selectAll("circle").data(data).enter().append("circle")
.attr("r", userSize)
.attr("fill", userColor)
.attr("cx", function (d){ return d.projected[0]; })
.attr("cy", function (d){ return d.projected[1]; });
var links = generateLinks(data);
svg.selectAll("line").data(links).enter().append("line")
.attr("r", 4)
.attr("stroke", linkColor)
.attr("stroke-width", "1px")
.attr("x1", function (d){ return d.projected[0]; })
.attr("y1", function (d){ return d.projected[1]; })
.attr("x2", function (d){ return d.projected_invited_by[0]; })
.attr("y2", function (d){ return d.projected_invited_by[1]; });
});
});
function type(d){
// This should actually be [d.longitude, d.latitude]
// It looks like these are reversed in the data.
d.projected = projection([d.latitude, d.longitude]);
return d;
}
function generateLinks(data){
locationsByUser = {};
data.forEach(function (d){
locationsByUser[d.user_name] = d.projected;
});
return data.filter(function (d){
return d.invited_by_user_name;
}).map(function (d){
d.projected_invited_by = locationsByUser[d.invited_by_user_name];
//console.log(d.projected_invited_by);
return d;
});
}
d3.select(self.frameElement).style("height", height + "px");
</script>
https://d3js.org/d3.v3.min.js
https://d3js.org/topojson.v1.min.js