Published
Edited
Nov 13, 2019
1 star
Insert cell
md`# Mr. Jingles and [mask](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/mask)
Applying a mask to an SVG image`
Insert cell
chart = {
const svg = d3.select(DOM.svg(width, height))
.style("width", "60%")
.style("height", "auto")
.style("font", "10px sans-serif");
svg.append("mask")
.attr("id", "myMask")
// Everything under a black pixel will be invisible
.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", width)
.attr("height", height)
.attr("fill", "black");
svg.select("#myMask")
// Everything under a white pixel will be visible
.append("circle")
.attr("cx", 100)
.attr("cy", 110)
.attr("r", 100)
.attr("fill", "white");

svg.append("image")
.attr("x", 0)
.attr("y", 0)
.attr("width", 250)
.attr("xlink:href", 'https://raw.githubusercontent.com/aaronxhill/standd/master/jj.jpg')
.attr("mask", "url(#myMask)");
return svg.node();
}
Insert cell
width = 300;
Insert cell
height = 300;
Insert cell
d3 = require("d3@5")
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