Skip to content

Instantly share code, notes, and snippets.

@johnwalley
Last active June 22, 2022 15:39
Show Gist options
  • Save johnwalley/a68b44fcc9f1f598ebdc00262b408a11 to your computer and use it in GitHub Desktop.
Save johnwalley/a68b44fcc9f1f598ebdc00262b408a11 to your computer and use it in GitHub Desktop.
Half-marathon times
license: mit

My half-marathon times.

license: gpl-3.0
Date Event Time Position
05/10/2008 Great North Run 02:55:23 34282
19/09/2010 Great North Run 02:16:27 21393
18/09/2011 Great North Run 02:20:48 24127
16/09/2012 Great North Run 02:11:42 22045
10/09/2015 Great North Run 02:26:58 26421
28/02/2016 Cambridge Half Marathon 02:13:22 4194
11/09/2016 Great North Run 02:11:29 17536
04/03/2018 Cambridge Half Marathon 2:27:12 6229
09/09/2018 Great North Run 02:33:14 27100
08/09/2019 Great North Run 02:43:59 32779
08/03/2020 Cambridge Half Marathon 02:27:04 9939
06/03/2022 Cambridge Half Marathon 02:46:00 9618
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 12px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.dot {
stroke: #000;
}
</style>
<body>
<script src="//d3js.org/d3.v3.js"></script>
<script>
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.time.scale()
.range([0, width]);
var y = d3.time.scale()
.range([height, 0]);
var color = d3.scale.category10();
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
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) {
if (error) throw error;
data.forEach(function(d) {
d.time = d3.time.format("%X").parse(d.Time);
d.date = d3.time.format("%d/%m/%Y").parse(d.Date);
});
x.domain(d3.extent(data, function(d) { return d.date; })).nice();
y.domain(d3.extent(data, function(d) { return d.time; })).nice();
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", -6)
.style("text-anchor", "end")
.text("Date");
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Time")
svg.selectAll(".dot")
.data(data)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 6)
.attr("cx", function(d) { return x(d.date); })
.attr("cy", function(d) { return y(d.time); })
.style("fill", function(d) { return color(d.Event); });
var legend = svg.selectAll(".legend")
.data(color.domain())
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", color);
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d; });
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment