All data hastily copied from formula1.com.
Last active
August 29, 2015 14:16
-
-
Save sconnors37/b99070b055f125c9dff1 to your computer and use it in GitHub Desktop.
F1 Testing Data, sortable
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 | value | date | team | |
---|---|---|---|---|
Rosberg | 3463 | 2015-03-05 | mercedes | |
Hamilton | 2434 | 2015-03-05 | mercedes | |
Bottas | 2255 | 2015-03-05 | williams | |
Massa | 2258 | 2015-03-05 | williams | |
Vettel | 2768 | 2015-03-05 | ferrari | |
Raikkonen | 2655 | 2015-03-05 | ferrari | |
Button | 1033 | 2015-03-05 | mclaren | |
Alonso | 536 | 2015-03-05 | mclaren | |
Ricciardo | 2243 | 2015-03-05 | red_bull | |
Kvyat | 2109 | 2015-03-05 | red_bull | |
Ericsson | 2732 | 2015-03-05 | sauber | |
Nasr | 2976 | 2015-03-05 | sauber | |
Maldonado | 2231 | 2015-03-05 | lotus | |
Grosjean | 1640 | 2015-03-05 | lotus | |
Sainz | 2700 | 2015-03-05 | toro_rosso | |
Verstappen | 2834 | 2015-03-05 | toro_rosso | |
Hulkenberg | 1262 | 2015-03-05 | force_india | |
Perez | 1327 | 2015-03-05 | force_india |
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> | |
body { | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
position: relative; | |
width: 960px; | |
} | |
.axis text { | |
font: 10px sans-serif; | |
} | |
.axis path, | |
.axis line { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} | |
.bar { | |
fill-opacity: .9; | |
} | |
.x.axis path { | |
display: none; | |
} | |
label { | |
position: absolute; | |
top: 10px; | |
right: 10px; | |
} | |
</style> | |
<label><input type="checkbox"> Sort values</label> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var margin = {top: 20, right: 20, bottom: 30, left: 40}, | |
width = 960 - margin.left - margin.right, | |
height = 500 - margin.top - margin.bottom; | |
var x = d3.scale.ordinal() | |
.rangeRoundBands([0, width], .1, 1); | |
var y = d3.scale.linear() | |
.range([height, 0]); | |
var color = d3.scale.ordinal() | |
.domain(["williams", "mercedes", "ferrari", "mclaren", "red_bull", "sauber", "lotus", "toro_rosso", "force_india"]) | |
.range(["grey", "steelblue","red", "darkorange", "purple", "blue", "black", "violet", "orangered"]); | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.orient("bottom"); | |
var yAxis = d3.svg.axis() | |
.scale(y) | |
.orient("left") | |
.ticks(10); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width + margin.left + margin.right) | |
.attr("height", height + margin.top + margin.bottom) | |
.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
d3.tsv("data.tsv", function(error, data) { | |
data.forEach(function(d) { | |
d.value = +d.value; | |
}); | |
x.domain(data.map(function(d) { return d.name; })); | |
y.domain([0, d3.max(data, function(d) { return d.value; })]); | |
svg.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(xAxis); | |
svg.append("g") | |
.attr("class", "y axis") | |
.call(yAxis) | |
.append("text") | |
.attr("transform", "rotate(-90)") | |
.attr("y", 6) | |
.attr("dy", ".71em") | |
.style("text-anchor", "end") | |
.text("Total Miles"); | |
svg.selectAll(".bar") | |
.data(data) | |
.enter().append("rect") | |
.attr("class", "bar") | |
.style("fill", function(d) { return color(d.team); }) | |
.attr("x", function(d) { return x(d.name); }) | |
.attr("width", x.rangeBand()) | |
.attr("y", function(d) { return y(d.value); }) | |
.attr("height", function(d) { return height - y(d.value); }); | |
d3.select("input").on("change", change); | |
var sortTimeout = setTimeout(function() { | |
d3.select("input").property("checked", true).each(change); | |
}, 2000); | |
function change() { | |
clearTimeout(sortTimeout); | |
// Copy-on-write since tweens are evaluated after a delay. | |
var x0 = x.domain(data.sort(this.checked | |
? function(a, b) { return b.value - a.value; } | |
: function(a, b) { return d3.ascending(a.name, b.name); }) | |
.map(function(d) { return d.name; })) | |
.copy(); | |
var transition = svg.transition().duration(750), | |
delay = function(d, i) { return i * 50; }; | |
transition.selectAll(".bar") | |
.delay(delay) | |
.attr("x", function(d) { return x0(d.name); }); | |
transition.select(".x.axis") | |
.call(xAxis) | |
.selectAll("g") | |
.delay(delay); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment