Published
Edited
Jun 4, 2018
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
wau = {
const lastSunday = addDays(new Date(), -(new Date()).getDay())
const rangeStart = addDays(lastSunday, (-7 * WEEK_SPAN) + 1)
const url =
`https://funfunautomator.herokuapp.com/wau` +
`?start=${dateIso8601(rangeStart)}&end=${dateIso8601(lastSunday)}`
return fetch(url)
.then(response => response.json())
.then(rows => rows.map(row => ({value: row[0], year: row[1], week: row[2] })))
.then(weeks => weeks.reduce((weekMap, week) => {
const key = firstDateOfWeekISO8601(week.year, week.week)
weekMap[key] = weekMap[key] ? weekMap[key] + week.value : week.value
return weekMap
}, {}))
.then(weekMap => Object.keys(weekMap).map(key => ({
date: key,
value: weekMap[key]
})))
}
Insert cell
Insert cell
mau = {
const lastDayLastMonth = new Date((new Date()).getFullYear(),(new Date()).getMonth(), 0)
const rangeStart = addDays(lastDayLastMonth, (-7 * WEEK_SPAN) + 1)
const url = `https://funfunautomator.herokuapp.com/mau?start=${dateIso8601(rangeStart)}&end=${dateIso8601(lastDayLastMonth)}`
return fetch(url)
.then(response => response.json())
.then(rows => rows.map(row => ({
value: row[0],
date: row[1] + '-' + leftpad(row[2], 2) + '-01'
})))
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Shows a graph of a given time series. Accepts C3 columns as argument
baseChart = {
// force dependencies
d3;
css;
return async function* (columns, {yOpts, xOpts} = {}) {
const divId = 'tsg' + Math.floor(Math.random()*100000000)
const div = html`<div id="${divId}" style="height: 250px"></div>`
yield div
const defaultXOpts = {
type: 'timeseries',
tick: { format: '%Y-%m-%d' }
}
const defaultYOpts = {
label: {
text: 'DEFAULT LABEL'
}
}
c3.generate({
bindto: '#' + divId,
data: {
x: 'x',
columns
},
legend: {
show: false
},
axis: {
x: {
...defaultXOpts,
...xOpts
},
y: {
...defaultYOpts,
...yOpts
}
}
})
}
}
Insert cell
Insert cell
Insert cell
Insert cell
DateInfo = browserify('date-info')
Insert cell
Insert cell
Insert cell
d3 = require("https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.js")
Insert cell
c3 = require("https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.18/c3.js")
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