Published
Edited
Jun 28, 2020
1 star
Insert cell
Insert cell
Insert cell
textures = require("textures")
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
minimapPositionTranslate = "" + miniMargin.left + "," + parseFloat(mainMargin.top + mainHeight + mainMargin.bottom + miniMargin.top);
Insert cell
// clip = clipPath => clipPath.append("rect")
// .attr("x", mainMargin.left)
// .attr("y", 0)
// .attr("width", mainWidth + mainMargin.left)
// .attr("height", mainHeight);
Insert cell
mainXScale = d3.scaleBand()
.domain(data.map(d => d.x))
.range([mainMargin.left, width - mainMargin.right])
.paddingInner(0.4);
Insert cell
miniXScale = d3.scaleBand()
.domain(data.map(d => d.x))
.range([0, miniWidth])
.paddingInner(0.4);
Insert cell
mainYScale = d3.scaleLinear()
.domain([0, d3.max(data, d => d.y)]).nice()
.range([mainMargin.top, mainHeight - mainMargin.bottom]);
Insert cell
miniYScale = d3.scaleLinear()
.domain([0, d3.max(data, d => d.y)]).nice()
.range([0, miniHeight]);
Insert cell
mainXZoom = d3.scaleLinear()
.range([0, mainWidth])
.domain([0, mainWidth]);
Insert cell
mainXAxis = g => g
.attr("transform", `translate(0,${mainHeight})`)
.call(d3.axisBottom(mainXScale)
.tickSizeOuter(0)
.tickFormat(d => d3.timeFormat("%a")(d).substring(0, 1))
);
Insert cell
initialBrushXSelection = [0, 200]
Insert cell
chartTitle = g => g
.append("text")
.attr("id", "chart-title")
.attr("x", 0)
.attr("y", 0)
.attr("dy", "1em")
.style("font-weight", "800")
.style("font-size", "clamp(.7rem, 2.5vw, 1.2rem)") // minimum, preferred, maximum
.text(data.barChartTitle);
Insert cell
chartBy = g => g
.attr("transform", `translate(${width}, ${height})`)
.append("text")
.attr("id", "source")
.attr("x", 0)
.attr("y", 0)
.attr("dy", "-0.5em")
.attr("text-anchor", "end")
.text('@DiDoesDigital');
Insert cell
Insert cell
mainMargin = ({top: 48, right: 0, bottom: 24, left: 0})
Insert cell
mainWidth = width - mainMargin.left - mainMargin.right;
Insert cell
mainHeight = 450;
Insert cell
miniMargin = ({top: 12, right: 0, bottom: 48, left: 0})
Insert cell
miniHeight = 100;
Insert cell
miniWidth = width - miniMargin.left - miniMargin.right;
Insert cell
barColor = "#EF767A"
Insert cell
inactiveColor = "#f2e9e9"
Insert cell
activeColor = "#EF767A"
Insert cell
Insert cell
Insert cell
Insert cell
accessibleDataTable = renderDataTable(data, {caption: data.tableCaption, columns: data.slice[0], focusable: false})
Insert cell
Insert cell
Insert cell
d3 = require("d3@5", "d3-array@2.4")
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