Quantcast
Channel: GoJS - Northwoods Software
Viewing all articles
Browse latest Browse all 7069

How to draw a new links and setting data while doing it

$
0
0

@Giosk wrote:

Hi Walter,
following this example I tried to draw a link between two of my entities, but with some issues.
I tried to follow this post but with no result.

The code to draw the link is the same as the above example

const drawLink = (e, button) => {
  var node = button.part.adornedPart
  var tool = e.diagram.toolManager.linkingTool
  tool.startObject = node.port
  e.diagram.currentTool = tool
  tool.doActivate()
}

I’ve add to my diagram these options and the linkConnected callback

  fromLinkable: true,
  fromLinkableDuplicates: true, 

  toLinkable: true,
  toLinkableDuplicates: true, 

  linkConnected: (node, link, port) => {
    if (link.fromNode !== null) {
      link.fromNode.invalidateConnectedLinks()
    }
    if (link.toNode !== null) {
      link.toNode.invalidateConnectedLinks()
    }
   }

and I also wrote this piece of code to handle the event of drawing a new link

myDiagram.addDiagramListener("LinkDrawn", e => {
  const subject = e.subject
  const { from, to } = subject.data
  const fromEntity = myDiagram.findPartForKey(from)
  const toEntity = myDiagram.findPartForKey(to)
  ....
})

in the “LinkDrawn” listener I get the “fromEntity” and “toEntity” in order to do a post to my server and store in my db my new link.

When I draw a link between two entities, I have the issue that after the drawing phase, the arrow goes to an empty place and I get this error:

Uncaught TypeError: Cannot read property 'LinkId' of null
    at selectionChanged (VM38 bundle.js:114665)
    at X.<anonymous> (VM38 bundle.js:21707)
    at E../node_modules/gojs/release/go.js.E.select.E.select (VM38 bundle.js:21011)
    at Vj../node_modules/gojs/release/go.js.qg.standardMouseSelect (VM38 bundle.js:20658)
    at Vj../node_modules/gojs/release/go.js.Vj.doMouseUp (VM38 bundle.js:20792)
    at hh../node_modules/gojs/release/go.js.hh.doMouseUp (VM38 bundle.js:20851)
    at E../node_modules/gojs/release/go.js.E.doMouseUp (VM38 bundle.js:20923)

I can’t find where is the problem and to be honest I didn’t understand how it works the tool for drawing the link.
Thanks

Posts: 3

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 7069

Trending Articles