Hi,
Note: Docs for panel.findObject(name) says “This does not recurse into the elements inside a Panel that holds elements for an itemArray.”
Question: How can I find the location and dimensions of a sub-part in a diagram where that sub-part is loaded as an itemArray, given a known piece of data ? See example below which adds 6 cells into a table. What is most efficient process to find details of part with id=‘c2-3’ ?
See codepen: http://codepen.io/JEE42/pen/PPBWzw enable console.
var $ = go.GraphObject.make; // for conciseness in defining templates
myDiagram =
$(go.Diagram, "myDiagram", // Diagram refers to its DIV HTML element by id
{
});
// Add an event listener for the first draw of the diagram - not critical in this tiny case but worthwhile when many elements to be drawn
this.myDiagram.addDiagramListener("InitialLayoutCompleted",
function (e) {
runTests()
})
var cellTemplate =
$(go.Panel, go.Panel.Auto, { margin: 0, stretch: go.GraphObject.Fill }
, new go.Binding("row", "row")
, new go.Binding("column", "column")
, $(go.Shape, {strokeWidth: 0, stretch: go.GraphObject.Fill, fill: 'gold', width: 50, height: 50}
,new go.Binding("fill", "itemIndex", // for fun and exploring use of itemIndex
function(i) { return (i%2 == 0) ? "lightgreen" : "lightyellow"; }).ofObject() // bound to this Panel itself, not to the Panel.data item
)
, $(go.TextBlock, { font: "normal 10pt sans-serif", textAlign: "center"}
, new go.Binding("text", "id")
) // end textblock
);// end cell
var tableTemplate =
$(go.Node, "Auto",
$(go.Shape, { fill: "white", stroke: "gray", strokeWidth: 0.5 })
, $(go.Panel, "Table"
, {
defaultRowSeparatorStroke: "gray"
, defaultRowSeparatorStrokeWidth: 0.5
, defaultColumnSeparatorStroke: "gray"
, defaultColumnSeparatorStrokeWidth: 0.5
, defaultAlignment: go.Spot.MiddleLeft
, defaultSeparatorPadding: 0
, padding: 0 // around table
, itemTemplate: cellTemplate} // points to above template for use in cells
,new go.Binding('itemArray', 'cells') )
)// end table template
var templmap=new go.Map("string", go.Node);
templmap.add("table", tableTemplate);
myDiagram.nodeTemplateMap=templmap // link the map to the diagram
var nodeDataArray=[
{ key: "table1"
, category: "table"
, cells: [
{id: 'c1-4', row: 1, column: 4, name: 'c1-4'}
, {id: 'c1-1', row: 1, column: 1, name: 'c1-1'}
, {id: 'c1-6', row: 1, column: 6, name: 'c1-6'}
, {id: 'c2-2', row: 2, column: 2, name: 'c2-2'}
, {id: 'c2-3', row: 2, column: 3, name: 'c2-3'}
, {id: 'c2-6', row: 2, column: 6, name: 'c2-6'}
]
}
];
var linkDataArray=[ ];
myDiagram.model=new go.GraphLinksModel(nodeDataArray, []) // finally hand the initial node info to the diagram
// Function called after diagram drawn first time
function runTests() {
console.clear()
console.log("How to find a reference and get position & dimensions of id='c2-3'")
}