Public
Edited
Oct 5, 2023
Insert cell
Insert cell
Insert cell
Insert cell
meta = fetch(
`https://api.targomo.com/statistics/collection/meta/79?key=${targomoKey()}`
).then((response) => response.json())
Insert cell
statsRequestConfig = ({
statisticIds: [statistic.statistic_id], // all the statistics we want to include in the results
statisticCollectionId: 79,
edgeWeight: "time",
travelType: "bike",
maxEdgeWeight: 900,
sources: [s1, s2],
serviceUrl: "https://api.targomo.com/westcentraleurope",
serviceKey: targomoKey()
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dependent = fetch(
`https://api.targomo.com/statistics/charts/dependent?apiKey=${targomoKey()}&serviceUrl=${
statsRequestConfig.serviceUrl
}`,
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(statsRequestConfig)
}
).then((response) => response.json())
Insert cell
independent = fetch(
`https://api.targomo.com/statistics/charts/independent?apiKey=${targomoKey()}&serviceUrl=${
statsRequestConfig.serviceUrl
}`,
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(statsRequestConfig)
}
).then((response) => response.json())
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
sourceDependent = ({
s1: Math.round(
Object.values(
dependent.individualStatistics.s1.statistics[statistic.statistic_id]
).reduce((acc, cur) => {
return acc + cur;
}, 0)
),
s2: Math.round(
Object.values(
dependent.individualStatistics.s2.statistics[statistic.statistic_id]
).reduce((acc, cur) => {
return acc + cur;
}, 0)
)
})
Insert cell
Insert cell
Insert cell
data = fetch("https://api.weather.gov/gridpoints/OKX/33,37/forecast").then((response) => response.json())
Insert cell
MapSources = new mapSources([
{ lng: 2.350838, lat: 48.861653, id: "s1" },
{ lng: 2.362131, lat: 48.858889, id: "s2" }
])
Insert cell
class mapSources {
sources = [];
constructor(sources) {
this.sources = sources;
}
getSource(id) {
return this.sources.find((d) => d.id === id);
}
getCenter() {
const lng =
this.sources.reduce((acc, cur) => {
acc += cur.lng;
return acc;
}, 0) / this.sources.length;
const lat =
this.sources.reduce((acc, cur) => {
acc += cur.lat;
return acc;
}, 0) / this.sources.length;

return { lng, lat };
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more