Skip to content

Instantly share code, notes, and snippets.

@robert-moore
Created January 18, 2018 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robert-moore/4204529708a429e4ae563ce79385947a to your computer and use it in GitHub Desktop.
Save robert-moore/4204529708a429e4ae563ce79385947a to your computer and use it in GitHub Desktop.
SVG Drop Shadow
export function addDropShadowDef(defsSelection, id, size, opacity) {
const filter = defsSelection.append("filter")
.attr("id", id)
.attr("height", "130%")
filter.append("feGaussianBlur")
.attr("in", "SourceAlpha")
.attr("stdDeviation", size * 1.5) // stdDeviation is how much to blur
filter.append("feOffset")
.attr("dx", size)
.attr("dy", size)
.attr("result", "offsetblur")
filter.append("feComponentTransfer")
.append("feFuncA")
.attr("type", "linear")
.attr("slope", opacity) // slope is the opacity of the shadow
const feMerge = filter.append("feMerge")
feMerge.append("feMergeNode") // this contains the offset blurred image
feMerge.append("feMergeNode")
.attr("in", "SourceGraphic")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment