anvaka / ngraph.graph

Graph data structure in JavaScript
BSD 3-Clause "New" or "Revised" License
526 stars 67 forks source link

See link direction #28

Open pvalin opened 4 years ago

pvalin commented 4 years ago

Hi,

Not really an issue rather an enhancement (or probably I'm hopeless and it's already practicable ^^). Is it possible to show the direction of a link with an arrow or a moving particle like vasturiano's 3d-force-graph :

Thanks for your work in any case! :)

lordnox commented 4 years ago

Hi,

When iterating through a link list you should know what node you are working with.

const linkDirection = (node: Node, incoming: boolean) =>
  node.links.filter(link => node.id === (incoming ? link.toId : link.fromId))

const incomingLinks = linkDirection(node, true)
const outgoingLinks = linkDirection(node, false)

With link.toId and link.fromId you can figure out the direction.

The other possibility is to use the link.data property to save the "direction"