Search code examples
javascriptflowchartgojs

Gojs draw templateLinks depending on nodeTemplateMap


I would like to set different offsets of linkTemplate depending of the nodetemplate type.

Actually I have only one linkTemplate

dia.linkTemplate =
  $(go.Link,
    // { routing: go.Link.AvoidsNodes },  // link route should avoid nodes
    $(go.Shape, { stroke: 'gray', height: 12 }),
    $(go.TextBlock, 'fiber_manual_record', { font: '20pt Material Icons', stroke: 'gray' },
      {
        segmentIndex: 0, segmentOffset: new go.Point(-9, 8),
        segmentOrientation: go.Link.OrientAlong
      }),
    $(go.TextBlock, 'fiber_manual_record', { font: '15pt Material Icons', stroke: 'gray' },
      {
        segmentIndex: -1, segmentOffset: new go.Point(-1, 8),
        segmentOrientation: go.Link.OrientAlong
      })
  );

but I have two nodeTemplateMap every one have a different shape.

My problem is that links don't starts on the same level depending on which node is used.


Solution

  • You can add a Binding to your link template that determines the Link.fromShortLength or Link.toShortLength depending on the kind of node it is. Something like:

    $(go.Link,
      new go.Binding("fromShortLength", "fromNode",
        node => node.category === "A" ? 10 : 20),
      . . .
    )
    

    Obviously you need to decide how to use the node to determine the value of Link.fromShortLength to use.