我想對編程的使用D3定義的路徑進行一些修改。我想做的改變非常簡單,修改路徑的不透明度。我得到的問題是路徑本身會改變,結束標記不會改變,我不確定如何讓它這樣做。修改SVG路徑不透明度和它的標記
標記被定義爲這樣:
// define arrow markers for graph links
svg.append('svg:defs').append('svg:marker')
.attr('id', 'end-arrow')
.attr('viewBox', '0 -5 10 10')
.attr('refX', 6)
.attr('markerWidth', 3)
.attr('markerHeight', 3)
.attr('orient', 'auto')
.append('svg:path')
.attr('d', 'M0,-5L10,0L0,5')
.attr('fill', '#CCCCCC');
的路徑:
// Create the links between the nodes
var links = svg.append("g")
.selectAll(".link")
.data(data.links)
.enter()
.append("path")
.attr("class", "link")
.attr("d", sankey.link())
.style('marker-end', "url(#end-arrow)")
.style("stroke-width", function (d) { return Math.max(1, d.dy); })
.sort(function (a, b) { return b.dy - a.dy; });
,我使用改變的路徑的代碼,其中不更新標記:
d3.selectAll("path.link")
.filter(function (link) {
// Find all the links that come to/from this node
if (self.sourceLinksMatch(self, link, node)) {
return true;
}
if (self.targetLinksMatch(self, link, node)) {
return true;
}
return false;
})
.transition()
.style("stroke-opacity", 0.5);
任何人都可以建議我可能需要改變以修改標記端樣式嗎?
感謝
如果您有多個具有相同預定義標記的路徑,則此功能不起作用 – SumNeuron
'「不透明度」可以覆蓋「填充「和」中風「混濁。分別設置「stroke-opacity」和「fill-opacity」更安全。 –