Built with blockbuilder.org
xxxxxxxxxx
<meta charset="utf-8">
<style>
body {
font: 14px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #e5e5e5;
shape-rendering: crispEdges;
}
.axis path {
display: none;
}
.line {
fill: none;
stroke-width: 1px;
opacity: 1;
}
.androgs {
fill: none;
stroke: #aaa;
stroke-linejoin: round;
stroke-linecap: round;
stroke-width: 1.5px;
}
.androg--hover {
stroke: #000;
stroke-width: 20px
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var margin = {top: 60, right: 80, bottom: 60, left: 80},
width = 700 - margin.left - margin.right,
height = 460 - margin.top - margin.bottom;
var x = d3.scale.linear()
.range([0, width])
.domain([12,1]);
var y = d3.scale.linear()
.range([height, 0])
.domain([0,1]);
var color = d3.scale.ordinal()
.range(["#e4b31f", "#9d1422", "#f9db9e", "#f4a3a5", "#f1624f"])
.domain(["A","B","C","D","E"]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.tickFormat(d3.format("d"));
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.ticks(5)
.tickSize(-width, 0, 0);
var line = d3.svg.line()
.interpolate("basis")
.x(function(d) { return x(d.rank); })
.y(function(d) { return y(d.cohort); });
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.csv("wins.txt", function(error, data) {
if (error) throw error;
data.forEach(function (d,i) {
d.rank = +d.rank;
d.A = +d.A;
d.B = +d.B;
d.C = +d.C;
d.D = +d.D;
d.E = +d.E;
})
var keys = d3.keys(data[0]).filter(function(key) { return key !== "rank"; });
var cohortLines = keys.map(function(name) {
return {
name: name,
values: data.map(function(d) {
return {
rank: d.rank,
cohort: d[name]};
})
};
});
//Append axes
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
//Append the lines
var lines = svg.selectAll(".lines")
.data(cohortLines)
.enter().append("g")
.attr("class", "lines");
//Very thick barely visible line
lines.append("path")
.attr("class", "line")
.attr("d", function(d) { return line(d.values); })
.style("stroke", function(d) { return color(d.name); })
.style("stroke-width", 10)
.style("opacity", 0.05)
.on("mouseover", function() {
d3.select(this)
.style("stroke-width", 20)
.classed("androg--hover", true )
})
.on("mouseout", function() {
d3.select(this)
.style("stroke-width", 10)
.classed("androg--hover", true)
})
;
//Thick rather difficult to see line
lines.append("path")
.attr("class", "line")
.attr("d", function(d) { return line(d.values); })
.style("stroke", function(d) { return color(d.name); })
.style("stroke-width", 6)
.style("opacity", 0.1)
;
//Actual full opacity thin line
lines.append("path")
.attr("class", "line")
.attr("d", function(d) { return line(d.values); })
.style("stroke", function(d) { return color(d.name); })
.style("stroke-width", 1.5)
;
});
</script>
https://d3js.org/d3.v3.min.js