question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Edge lines sometimes overlay edge labels

See original GitHub issue

Describe the Bug

In some cases edge lines will overlay the edge labels, which looks bad and can cause readability issues. Whether or not this happens depends on the rendering order of the edges in the final svg.

Your Example Website or App

https://reactflow.dev/docs/examples/edges/custom-edge/

Steps to Reproduce the Bug or Issue

  1. Go To: https://reactflow.dev/docs/examples/edges/custom-edge/
  2. Notice how the label with styled bg box is behind the line for custom edge

Expected behavior

As a user, I expect custom edge content to be rendered above the edge lines, so that none of the content in the edges gets hidden, and for better visual appeal.

Screenshots or Videos

image

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 106.0.5249.103

Additional context

There is a clear explanation of svg z-index and rendering order here: https://stackoverflow.com/a/25302276/2373122.

I created a small script that fixes the overlay issue on the example page that I referenced. We can run this in our app, but it’s not ideal to do dom surgery every time reactflow renders. Life would be much better if reactflow was careful to render all the edge lines before the edges themselves so that the lines do not overlay actual content. With the current structure of the custom edges, I don’t know exactly how this would be implemented. I might be missing something here, perhaps there’s an easier way to accomplish what we need, but I wanted to pose the issue anyway and see where it goes.

Also worth noting, someone else reported this issue as a discussion, but there was no response there: https://github.com/wbkd/react-flow/discussions/2250. They were on an older version of reactflow, but I am on the current version (v11).

const edgeClass = 'react-flow__edge';
const edgePathClass = 'react-flow__edge-path';

const edges = [...document.querySelectorAll(`.${edgeClass}`)];

if (edges.length === 0) {
  return;
}

const edgesContainer = edges[0].parentElement;

edges.forEach((edge) => {
  const edgeText = edge.querySelector('text');
  const edgePath = edge.querySelector(`.${edgePathClass}`);

  if (!edgeText || !edgePath) {
    return;
  }

  const clonedEdge = edge.cloneNode(true);
  clonedEdge.querySelector(`.${edgePathClass}`).remove();
  edgesContainer.append(clonedEdge);
  edgeText.remove();
});

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
moklickcommented, Oct 26, 2022

This is a very first draft, but I could imagine that it could work: https://codesandbox.io/s/portaledgelabelrenderer-ikxqkb?file=/ButtonEdge.js . In this example the edge label is just a div. No foreignObject needed. The edge labels get rendered to a separate EdgeLabelRenderer component with the help of a Portal.

We could export a component (EdgeLabelRenderer) that one could use as a helper component to render a label to a dedicated edge-label-renderer dom node as seen in the example.

1reaction
moklickcommented, Oct 15, 2022

I would love to have a separated div based renderer for the edge labels. I will try to find out if this is possible with the current structure.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Graphviz edges not discernible / edge labels overwritten
Graphviz edges not discernible / edge labels overwritten · This problem exists when there is a node in the middle of a bidirectionally...
Read more >
More than 3 labels per edge · Issue #2170 - GitHub
For certain use cases more labels per edge are needed. They should be freely placeable based on both absolute (pixel-) length and relative...
Read more >
Attributes - Graphviz
Instructions to customise the layout of Graphviz nodes, edges, graphs, ... Whether to connect the edge label to the edge with a line....
Read more >
Graph Overlays and Legends - FlowJo V9
Often it is useful to plot two or more data sets or population on the ... When the mouse passes over an edge...
Read more >
Overview of DevTools - Microsoft Edge Development
Get to know the Microsoft Edge Developer Tools. ... At the command line, open Microsoft Edge, passing in the --auto-open-devtools-for-tabs ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found