我想爲我使用d3和SVG繪製的陰影設置陰影,但我在疊加相鄰元素的陰影時遇到了問題。看到下面的圖片,瞭解它目前的樣子。請注意,中間的六邊形看起來有不同的高度,因爲陰影正在其中一些上面呈現。我想要做的就是設置陰影,使它們只在背景上渲染,而不是在其他相鄰的格子上。SVG陰影分層
這裏是如何,目前正在定義陰影代碼:
var filter = defs.append("filter")
.attr("id", "drop-shadow")
.attr("height", "130%");
// SourceAlpha refers to opacity of graphic that this filter will be applied to
// convolve that with a Gaussian with standard deviation 3 and store result
// in blur
filter.append("feGaussianBlur")
.attr("in", "SourceAlpha")
.attr("stdDeviation", 1)
.attr("result", "blur");
// translate output of Gaussian blur to the right and downwards with 2px
// store result in offsetBlur
filter.append("feOffset")
.attr("in", "blur")
.attr("dx", 1)
.attr("dy", 1)
.attr("result", "offsetBlur");
// overlay original SourceGraphic over translated blurred opacity by using
// feMerge filter. Order of specifying inputs is important!
var feMerge = filter.append("feMerge");
feMerge.append("feMergeNode")
.attr("in", "offsetBlur")
feMerge.append("feMergeNode")
.attr("in", "SourceGraphic");
的樣式會應用到六邊形:
d3.select(this).style("filter", "url(#drop-shadow)")