Space station orbit data in Two-Element Format. Data collected at 1:40am PDT August 8, 2015.
forked from syntagmatic‘s block: Space Stations
<!DOCTYPE html>
<meta charset="utf-8">
<title>Space Stations</title>
<style>
svg {
font: 8px sans-serif;
}
.foreground path {
fill: none;
stroke: #222;
stroke-opacity: 0.4;
pointer-events: none;
stroke-width: 1px;
}
.axis .title {
font-size: 8px;
font-weight: bold;
text-transform: uppercase;
transform: rotate(-12deg) translate(-5px,-6px);
}
.axis line,
.axis path {
fill: none;
stroke: #000;
stroke-width: 1px;
}
.brush .extent {
fill-opacity: .3;
stroke: #fff;
stroke-width: 1px;
}
pre {
width: 900px;
margin: 10px 30px;
tab-size: 25;
font-size: 12px;
overflow: auto;
}
</style>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>
var margin = {top: 50, right: 80, bottom: 20, left: 100},
width = 960 - margin.left - margin.right,
height = 340 - margin.top - margin.bottom;
var types = {
"Number": {
key: "Number",
coerce: function(d) { return +d; },
extent: d3.extent,
within: function(d, extent) { return extent[0] <= d && d <= extent[1]; },
defaultScale: d3.scale.linear().range([height, 0])
},
"String": {
key: "String",
coerce: String,
extent: function (data) { return data.sort(); },
within: function(d, extent, dim) { return extent[0] <= dim.scale(d) && dim.scale(d) <= extent[1]; },
defaultScale: d3.scale.ordinal().rangePoints([0, height])
},
"Date": {
key: "Date",
coerce: function(d) { return new Date(d); },
extent: d3.extent,
within: function(d, extent) { return extent[0] <= d && d <= extent[1]; },
defaultScale: d3.time.scale().range([0, height])
}
};
var dimensions = [
{
key: "name",
description: "Name",
type: types["String"]
},
{
key: "satelliteNumber",
description: "SatelliteNumber",
type: types["String"]
},
{
key: "classification",
description: "Classification",
type: types["String"]
},
{
key: "launchNumber",
description: "Launch Number",
type: types["Number"]
},
{
key: "launchPiece",
description: "Launch Piece",
type: types["String"]
},
{
key: "epochYear",
description: "Epoch Year",
type: types["String"]
},
{
key: "epochDay",
description: "Epoch Day",
type: types["Number"],
domain: [0,360]
},
{
key: "inclination",
description: "inclination",
type: types["Number"],
domain: [0,90]
},
{
key: "rightAscension",
description: "Right Ascension",
type: types["Number"],
domain: [0,360]
},
{
key: "eccentricity",
description: "Eccentricity",
type: types["Number"],
domain: [0,0.002]
},
{
key: "perigee",
description: "Perigee",
type: types["Number"],
domain: [0,360]
},
{
key: "meanAnomaly",
description: "Mean Anomaly",
type: types["Number"],
domain: [0,360]
},
{
key: "meanMotion",
description: "Mean Motion",
type: types["Number"]
},
{
key: "firstDerivMeanMotion",
description: "First Deriv Mean Motion",
type: types["Number"]
}
];
var x = d3.scale.ordinal()
.domain(dimensions.map(function(dim) { return dim.key; }))
.rangePoints([0, width]);
var line = d3.svg.line()
.defined(function(d) { return !isNaN(d[1]); });
var yAxis = d3.svg.axis()
.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 + ")");
var output = d3.select("body").append("pre");
var foreground = svg.append("g")
.attr("class", "foreground");
var axes = svg.selectAll(".axis")
.data(dimensions)
.enter().append("g")
.attr("class", "axis")
.attr("transform", function(d) { return "translate(" + x(d.key) + ")"; });
d3.csv("stations.csv", function(error, data) {
if (error) throw error;
data.forEach(function(d) {
dimensions.forEach(function(p) {
d[p.key] = p.type.coerce(d[p.key]);
});
});
// type/dimension default setting happens here
dimensions.forEach(function(dim) {
if (!("domain" in dim)) {
// detect domain using dimension type's extent function
dim.domain = d3.functor(dim.type.extent)(data.map(function(d) { return d[dim.key]; }));
// TODO - this line only works because the data encodes data with integers
// Sorting/comparing should be defined at the type/dimension level
dim.domain.sort(function(a,b) {
return a - b;
});
}
if (!("scale" in dim)) {
// use type's default scale for dimension
dim.scale = dim.type.defaultScale.copy();
}
dim.scale.domain(dim.domain);
});
foreground.selectAll("path")
.data(data)
.enter().append("path")
.attr("d", draw)
.style("stroke", function(d) { return "#6ac"; });
axes.append("g")
.attr("class", "axis")
.each(function(d) {
var renderAxis = "axis" in d
? d.axis.scale(d.scale) // custom axis
: yAxis.scale(d.scale); // default axis
d3.select(this).call(renderAxis);
})
.append("text")
.attr("class", "title")
.attr("text-anchor", "start")
.text(function(d) { return "description" in d ? d.description : d.key; });
// Add and store a brush for each axis.
axes.append("g")
.attr("class", "brush")
.each(function(d) {
d3.select(this).call(d.brush = d3.svg.brush()
.y(d.scale)
.on("brushstart", brushstart)
.on("brush", brush));
})
.selectAll("rect")
.attr("x", -8)
.attr("width", 16);
output.text(d3.tsv.format(data));
function draw(d) {
return line(dimensions.map(function(dim) {
return [x(dim.key), dim.scale(d[dim.key])];
}));
}
function brushstart() {
d3.event.sourceEvent.stopPropagation();
}
// Handles a brush event, toggling the display of foreground lines.
function brush() {
var actives = dimensions.filter(function(p) { return !p.brush.empty(); }),
extents = actives.map(function(p) { return p.brush.extent(); });
var selected = [];
d3.selectAll(".foreground path").style("display", function(d) {
if (actives.every(function(dim, i) {
// test if point is within extents for each active brush
return dim.type.within(d[dim.key], extents[i], dim);
})) {
selected.push(d);
return null;
}
return "none";
});
output.text(d3.tsv.format(selected));
}
});
</script>