I have created a tree-like structure of cards with lines between parents and children. The lines are svg paths like so:
const newpath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
newpath.setAttributeNS(
null,
'd',
`M${parentX} ${parentY} h10 a${arcRadius},${arcRadius} 0 0 1 ${arcRadius},${arcRadius} v ${
childY - arcRadius * 2
} a${arcRadius},${arcRadius} 0 0 0 ${arcRadius},${arcRadius} h12`
);
newpath.setAttributeNS(null, 'stroke', 'black');
newpath.setAttributeNS(null, 'stroke-width', '1');
newpath.setAttributeNS(null, 'opacity', '1');
newpath.setAttributeNS(null, 'fill', 'none');
Now this means that for 1 parent with 3 children, 3 paths are created. All 3 overlaps to the first child, 2 paths overlaps to the second child and finally there's 1 path to the third child. The whole tree is zoomable by adjusting the transform: scale() property. Now when I zoom out the lines are darker where they overlap. Is there any way to get rid of this behaviour except drawing the lines only from child to child?
A similiar question has been asked before here: Why do SVG lines/ paths on top of each other create a different stroke? but the accepted solution does not work for me.


Unfortunately, there is no perfect solution.
A workaround providing a decent balance between crispness and smooth edges might be to apply a svg
feComponentTransferfilter to enhance the contrast of the alpha channel.The above example compares different workarounds:
shape-rendering: crispEdges– perfect for straight lines but produces jagged edges on curvesfeComponentTransferfilter: we're basically reducing the number of semi-transparent pixels.