Published
Edited
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = {
const timeParser = d3.timeParse("%d %b %Y");
const csvString = await FileAttachment("Cells in Journal_ Getting Started with Data Viz - Journal cells - 12 Jun 2020.csv").text();
const rowConversionFunction = ({
"Title": title,
"URL": url,
"Number of cells": y,
"Date": x
}) => ({
title,
url,
x: timeParser(x),
dayOfWeek: timeParser(x),
y: +y
});
let dataObjectTarget = d3.csvParse(csvString, rowConversionFunction);
dataObjectTarget = d3.rollups(dataObjectTarget, v => d3.format("d")(d3.mean(v, d => d.y)), d => d3.timeFormat("%a")(d.dayOfWeek))
.map(d => ({x: d[0], y: d[1] }));
const extraPropertiesSource = {xAxisLabel: "Day of the week", yAxisLabel: "Cells (mean)", caption: "This bar chart shows average cells written each day of the week, where Saturday is highlight with the highest mean cells written of 42."};
return Object.assign(dataObjectTarget, extraPropertiesSource);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
x = d3.scaleBand()
.domain(data.map(d => d.x))
.range([margin.left, width * 1.3 - margin.right])
.padding(0.1)
Insert cell
y = d3.scaleLinear()
.domain([0, d3.max(data, d => d.y)]).nice()
.range([height - margin.bottom, margin.top]);
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).tickSizeOuter(0));
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(g => g.select(".domain").remove())
.call(g => g.select(".tick:last-of-type text").clone()
.attr("x", 3)
.attr("text-anchor", "start")
.style("font-weight", 800)
.text(data.yAxisLabel));
Insert cell
height = 450;
Insert cell
Insert cell
assistant = html`<style>
@import url('https://fonts.googleapis.com/css2?family=Assistant:wght@300;800&display=swap');

text {
fill: #282541;
font: 300 16px/1.4 "Assistant", sans-serif;
}
.domain {
stroke: #cdcccf;
}
.tick line {
stroke: #cdcccf;
}
</style>
`
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