import { Selection } from 'd3'; // https://stackoverflow.com/questions/17883655/svg-shadow-cut-off export function addDropShadowFilter(svg: Selection, dx = 1, dy = 1, stdDeviation = 4): void { const defs = svg.append('defs'); const filter = defs.append('filter') .attr('id', 'dropshadow') .attr('y', '-90%') // This positions the filter so that it starts before the element. Preventing cut-off lines .attr('x', '-90%') .attr('height', '300%') .attr('width', '300%'); filter.append('feGaussianBlur') .attr('in', 'SourceAlpha') .attr('stdDeviation', stdDeviation) .attr('result', 'blur'); filter.append('feOffset') .attr('in', 'blur') .attr('dx', dx) .attr('dy', dy) .attr('result', 'offsetBlur'); const feMerge = filter.append('feMerge'); feMerge.append('feMergeNode') .attr('in', 'offsetBlur'); feMerge.append('feMergeNode') .attr('in', 'SourceGraphic'); }