Created
August 5, 2014 19:17
-
-
Save peachyo/4f6ed17df8459f5fe216 to your computer and use it in GitHub Desktop.
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> | |
#tooltip { | |
color: white; | |
opacity: .8; | |
background: #333; | |
padding: 5px; | |
border: 1px solid lightgrey; | |
border-radius: 5px; | |
position: absolute; | |
z-index: 10; | |
visibility: hidden; | |
pointer-events: none; | |
} | |
#circle circle { | |
fill: none; | |
pointer-events: all; | |
} | |
.group path { | |
fill-opacity: .5; | |
} | |
path.chord { | |
stroke: #000; | |
stroke-width: .25px; | |
} | |
#circle:hover path.fade { | |
display: none; | |
} | |
</style> | |
<body> | |
<h2>Worldcup 2014 Matches</h2> | |
<div id="tooltip"></div> | |
<script src="http://d3js.org/d3.v2.min.js?2.8.1"></script> | |
<script> | |
var width = 720, | |
height = 720, | |
outerRadius = Math.min(width, height) / 2 - 10, | |
innerRadius = outerRadius - 24; | |
var formatPercent = d3.format(".1%"); | |
var arc = d3.svg.arc() | |
.innerRadius(innerRadius) | |
.outerRadius(outerRadius); | |
var layout = d3.layout.chord() | |
.padding(.04) | |
.sortSubgroups(d3.descending) | |
.sortChords(d3.ascending); | |
var path = d3.svg.chord() | |
.radius(innerRadius); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("g") | |
.attr("id", "circle") | |
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); | |
svg.append("circle") | |
.attr("r", outerRadius); | |
d3.csv("teams.csv", function(cities) { | |
d3.json("matrix.json", function(matrix) { | |
// Compute the chord layout. | |
layout.matrix(matrix); | |
// Add a group per neighborhood. | |
var group = svg.selectAll(".group") | |
.data(layout.groups) | |
.enter().append("g") | |
.attr("class", "group") | |
.on("mouseover", mouseover); | |
// Add the group arc. | |
var groupPath = group.append("path") | |
.attr("id", function(d, i) { return "group" + i; }) | |
.attr("d", arc) | |
.style("fill", function(d, i) { return cities[i].color; }); | |
// Add a text label. | |
var groupText = group.append("text") | |
.attr("x", 6) | |
.attr("dy", 10); | |
groupText.append("textPath") | |
.attr("xlink:href", function(d, i) { return "#group" + i; }) | |
.text(function(d, i) { return cities[i].name; }); | |
// Remove the labels that don't fit. :( | |
groupText.filter(function(d, i) { return groupPath[0][i].getTotalLength() / 2 - 16 < this.getComputedTextLength(); }) | |
.remove(); | |
// Add the chords. | |
var chord = svg.selectAll(".chord") | |
.data(layout.chords) | |
.enter().append("path") | |
.attr("class", "chord") | |
.style("fill", function(d) { | |
console.log(d); | |
return cities[d.source.index].color; }) | |
.attr("d", path) | |
.on("mouseover", mouseoverd) | |
.on("mouseout", mouseouted); | |
function mouseoverd(d, i) { | |
d3.select("#tooltip") | |
.style("visibility", "visible") | |
.html(cities[d.source.index].name | |
+ "-" + cities[d.target.index].name | |
+ ": " + d.source.value + "-" + d.target.value) | |
.style("top", function () { return (d3.event.pageY + 50)+"px"}) | |
.style("left", function () { return (d3.event.pageX - 50)+"px";}); | |
} | |
function mouseouted(d) { | |
d3.select("#tooltip").style("visibility", "hidden"); | |
} | |
function mouseover(d,i){ | |
chord.classed("fade", function(p) { | |
return p.source.index != i && p.target.index != i; | |
}); | |
} | |
}); | |
}); | |
</script> | |
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
[ | |
[0,1,0,7,0,0,0,1,1,0,2,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0], | |
[0,0,0,0,0,1,0,0,0,1,0,3,0,0,0,0,0,0,0,0,0,0,2,1,0,0,0,0,0,0,0,0], | |
[0,0,0,3,0,0,0,0,0,0,0,0,0,2,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
[1,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,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0,0,0,0], | |
[2,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
[0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0], | |
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0], | |
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0], | |
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0], | |
[0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0], | |
[0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0], | |
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0], | |
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0], | |
[0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
[0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
[0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
[0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0] | |
] |
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
name | color | |
---|---|---|
Germany | #9ACD32 | |
Argentina | #377DB8 | |
Neitherlands | #F5DEB3 | |
Brazil | #EE82EE | |
Costa Rica | #40E0D0 | |
Belgium | #FF6347 | |
Colombia | #D8BFD8 | |
France | #D2B48C | |
USA | #4682B4 | |
Switzerland | #00FF7F | |
Algeria | #FFFAFA | |
Nigeria | #708090 | |
Greece | #708090 | |
Mexico | #6A5ACD | |
Uruguay | #87CEEB | |
Chile | #A0522D | |
Russia | #FFF5EE | |
Korea Republic | #2E8B57 | |
Portugal | #F4A460 | |
Ghana | #FA8072 | |
Ecuador | #e7e1ef | |
Honduras | #c994c7 | |
Bosnia Herzegovina | #dd1c77 | |
Iran | #f7fcb9 | |
Cote D'Ivorie | #addd8e | |
Japan | #31a354 | |
England | #efedf5 | |
Italy | #bcbddc | |
Camaroon | #756bb1 | |
Australia | #fee8c8 | |
Spain | #fdbb84 | |
Croatia | #e34a33 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment