D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
benelsen
Full window
Github gist
GOCE orbit altitude since 2009
<!DOCTYPE html> <html> <head> <title></title> <style> body { font: 10px sans-serif; } .axis path, .axis line { fill: none; stroke: #000; shape-rendering: crispEdges; } .line { fill: none; stroke-width: 1.5px; } .line.semimajor { stroke: steelblue; } .line.apoapsis, .line.periapsis { opacity: 0.4; } .line.apoapsis { stroke: red; } .line.periapsis { stroke: green; } .brush .extent { stroke: #fff; fill-opacity: .125; shape-rendering: crispEdges; } .legend text { font: 14px sans-serif; } </style> </head> <body> <script src="https://d3js.org/d3.v3.js"></script> <script> var margin = {top: 10, right: 10, bottom: 125, left: 40}, margin2 = {top: 400, right: 10, bottom: 20, left: 40}, width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom, height2 = 500 - margin2.top - margin2.bottom; var parseDate = d3.time.format("%Y-%m-%d").parse; var x = d3.time.scale().range([0, width]), x2 = d3.time.scale().range([0, width]); var y = d3.scale.linear().range([height, 0]), y2 = d3.scale.linear().range([height2, 0]); var xAxis = d3.svg.axis().scale(x).orient("bottom"), xAxis2 = d3.svg.axis().scale(x).orient("bottom"); var yAxis = d3.svg.axis().scale(y).orient("left"), yAxis2 = d3.svg.axis().scale(y).orient("left"); var brush = d3.svg.brush() .x(x2) .y(y2) .on("brush", brushed); var lineSemimajor = d3.svg.line() .interpolate('basis') .x(function(d) { return x(d.date); }) .y(function(d) { return y(d.a); }); var linePeriapsis = d3.svg.line() .interpolate('basis') .x(function(d) { return x(d.date); }) .y(function(d) { return y(d.apoapsis); }); var lineApoapsis = d3.svg.line() .interpolate('basis') .x(function(d) { return x(d.date); }) .y(function(d) { return y(d.periapsis); }); var line2 = d3.svg.line() .interpolate('basis') .x(function(d) { return x2(d.date); }) .y(function(d) { return y2(d.a); }); var svg = d3.select("body").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom); svg.append("defs").append("clipPath") .attr("id", "clip") .append("rect") .attr("width", width) .attr("height", height); var focus = svg.append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); var context = svg.append("g") .attr("transform", "translate(" + margin2.left + "," + margin2.top + ")"); var legend = svg.append("g") .attr("class", "legend") .attr("transform", "translate(" + (width - 100) + ",25)"); var lSemiMajor = legend.append("g") .attr("transform", "translate(0,0)") lSemiMajor.append("rect") .attr("width", 12) .attr("height", 12) .attr("fill", "steelblue"); lSemiMajor.append("text") .attr("y", 11) .attr("x", 16) .text("Semi-Major axis"); var lApoapsis = legend.append("g") .attr("transform", "translate(0,20)") lApoapsis.append("rect") .attr("width", 12) .attr("height", 12) .attr("fill", "red"); lApoapsis.append("text") .attr("y", 11) .attr("x", 16) .text("Apogee"); var lPeriapsis = legend.append("g") .attr("transform", "translate(0,40)") lPeriapsis.append("rect") .attr("width", 12) .attr("height", 12) .attr("fill", "green"); lPeriapsis.append("text") .attr("y", 11) .attr("x", 16) .text("Perigee"); d3.csv("goce.csv", function(error, data) { data.forEach( function(d) { d.date = new Date(+d.date); d.T = +d.T; d.a = +d.a; d.apoapsis = +d.apoapsis; d.periapsis = +d.periapsis; }); x.domain(d3.extent(data, function(d) { return d.date; })).nice(d3.time.week); y.domain([ d3.min(data, function(d) { return d.periapsis; }), d3.max(data, function(d) { return d.apoapsis; }) ]).nice(); x2.domain(x.domain()); y2.domain(d3.extent(data, function(d) { return d.a; })); focus.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + height + ")") .call(xAxis); focus.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("Altitude [km]"); focus.append("path") .datum(data) .attr("class", "line semimajor") .attr("clip-path", "url(#clip)") .attr("d", lineSemimajor); focus.append("path") .datum(data) .attr("class", "line apoapsis") .attr("clip-path", "url(#clip)") .attr("d", linePeriapsis); focus.append("path") .datum(data) .attr("class", "line periapsis") .attr("clip-path", "url(#clip)") .attr("d", lineApoapsis); context.append("path") .datum(data) .attr("class", "line semimajor") .attr("d", line2); context.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + height2 + ")") .call(xAxis2); context.append("g") .attr("class", "x brush") .call(brush); }); function brushed() { var extent = brush.extent(); var xExt = extent.map( function(d) { return d[0]; }), yExt = extent.map( function(d) { return d[1]; }); x.domain(brush.empty() ? x2.domain() : xExt); y.domain(brush.empty() ? y2.domain() : yExt); focus.select(".line.semimajor").attr("d", lineSemimajor); focus.select(".line.apoapsis").attr("d", lineApoapsis); focus.select(".line.periapsis").attr("d", linePeriapsis); focus.select(".x.axis").call(xAxis); focus.select(".y.axis").call(yAxis); } </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js