Issue with editing visible parts of Panel Table

I am creating a “editor” where one of the features is that the user is able to decide whether to align text on left, right, top or bottom side of a relation - using a line and a dot to “connect” to the line.

My template looks like this

return $go(go.Node, “Auto”, {
contextMenu: $go(go.Adornment)
},
new go.Binding(“position”, “”, function(v) {
return new go.Point(v.x, v.y);
}),
$go(go.Panel, “Table”,
$go(go.TextBlock,
{ font: “12pt Sans-Serif”, column: 2, row: 2 },
new go.Binding(“text”, “”, function (v) {
var value = ‘’;
for (var val in v.data) {
if(val === ‘Process Value’) {
value += v.data[val];
}
}
return value;
})),
$go(go.Shape, “Circle”, { column: 0, row: 2, width: 5, height: 5, fromSpot: go.Spot.AllSides, toSpot: go.Spot.AllSides },
new go.Binding(“portId”, “”, function (data) {
return data.align ===‘right’ ? “” : -1;
}),
new go.Binding(“visible”, “”, function (data) {
return data.align === ‘right’;
})),
$go(go.Shape, “LineH”, { width: 20, column: 1, row: 2 },
new go.Binding(“visible”, “”, function (data) {
return data.align === ‘right’;
})),
$go(go.Shape, “Circle”, { column: 4, row: 2, width: 5, height: 5, fromSpot: go.Spot.AllSides, toSpot: go.Spot.AllSides },
new go.Binding(“portId”, “”, function (data) {
return data.align === ‘left’ ? “” : -1;
}),
new go.Binding(“visible”, “”, function (data) {
return data.align === ‘left’;
})),
$go(go.Shape, “LineH”, { width: 20, column: 3, row: 2 },
new go.Binding(“visible”, “”, function (data) {
return data.align === ‘left’;
})),
$go(go.Shape, “Circle”, { column: 2, row: 0, width: 5, height: 5, fromSpot: go.Spot.AllSides, toSpot: go.Spot.AllSides },
new go.Binding(“portId”, “”, function (data) {
return data.align ===‘top’ ? “” : -1;
}),
new go.Binding(“visible”, “”, function (data) {
return data.align === ‘top’;
})),
$go(go.Shape, “LineV”, { height: 20, column: 2, row: 1 },
new go.Binding(“visible”, “”, function (data) {
return data.align === ‘top’;
})),
$go(go.Shape, “Circle”, { column: 2, row: 4, width: 5, height: 5, fromSpot: go.Spot.AllSides, toSpot: go.Spot.AllSides },
new go.Binding(“portId”, “”, function (data) {
return data.align ===‘bottom’ ? “” : -1;
}),
new go.Binding(“visible”, “”, function (data) {
return data.align === ‘bottom’;
})),
$go(go.Shape, “LineV”, { height: 20, column: 2, row: 3 },
new go.Binding(“visible”, “”, function (data) {
return data.align === ‘bottom’;
}))

                           ))
        },

and my update logic looks like this

}).success(function (node) {
var model = diagram.diagram.model;

<span =“Apple-tab-span” style=“white-space:pre”> var item = model.findNodeDataForKey(node.key);
model.setDataProperty(item, “align”, node.align);
model.updateTargetBindings(item);
}

This works for all changes except from the one called ‘right’. When i change to right the node itself is becoming the port. When i refresh the whole view and its getting rendered with these new settings everything is working and the ‘dot’ is considered a port again.

Adding a picture showing two nodes where both where aligned left, and then after the display is rendered the bottom one is realigned to right - but the “port” information is gone and the node itself has become the port. (this is working for all other scenarios)

Did you want the Circle Shape to be at the x,y position? Then you want to give that Circle Shape a name and assign Node.locationObjectName to be that name, and instead of binding the Node.position you should bind the Node.location. Also, set Node.locationSpot to be go.Spot.Center. The combination of those settings/bindings means that your x,y point will be at the center of the Circle Shape, no matter what is in the table rows or columns around it. Read more at http://gojs.net/latest/api/symbols/Part.html or http://gojs.net/latest/intro/viewport.html

You should start and commit a transaction around the model changing code in your success function.
Since you are calling Model.setDataProperty, your call to Model.updateTargetBindings is unnecessary.

You have a lot of Bindings to the whole data object (i.e. the second argument is the empty string) when you don’t need to. Those bindings are “expensive” because they get evaluated a lot. It would be more efficient to have the bindings be like:
new go.Binding(“visible”, “align”, function(a) { return a === “bottom”; })
That way most of the bindings would only be evaluated when the value of the “align” property changes.

It appears that your Node, which is an “Auto” Panel, only has one element in it. One uses an “Auto” Panel to provide a border (the first/main element) around the content (the second and other elements). Save yourself a Panel by moving up the “Table” Panel to be the Node.

I hope you don’t mind my additional critique of your code.

Thank you very much for the suggestions! I will try to implement those and see if its work out.


I don’t mind your critique of my code - that is how I learn to master this framework. Smile

Worked out perfectly fine, and from your suggestions i manage to clean up a lot of the code. Thank you :-)