2
我有一個D3 v4力仿真,其中有100個節點。每個節點都是一個圖像,我想爲每個圖像添加一個陰影,但是,我認爲由於我呈現陰影的方式,這不會縮放。 100個沒有陰影的圖像運行60fps,但是陰影更像8fps。有沒有一個hacky的解決方案,或者更好的方法來做到這一點。以下是我現在所擁有的(渲染上的圖像後面的圓圈):將陰影添加到很多D3力模擬節點?
var dropShadowFilter = this.d3Graph.append('svg:filter')
.attr('id', 'drop-shadow')
.attr('filterUnits', "userSpaceOnUse")
.attr('width', '250%')
.attr('height', '250%');
dropShadowFilter.append('svg:feGaussianBlur')
.attr('in', 'SourceGraphic')
.attr('stdDeviation', 2)
.attr('result', 'blur-out');
dropShadowFilter.append('svg:feColorMatrix')
.attr('in', 'blur-out')
.attr('type', 'hueRotate')
.attr('values', 180)
.attr('result', 'color-out');
dropShadowFilter.append('svg:feOffset')
.attr('in', 'color-out')
.attr('dx', 3)
.attr('dy', 3)
.attr('result', 'the-shadow');
dropShadowFilter.append('svg:feBlend')
.attr('in', 'SourceGraphic')
.attr('in2', 'the-shadow')
.attr('mode', 'normal');
this.node = this.d3Graph.selectAll(null)
.data(Nodes)
.enter()
.append("g")
.attr("class", "nodes");
this.node.append("circle")
.attr("r", 30)
.attr("fill", "red")
.style("filter", "url(#drop-shadow)")
如果每個節點都有追加到它們的圖像,你可以創建爲每個圖像的照片編輯應用程序中的陰影效果,而不是使用SVG過濾 –
這穿過我的腦海,但不幸的是,我不這麼認爲。當它們彼此靠近時,陰影最終會與其他節點重疊,這看起來不正確。 – PurplePanda