Published
Edited
Jul 17, 2020
5 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
xM = d3.scaleLinear()
.domain([0, d3.max(data, d => d.value)])
.rangeRound([(params.svg.width / 2), params.margin.left * 2])
Insert cell
xF = d3.scaleLinear()
.domain(xM.domain())
.rangeRound([params.svg.width / 2, params.svg.width - (params.margin.right * 2)])
Insert cell
y = d3.scaleBand()
.domain(data.map(d => d.age))
.rangeRound([params.svg.height - params.margin.bottom, params.margin.top])
.padding(0.1)
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${params.svg.height - params.margin.bottom})`)
.call(g => g.append("g").call(d3.axisBottom(xM).ticks(params.svg.width / 80, "s")))
.call(g => g.append("g").call(d3.axisBottom(xF).ticks(params.svg.width / 80, "s")))
.call(g => g.selectAll(".tick:first-of-type").remove())
.call(g => g.selectAll(".tick line").attr("stroke", "#767676"))
.call(g => g.selectAll(".domain").attr("stroke", "#767676"))
.call(g => g.selectAll(".tick text").attr("fill", "#767676").style("font-size", "clamp(.7rem, 2.2vw, 1.0rem)").attr("font-family", "'Source Sans Pro', sans-serif"))
Insert cell
yAxis = g => g
.attr("transform", `translate(${xM(0)},0)`)
.call(d3.axisRight(y).tickSizeOuter(0))
.call(g => g.selectAll(".tick text").attr("fill", "white").style("font-size", "clamp(.7rem, 2.2vw, 1.0rem)").attr("font-family", "'Source Sans Pro', sans-serif"))
.call(g => g.selectAll(".tick line").attr("stroke", "white"))
.call(g => g.selectAll(".domain").attr("stroke", "white"))
Insert cell
height = data.length / 2 * 25 + params.margin.top + params.margin.bottom
Insert cell
mutable params = {
let output = {};
output["svg"] = {
"width": width,
"height": 450
};
output["margin"] = {
"top": 96,
"right": 24,
"bottom": 96,
"left": 24
};
output["plot"] = {
"x": output["margin"]["left"],
"y": output["margin"]["top"],
"width": output["svg"]["width"] - output["margin"]["left"] - output["margin"]["right"],
"height": output["svg"]["height"] - output["margin"]["top"] - output["margin"]["bottom"]
};

return output;
}
Insert cell
typographyStyles = html`<style>
@import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;700&display=swap');
`
Insert cell
chartStyles = html`<style>
#large-screen-source {
display: none;
}

@media (min-width: 900px) {
#small-screen-source {
display: none;
}
#large-screen-source {
display: initial;
}
}
</style>
`
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