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

Add Dynamic ports

$
0
0

@sharmaDevashish wrote:

Hi,I am using a treeview palette to drag and drop my nodes in the editor part, it works fine.
When I try to add dynamic ports to node in my application. i am able to add the ports to the node with this code

{
var newPort = this.makePort("I3",true);
}

makePort(name, leftside) {
const ggm = go.GraphObject.make;
var port = ggm(go.Shape, "Rectangle",
{
fill: "gray", stroke: null,
desiredSize: new go.Size(8, 8),
portId: name, // declare this object to be a "port"
toMaxLinks: 1, // don't allow more than one link into a port
cursor: "pointer", // show a different cursor to indicate potential link point
name:"SHAPE"
});

var lab = ggm(go.TextBlock, name,  // the name of the port
            { font :"10px Noto Sans",
              stroke :"#fff"
   });

var panel = ggm(go.Panel, "Horizontal",
              { margin: new go.Margin(2, 0) });

// set up the port/panel based on which side of the node it will be on
if (leftside) {
  port.toSpot = go.Spot.Left;
  port.toLinkable = true;
  lab.margin = new go.Margin(1, 0, 0, 1);
  panel.alignment = go.Spot.TopLeft;
  panel.add(port);
  panel.add(lab);
} else {
  port.fromSpot = go.Spot.Right;
  port.fromLinkable = true;
  lab.margin = new go.Margin(1, 1, 0, 0);
  panel.alignment = go.Spot.TopRight;
  panel.add(lab);
  panel.add(port);
}
return panel;

var side = selectedNode.findObject("LeftPanel"); //LeftPanel is the name of panel to which port is to be added
side.add(newPort);
}

the port gets added and the changes are reflected in model as well. i save the the model in sessionStorage and while reloading the page i use fromJson() method to redraw the diagram. the changes(added ports) are not reflected in the diagram but in nodedataarray and linkdataarray the values are present.

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6969

Trending Articles