dash14 / v-network-graph

An interactive network graph visualization component for Vue 3

Home Page:https://dash14.github.io/v-network-graph/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected behavior for path containing repeated edge IDs

kyle42walker opened this issue · comments

Hello,

First off, thank you so much for maintaining this library! You have done some truly excellent work, and your library has been a joy to use.

However, I have encountered a small issue when rendering paths on a graph. Here is a simplified example to showcase the issue.

Consider an agent traversing a graph with 3 nodes and 2 edges as follows:

const data = {
  nodes: {
    node1: { name: 'Node 1' },
    node2: { name: 'Node 2' },
    node3: { name: 'Node 3' }
  },
  layouts: {
    nodes: {
      node1: { x: 100, y: 100 },
      node2: { x: 300, y: -300 },
      node3: { x: 500, y: 100 }
    }
  },
  edges: {
    edge1: { source: 'node1', target: 'node2', label: 'Edge 1' },
    edge2: { source: 'node2', target: 'node3', label: 'Edge 2' }
  }
}

v-network-graph Issue 131 Image 1

If the agent travels from Node 1 to Node 2 to Node 3 (via Edge 1 and Edge 2), everything works as intended.

const paths: vNG.Paths = { p: { edges: ['edge1', 'edge2'] } }

v-network-graph Issue 131 Image 2

But when the agent gets a bit lost and backtracks over the same edge multiple times, things get unusual. If the agent moves from Node 1 to Node 2 to Node 1 to Node 2 to Node 3, then the following is rendered:

const paths: vNG.Paths = { p: { edges: ['edge1', 'edge1', 'edge1', 'edge2'] } }

v-network-graph Issue 131 Image 3

Because the library specifies paths as a sequence of edges rather than nodes, it must choose which node should be the start of the path. In this example, Node 2 is treated as the start, and a false new edge between Nodes 1 and 3 is created to handle the incorrect assumption.

Is there any way for me to specify which node should be at the start of a path? Or perhaps is there another way I can define a path based on nodes rather than edges?

Thank you again for your hard work maintaining this!

Hi @kyle42walker,
Thank you for the detailed report!! Sorry to keep you waiting.

The implementation was not intended to repeat the same edge more than three times.
Please check v0.9.9 to see that it has been corrected to the expected behavior.
This fix was implemented by revising the method of calculating the first node.

Is there any way for me to specify which node should be at the start of a path? Or perhaps is there another way I can define a path based on nodes rather than edges?

Since this library allows multiple edges to be placed between two nodes, the path is designed to specify which edge it passes through.
This time, it was possible to handle the case by revising the calculation, but in the future, if a case arises where the calculation cannot be specified by any means, we may consider allowing the specification of the first node or a way to specify based on the node....

Thanks again for the report!

Thank you very much! That seems to have completely fixed my issue. I really appreciate your work on this!

Adding more ways to describe paths would be an awesome feature to add eventually. I look forward to seeing it someday!

Thank you very much for the fix! I faced this issue yesterday and I found your new version this morning.
Your work is amazing!