Published
Edited
Dec 19, 2018
Importers
Insert cell
Insert cell
Insert cell
loadTimetable = (url) => {
let x = 42
return d3.tsv(url)
.then ((tsOrig) => {
// Change column names ("." inherited from the R world) and turn some text fields into numbers.
let columns = _.keys(tsOrig[0]);
let colNewNames = {}
_.each(columns, (c)=>{
if(c.indexOf('.') >0){
colNewNames[c] = c.replace(/\./g, '_');
}
});

// transform the row element names accordingly to the mapping defained above
// transform numerical fields
let ts = _.map(tsOrig,
(rOrig) => {
let r = _.clone(rOrig)
_.each(colNewNames,
(newName, oldName) => {
r[newName]=r[oldName]
delete r[oldName]
})
r.trip_distance = +r.trip_distance
r.h_departure_time = +r.h_departure_time
r.next_trip_distance = +r.next_trip_distance
r.next_h_arrival_time = +r.next_h_arrival_time
r.q80_next_delta_arrival_min = +r.q80_next_delta_arrival_min
return r
})

return ts
})
}
Insert cell
Insert cell
dimensions = {
return {
overall: {
height: 400,
width: 800
},
margins:{
left: 100,
right: 10,
top: 10,
bottom: 30
}
}
}
Insert cell
newSVG = () => {
return d3.select(DOM.svg(dimensions.overall.width, dimensions.overall.height));
}

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more