Sto cercando di apportare alcune modifiche a un percorso, definito utilizzando D3 a livello di programmazione. Il cambiamento che voglio fare è abbastanza semplice, modificando l'opacità del percorso. Il problema che ho è mentre il percorso stesso cambia, il marcatore finale non lo fa, e non sono abbastanza sicuro di come farlo.Modifica dell'opacità del percorso SVG e del marker
Il marcatore è definito come modo:
// 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');
Il percorso:
// 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; });
Il codice che uso per cambiare i percorsi che non aggiorna i marcatori:
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);
Qualcuno può suggerire cosa potrei aver bisogno di cambiare per modificare anche lo stile di fine marcatore?
Grazie
non funziona se hai più percorsi con lo stesso indicatore predefinito – SumNeuron
'" opacità "' può ignorare entrambi "riempimento "e" opacità "di tratto. È più sicuro impostare "opacità del tratto" e "opacità del riempimento" separatamente. –