dagrejs / dagre-d3

A D3-based renderer for Dagre
MIT License
2.84k stars 587 forks source link

Getting SVG element for edge label #325

Open dan2097 opened 6 years ago

dan2097 commented 6 years ago

For nodes and edges g.node(v).elem and g.edge(v,w).elem can be used to access the corresponding SVG element. Am I right in saying that there is currently no way to get the corresponding SVG element for an edge label in a similar manner? [or perhaps through a property of the edge object]

The use case I have is to interactively toggle the visibility of the nodes/edges of the graph. When changing the visibility of an edge, I would obviously also want to do the same to its corresponding edge label.

dan2097 commented 6 years ago

A workaround for this is to create the SVG element for the edge label yourself e.g. g.setEdge(start, end, {labelType: "svg", label: svgLabel});

The SVG element can then be associated with a property of the edge object to allow it to be retrieved from the edge e.g. g.edge(start, end).labelElem = svgLabel

https://dagrejs.github.io/project/dagre-d3/latest/demo/svg-labels.html gives an example of creating an SVG element for use as an edge label