Published
Edited
May 14, 2021
6 forks
Importers
72 stars
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
facet: { data, y: d => d.date.getUTCFullYear() },
fy: { tickPadding: 0, reverse: true },
x: { label: 'Week of year' },
y: { tickFormat: Plot.formatWeekday() },
color: { scheme: 'gnbu', type: 'log' },
marks: [
Plot.cell(data, {
x: d => d3.utcWeek.count(d3.utcYear(d.date), d.date),
y: d => d3.utcDay.count(d3.utcWeek(d.date), d.date),
title: d => `${d.views} page views on ${d.date}`,
fill: 'views'
})
],
width,
marginTop: 0,
marginRight: 50,
marginBottom: 35,
style: { background: '#fff' }
})
Insert cell
data = pageviewsPerArticle(article)
Insert cell
pageviewsPerArticle = (
article,
{
start = '20150801',
end = date2ts(new Date()),
access = 'all-access',
project = 'en.wikipedia',
granularity = 'daily',
agent = 'user'
} = {}
) => {
return fetch(
`https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/${project}/${access}/${agent}/${encodeURIComponent(
article
)}/${granularity}/${start}/${end}`
)
.then(res => res.json())
.then(data => {
if (!data.items) return data;
data.items.forEach(d => (d.date = ts2date(d.timestamp)));
return data.items;
});
}
Insert cell
date2ts = date =>
(
date.getUTCFullYear() * 1e6 +
(date.getUTCMonth() + 1) * 1e4 +
date.getUTCDate() * 1e2 +
date.getUTCHours()
).toString()
Insert cell
ts2date = ts =>
new Date(
Date.UTC(
+ts.slice(0, 4),
+ts.slice(4, 6) - 1,
+ts.slice(6, 8),
+ts.slice(8, 10)
)
)
Insert cell
import { legend } from '@d3/color-legend'
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