Skip to content

Instantly share code, notes, and snippets.

@boulderalf
Forked from d3noob/.block
Last active October 4, 2015 23:44
Show Gist options
  • Save boulderalf/2eeccdb40da8aba20657 to your computer and use it in GitHub Desktop.
Save boulderalf/2eeccdb40da8aba20657 to your computer and use it in GitHub Desktop.
City of Boulder Colorado Municipal Elections
source target value
Amabile, Judy Coalition for One Boulder 96.8
Anderson, Cherry-Rose Coalition for One Boulder 100
Anderson, Sidney Coalition for One Boulder 485.2
Appelbaum, Matt Coalition for One Boulder 25
Beverage World, Hazel's Coalition for One Boulder 67.37
Biek, David Coalition for One Boulder 50
Born, Karen Coalition for One Boulder 970.7
Boulder, Better Coalition for One Boulder 2500
Burton, Jan Coalition for One Boulder 48.65
Byrne, Ed Coalition for One Boulder 50
Cowles, Macon Coalition for One Boulder 50
Craig, Robert Coalition for One Boulder 23.98
Day, Phil Coalition for One Boulder 2500
Dierking, Bruce Coalition for One Boulder 1000
Doyle, Benedict Coalition for One Boulder 9.41
Eaton, Leslie Coalition for One Boulder 485.2
Espinoza, Angelique Coalition for One Boulder 50
Fitch, John Coalition for One Boulder 23.98
Foy, Richard Coalition for One Boulder 96.8
Gidfar, Ali Coalition for One Boulder 100
Glustrom, Leslie Coalition for One Boulder 35
Group, LLC, Foundry Coalition for One Boulder 2500
Heinz, Peter Coalition for One Boulder 242.45
Heit, Steven Coalition for One Boulder 100
Holdings, Circle D Coalition for One Boulder 500
Investors, West Baseline Coalition for One Boulder 1000
Johnson, Erik Coalition for One Boulder 15
Kalinski, Tom Coalition for One Boulder 500
Land Company, Southern Coalition for One Boulder 5000
Lawrence, Stephen Coalition for One Boulder 23.96
Merker, Diane Coalition for One Boulder 15
Morehouse, Robert Coalition for One Boulder 100
Polk, Richard Coalition for One Boulder 48.25
Properties, Tebo Coalition for One Boulder 2500
Property Group, Amterre Coalition for One Boulder 96.8
Publications, Lifestyle Coalition for One Boulder 1550
Pugh, John Coalition for One Boulder 485.2
Real Estate, Kruegel Commercial Coalition for One Boulder 200
Realtors, Boulder Area Coalition for One Boulder 5000
Rogers, Alan Coalition for One Boulder 100
Ross, Susan Coalition for One Boulder 12.5
Shoemaker, Andrew Coalition for One Boulder 50
Solutions, D&C Home Coalition for One Boulder 50
Sparn Architects, Sopher Coalition for One Boulder 176.88
Spinrad, Lauren Coalition for One Boulder 5
Stableford, Brooke Coalition for One Boulder 48.65
Strategy Group, Trestle Coalition for One Boulder 250
Toor, Will Coalition for One Boulder 23.65
Tree, Inc, Leanin Coalition for One Boulder 1000
Tremper, Amy Coalition for One Boulder 45
Trost, Peter Coalition for One Boulder 100
Wilson, Cindy Coalition for One Boulder 100
Wilson, D.B. Coalition for One Boulder 100
Yates, Bob Coalition for One Boulder 100
<!DOCTYPE html>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.js"></script>
<style>
path.link {
fill: none;
stroke: #666;
stroke-width: 1.5px;
}
circle {
fill: #ccc;
stroke: #fff;
stroke-width: 1.5px;
}
text {
fill: #000;
font: 10px sans-serif;
pointer-events: none;
}
</style>
<body>
<script>
// get the data
d3.csv("force.csv", function(error, links) {
var nodes = {};
// Compute the distinct nodes from the links.
links.forEach(function(link) {
link.source = nodes[link.source] ||
(nodes[link.source] = {name: link.source});
link.target = nodes[link.target] ||
(nodes[link.target] = {name: link.target});
link.value = +link.value;
});
var width = 960,
height = 500;
var force = d3.layout.force()
.nodes(d3.values(nodes))
.links(links)
.size([width, height])
.linkDistance(60)
.charge(-300)
.on("tick", tick)
.start();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
// build the arrow.
svg.append("svg:defs").selectAll("marker")
.data(["end"]) // Different link/path types can be defined here
.enter().append("svg:marker") // This section adds in the arrows
.attr("id", String)
.attr("viewBox", "0 -5 10 10")
.attr("refX", 15)
.attr("refY", -1.5)
.attr("markerWidth", 6)
.attr("markerHeight", 6)
.attr("orient", "auto")
.append("svg:path")
.attr("d", "M0,-5L10,0L0,5");
// add the links and the arrows
var path = svg.append("svg:g").selectAll("path")
.data(force.links())
.enter().append("svg:path")
// .attr("class", function(d) { return "link " + d.type; })
.attr("class", "link")
.attr("marker-end", "url(#end)");
// define the nodes
var node = svg.selectAll(".node")
.data(force.nodes())
.enter().append("g")
.attr("class", "node")
.call(force.drag);
// add the nodes
node.append("circle")
.attr("r", 5);
// add the text
node.append("text")
.attr("x", 12)
.attr("dy", ".35em")
.text(function(d) { return d.name; });
// add the curvy lines
function tick() {
path.attr("d", function(d) {
var dx = d.target.x - d.source.x,
dy = d.target.y - d.source.y,
dr = Math.sqrt(dx * dx + dy * dy);
return "M" +
d.source.x + "," +
d.source.y + "A" +
dr + "," + dr + " 0 0,1 " +
d.target.x + "," +
d.target.y;
});
node
.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")"; });
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment