Published
Edited
Jul 8, 2021
1 star
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
Insert cell
trans = (x, y, k) => {
if (k) return `translate(${[x, y, k].join(',')})`;
return `translate(${[x, y].join(',')})`;
}
Insert cell
getKey = ([k, v]) => k
Insert cell
getValue = ([k, v]) => v
Insert cell
cfg = {
const c = {
height: 600,
width: width,
marginTop: 50,
marginBottom: 50,
marginLeft: 50,
marginRight: 50
};
return {
...c,
chartWidth: c.width - (c.marginTop + c.marginBottom),
chartHeight: c.height - (c.marginLeft + c.marginRight)
};
}
Insert cell
scaleX = d3
.scaleLinear()
.domain([minValue, maxValue])
.range([0, cfg.chartWidth]);

Insert cell
scaleAltY = {
const minKey = d3.min(Array.from(newData.keys()).map(n => Number(n)));
const maxKey = d3.max(Array.from(newData.keys()).map(n => Number(n)));
return d3
.scaleLinear()
.domain([minKey, maxKey])
.range([0, cfg.chartHeight]);
}
Insert cell
maxValue = d3.max(newData.values())
Insert cell
minValue = d3.min(newData.values())
Insert cell
axisScaleY = d3
.scaleLinear()
.domain([maxValue, minValue])
.range(scaleY.range())
Insert cell
scaleY = d3
.scaleLinear()
.domain([minValue, maxValue])
.range([0, cfg.height - (cfg.marginTop + cfg.marginBottom)])
Insert cell
scaleBandX = d3
.scaleBand()
.domain(newData.keys())
.range([cfg.marginLeft, cfg.width - (cfg.marginLeft + cfg.marginRight)])
.paddingInner(.2)
Insert cell
barWidth = scaleBandX.bandwidth()
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