I have the following node template in my diagram:
var $ = go.GraphObject.make; // for conciseness in defining templates
myDiagram =
$(go.Diagram, "myDiagram", // must name or refer to the DIV HTML element
{
initialContentAlignment: go.Spot.Center
,allowDrop: true
, grid: $(go.Panel, "Grid",
{ gridCellSize: new go.Size (10, 10) },
$(go.Shape, "LineH", { stroke: "#d9d8d8" }),
$(go.Shape, "LineV", { stroke: "#d9d8d8" }),
$(go.Shape, "LineH", { stroke: "blue", interval: 5 }),
$(go.Shape, "LineV", { stroke: "blue", interval: 5 })
)
, "draggingTool.isGridSnapEnabled": true,
"draggingTool.gridSnapCellSpot": go.Spot.Center
}); // must be true to accept drops from the Palette
// define the Node template for regular nodes
myDiagram.nodeTemplateMap.add("", // the default category
$(go.Node, go.Panel.Auto
, {
selectionChanged: onSelectionChanged
, locationSpot: new go.Spot(0, 0, cellSize.width / 2, cellSize.height / 2)
}
// The Node.location comes from the "loc" property of the node data,
// converted by the Point.parse method.
// If the Node.location is changed, it updates the "loc" property of the node data,
// converting back using the Point.stringify method.
, new go.Binding("location", "pos", go.Point.parse).makeTwoWay(go.Point.stringify),
// the main object is a Panel that surrounds a TextBlock with a rectangular Shape
$(go.Shape,
{ figure: "Rectangle", fill: "white", strokeWidth: 2 }
, new go.Binding("stroke", "color")
//, new go.Binding("position", "pos")
)
, $(go.TextBlock,
{
maxSize: new go.Size(150, NaN), textAlign: "center",
margin: 12, editable: true, name: "TEXT",
font: "16pt Helvetica, Arial, sans-serif"
}
, new go.Binding("text", "text").makeTwoWay()
)
)
);
myDiagram.groupTemplate =
$(go.Group, go.Panel.Auto,
{
isSubGraphExpanded: false, // only show the Group itself, not any of its members
ungroupable: true
}
// allow the ExternalObjectsDropped event handler to ungroup the members as top-level parts
, $(go.Shape, "Rectangle", // the rectangular shape around the members
{ fill: "rgba(128,128,128,0.2)", stroke: "black", strokeWidth: 1 }
)
, $(go.Placeholder, { alignment: go.Spot.TopLeft }),
$(go.TextBlock,
{ font: "bold 16pt Helvetica, Arial, sans-serif", margin: 10 },
new go.Binding("text", "RackGrpName")
//, new go.Binding("key", "RackGrpID")
)
);
I have the follwing Json:
myPalette.model = new go.GraphLinksModel([
{ key: "1", RackGrpName: "Customer Left", isGroup: true },
{ key: "Ge", text: "Pocket 1", color: "green", group: "1", pos: "0 0" },
{ key: "Gr", text: "Pocket 2", color: "orange", group: "1", pos: "100 25" },
{ key: "Gd", text: "Pocket 3", color: "red", group: "1", pos: "50 100" },
]
, []);
}
However, in the function:
function onSelectionChanged(node) {
var SelectedNode = myDiagram.selection.first();
if (SelectedNode !== null) {
var data = SelectedNode.data;
}
}
The SelectedNode.group property results in undefined.
Can any one help?
thank you
Felipe Solanet
magnet