Is there a method or way to get all the graph object’s the diagram currently has, perhaps as a list? I’ve searched for one but nothing came up.
If not how would I approach this?
Is there a method or way to get all the graph object’s the diagram currently has, perhaps as a list? I’ve searched for one but nothing came up.
If not how would I approach this?
Here’s a function that I used a lot when we were first debugging GoJS, before version 1.0 came out. I suggest that you adapt it for your own needs.
function dumpVisualTree(obj) {
if (obj instanceof go.Diagram) {
var lit = obj.layers;
while (lit.next()) {
var lay = lit.value;
console.log(lay.toString());
var pit = lay.parts;
while (pit.next()) {
dumpVisualTree(pit.value);
}
}
} else if (obj instanceof go.Part) {
var permits = ' ';
if (obj.copyable) permits += 'c';
if (obj.deletable) permits += 'd';
if (obj.groupable) permits += 'g';
if (obj.movable) permits += 'm';
if (obj.reshapable) permits += 'h';
if (obj.resizable) permits += 'z';
if (obj.rotatable) permits += 'o';
if (obj.selectable) permits += 's';
if (obj.textEditable) permits += 't';
if (obj.selectionAdorned) permits += 'A';
if (obj.isInDocumentBounds) permits += 'B';
if (obj.isLayoutPositioned) permits += 'L';
if (obj.isSelected) permits += 'S';
if (obj.isShadowed) permits += 'H';
dumpVisualTree1(obj, 1, permits);
}
}
function dumpVisualTree1(obj, indent, prefix) {
var line = '';
for (var i = 0; i < indent; i++) line += ' ';
line += obj.toString();
if (prefix) line += prefix;
var props = (obj.name ? ' "' + obj.name + '" ' : ' ');
if (obj.visible) props += 'v'; else props += '!v';
if (obj.pickable) props += 'p'; else props += '!p';
if (obj.isPanelMain) props += 'm';
if (obj.isActionable) props += 'a';
line += props;
if (obj.row !== 0 || obj.column !== 0) line += ' [' + obj.row + ',' + obj.column + ']';
line += ' ' + obj.actualBounds.toString();
if (obj.desiredSize.isReal()) line += ' d:' + obj.desiredSize.toString();
if (obj.naturalBounds.isReal()) line += ' n:' + obj.naturalBounds.toString();
if (obj.scale !== 1) line += ' s:' + obj.scale;
if (obj.angle !== 0) line += ' a:' + obj.angle;
if (obj.background !== null) line += ' b:' + obj.background.toString();
if (obj.areaBackground !== null) line += ' a:' + obj.background.toString();
if (obj instanceof go.Panel) {
line += ' elts:' + obj._elements.count;
if (!obj.isEnabled) line += ' !ENABLED';
if (obj.isClipping) line += ' CLIPPING';
if (obj.topIndex !== 0) line += ' top:' + obj.topIndex;
if (obj.leftIndex !== 0) line += ' left:' + obj.leftIndex;
if (obj.itemArray !== null) line += ' itemArray#:' + obj.itemArray.length;
if (obj.itemCategoryProperty) line += ' cat:' + obj.itemCategoryProperty;
if (obj.data !== null) line += ' data:' + obj.data;
}
if (obj.portId !== null) line += ' portId: "' + obj.portId + '"';
console.log(line);
if (obj instanceof go.Panel) {
var it = obj.elements;
while (it.next()) {
dumpVisualTree1(it.value, indent + 1, '');
}
}
}