Published
Edited
Sep 22, 2020
11 stars
Insert cell
Insert cell
createTexturedSvg = texture => {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);

svg.call(texture);

svg
.append("g")
.attr("fill", texture.url())
.selectAll("rect")
.data(data)
.join("rect")
.attr("x", (d, i) => x(i))
.attr("y", d => y(d.value))
.attr("height", d => y(0) - y(d.value))
.attr("width", x.bandwidth());

svg.append("g").call(xAxis);

svg.append("g").call(yAxis);

return svg;
}
Insert cell
withLines = {
const texture = textures.lines();
const svg = createTexturedSvg(texture);
return svg.node();
}
Insert cell
withCircles = {
const texture = textures.circles().size(5);
const svg = createTexturedSvg(texture);
return svg.node();
}
Insert cell
withPolkaDots = {
const texture = textures
.circles()
.radius(4)
.fill("darkorange")
.strokeWidth(2)
.stroke("firebrick")
.complement()
.background("#ccc");
const svg = createTexturedSvg(texture);
return svg.node();
}
Insert cell
withHexagons = {
const texture = textures
.paths()
.d("hexagons")
.size(8)
.strokeWidth(2)
.stroke("darkorange");
const svg = createTexturedSvg(texture);
return svg.node();
}
Insert cell
withCrosses = {
const texture = textures
.paths()
.d("crosses")
.lighter()
.thicker();
const svg = createTexturedSvg(texture);
return svg.node();
}
Insert cell
withCaps = {
const texture = textures
.paths()
.d("caps")
.lighter()
.thicker()
.stroke("darkorange");
const svg = createTexturedSvg(texture);
return svg.node();
}
Insert cell
withWoven = {
const texture = textures
.paths()
.d("woven")
.lighter()
.thicker();
const svg = createTexturedSvg(texture);
return svg.node();
}
Insert cell
withWaves = {
const texture = textures
.paths()
.d("waves")
.thicker()
.stroke("firebrick");
const svg = createTexturedSvg(texture);
return svg.node();
}
Insert cell
withNylon = {
const texture = textures
.paths()
.d("nylon")
.lighter()
.shapeRendering("crispEdges");
const svg = createTexturedSvg(texture);
return svg.node();
}
Insert cell
withSquares = {
const texture = textures
.paths()
.d("squares")
.stroke("darkorange");
const svg = createTexturedSvg(texture);
return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
textures = require("textures")
Insert cell
d3 = require("d3@6")
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