-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* improve default templates * fix test, docs
- Loading branch information
Showing
10 changed files
with
145 additions
and
163 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,16 @@ | ||
import * as Plot from "npm:@observablehq/plot"; | ||
import * as d3 from "npm:d3"; | ||
|
||
export function timeline(events) { | ||
export function timeline(events, {width, height} = {}) { | ||
return Plot.plot({ | ||
insetTop: 30, | ||
insetBottom: 10, | ||
insetRight: 10, | ||
height: 250, | ||
x: { | ||
domain: d3.extent(events, (d) => d["year"]), | ||
label: "Year", | ||
nice: true, | ||
}, | ||
y: { axis: null }, | ||
width, | ||
height, | ||
marginTop: 30, | ||
x: {nice: true, label: null, tickFormat: ""}, | ||
y: {axis: null}, | ||
marks: [ | ||
Plot.axisX({tickFormat: d3.format(".0f")}), | ||
Plot.ruleX(events, {x: "year", y: "y", stroke: "#eee", strokeWidth: 2}), | ||
Plot.ruleY([0], {stroke: "#eee"}), | ||
Plot.dot(events, {x: "year", y: "y", fill: "currentColor", r: 5}), | ||
Plot.text(events, { | ||
x: "year", | ||
y: "y", | ||
text: "name", | ||
dy: -20, | ||
lineWidth: 10, | ||
fontSize: 12, | ||
}), | ||
Plot.ruleX(events, {x: "year", y: "y", markerEnd: "dot", strokeWidth: 2.5}), | ||
Plot.ruleY([0]), | ||
Plot.text(events, {x: "year", y: "y", text: "name", lineAnchor: "bottom", dy: -10, lineWidth: 10, fontSize: 12}) | ||
] | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{"name": "Sputnik 1", "year": 1957, "y": 10}, | ||
{"name": "Apollo 11", "year": 1969, "y": 20}, | ||
{"name": "Viking 1 and 2", "year": 1975, "y": 30}, | ||
{"name": "Space Shuttle Columbia", "year": 1981, "y": 40}, | ||
{"name": "Hubble Space Telescope", "year": 1990, "y": 50}, | ||
{"name": "ISS Construction", "year": 1998, "y": 60} | ||
] |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import {csvFormat, tsvParse} from "d3-dsv"; | ||
import {utcParse} from "d3-time-format"; | ||
|
||
async function text(url) { | ||
const response = await fetch(url); | ||
if (!response.ok) throw new Error(`fetch failed: ${response.status}`); | ||
return response.text(); | ||
} | ||
|
||
// “Top” vehicles | ||
const TOP_LAUNCH_VEHICLES = new Set([ | ||
"Falcon9", | ||
"R-7", | ||
"R-14", | ||
"Thor", | ||
"DF5", | ||
"R-36", | ||
"Proton", | ||
"Titan", | ||
"Zenit", | ||
"Atlas" | ||
]); | ||
|
||
// “Top” launching states | ||
const TOP_STATES_MAP = new Map([ | ||
["US", "United States"], | ||
["SU", "Soviet Union"], | ||
["RU", "Russia"], | ||
["CN", "China"] | ||
]); | ||
|
||
// Load and parse launch vehicles. | ||
const launchVehicles = tsvParse(await text("https://planet4589.org/space/gcat/tsv/tables/lv.tsv")); | ||
|
||
// Construct map to lookup vehicle family from name. | ||
const launchVehicleFamilyMap = new Map(launchVehicles.map((d) => [d["#LV_Name"], d.LV_Family.trim()])); | ||
|
||
// Reduce cardinality by mapping smaller states to “Other”. | ||
function normalizeState(d) { | ||
return TOP_STATES_MAP.get(d) ?? "Other"; | ||
} | ||
|
||
// Reduce cardinality by mapping smaller launch families to “Other”. | ||
function normalizeFamily(d) { | ||
const family = launchVehicleFamilyMap.get(d); | ||
return TOP_LAUNCH_VEHICLES.has(family) ? family : "Other"; | ||
} | ||
|
||
// Parse dates! | ||
const parseDate = utcParse("%Y %b %_d"); | ||
|
||
// Load and parse launch-log and trim down to smaller size. | ||
const launchHistory = tsvParse(await text("https://planet4589.org/space/gcat/tsv/derived/launchlog.tsv"), (d) => ({ | ||
date: parseDate(d.Launch_Date.slice(0, 11)), | ||
state: normalizeState(d.LVState), | ||
stateId: d.LVState, | ||
family: normalizeFamily(d.LV_Type) | ||
})).filter((d) => d.date != null); | ||
|
||
// Write out csv formatted data. | ||
process.stdout.write(csvFormat(launchHistory)); |
This file was deleted.
Oops, something went wrong.
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
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
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
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