Frontend API

export class GraphController

Provide all the methods used to interact with the displayed graph, such as adding and removing nodes and edges and also manage the layout of the elements on the graph.

Created by antoine on 10/07/17.

addNode (node: Node)

Add the given node on the graph.

addNodes(n: Array)

Add the given nodes on the graph.

removeNode (node: Node)

Remove the given node from the graph.

addEdge (edge: Edge)

Add the given edge on the graph.

removeGraphNodesThatAreNotInThisSet (nodes: Array)

Remove the nodes that are displayed on the graph but not included in the given set.

removeEdge(edge: Edge)

Remove the given edge from the graph.

updateEdge (oldEdge: Edge, newEdge: Edge)

Replace all the information of an edge with new ones.

private removeNodeFromId (id: string)

Remove a node to the graph from its id

private updateSourceConnectedEdge (attr: any)

Update the connectedEdge field of the node connected to the given edge’s source.

private updateTargetConnectedEdge (attr: any)

Update the connectedEdge field of the node connected to the given edge’s target.

Add the source part of an edge that is in the “linkWaitingForSrc” list and remove it from the list. Then it calls flowComponent.createEdge that will send a ‘graph:addedge’ message to the server in order to confirm the creation of the edge. If every goes well, this UI will receive a message graph:addedge in return add process, resulting in a new edge on the graph.

Add the source part of an edge that is in the “linkWaitingForTgt” list and remove it from the list. Then it calls flowComponent.createEdge that will send a ‘graph:addedge’ message to the server in order to confirm the creation of the edge. If every goes well, this UI will receive a message graph:addedge in return add process, resulting in a new edge on the graph.

displayNodesOnSameLine (nodes: Array)

Add all the given nodes on one line on the graph.

nodeStartRunning (id: string)

Highlight the node with the given id to show the user that the node is running.

nodeStopRunning (id: string)

Remove the highlighting of the node with the given id to show the user that the node is not running anymore.

removeRunningClassOnAllNodes ()

Remove the .running class from all nodes on the graph to make sure no ones is seen as running. Usually use this method when the simulation is finished.

createBlockForNode(node: Node)

Create a JointJS block for the given node.

nextPosition (): Object

Return the most appropriate coordinate where to put a new element on the graph.

private occupiedZone (): Object

Returns the x0, y0 coordinates, width and height of the zone occupied by the workflow on the graph.

private findFirstNodes (nodes: Array)

Determines which nodes are the first one in the given list and returns the list of them. The first nodes are the ones with no dependencies. In other words, the ones with no other nodes connected to their inports.

Those first nodes are the ones to display on top of the graph and also the first ones to execute when running the workflow.

addedEdge (cell: any)

To call when the user added an edge on the graph. This method must be called right after the edge is created. At that moment, only the src OR the tgt element will be defined, so we store the edge in a list, either “linkWaitingForSrc” or “linkWaitingForTgt” and another event will be triggered when the other side of the edge will be connected.

removedEdge (cell: any)

The user wants to remove the given edge from the workflow. Send this information to the server.

edgeChanged (cell: any)

The given edge’s metadata change. Send its new metadata to the server.

removedNode (evt: MouseEvent)

The user wants to remove the given node from the workflow. Send this information to the server.

private addGraphEventListeners ()

Configure the graph event listeners to subscribe to and the methods they should call when triggered.

private getIds (objects: Array): Array

Returns an Array containing the ids of all the elements that are in the given array of objects.

private getJointCellsNodesIds (): Array

Return an array containing the ids of all the nodes displayed on the graph.