vasturiano/force-graph

How to conditionally change linkLineDash between nodes

jacoblindgren opened this issue · 1 comments

I haven't been able to figure out a way to style links between nodes conditionally, on a node-by-node basis, the same way it's possible to conditionally style the nodes themselves (i.e. #331). I'm trying something like this:

.linkLineDash(node => {
      if (node.type === "output") {
        return [1,15];
      } else {
        return [1,1];
      }
    })

with a JSON structure like this:

{
"id": "MW7OHHLuUO9qRuG6",
"title": "Example1",
"type": "output"
},
{
"id": "K21lZ3Bx8sg5aIzW",
"title": "Example2",
"type": "place"
}

with no luck. Is .linkLineDash() the wrong place to do this?

@jacoblindgren the parameter you get in the linkLineDash method is a link object, not a node. So yes you can style the links conditionally this way, but your logic needs to be based on the link, f.e.:

.linkLineDash(link => {
      if (link.source.type === "output") {
        return [1,15];
      } else {
        return [1,1];
      }
    })