I want to get the specific part of a part(i.e, node)
const firstPart = diagram.findPartForKey(“”);
// To get the specific part
const part = firstPart.findObject(“name”); // This returns a GraphObject
diagram.commandHandler.scrollToPart(part) // This throws an error as “part” is a GraphObject
I have tried using scrollToRect
diagram.scrollToRect(part.getDocumentBounds()); // This works only when the tree is expanded
We are using a tree layout and we have an option to collapse some nodes ( like loop nodes). scrollToRect is able to scroll to a specific part of a node if the tree is expanded. But if the tree is collapsed, scrollToRect isn’t scrolling to the specific part.
I’m able to scroll to the node using diagram.commandHandler.scrollToPart(firstPart), but I want to scroll to specific part of a node. Are there any methods which I could use, that returns the Specific Part. I have tried using Part.findObject and it is returning a GraphObject and with GraphObject.getDocumentBounds couldn’t able to use scrollToPart
Well, I suppose you could call CommandHandler.scrollToPart and then when then animation is finished you could call Diagram.scrollToRect. (I’m assuming animation is still enabled.)
Assuming you have done: myDiagram.addDiagramListener("AnimationFinished", onAnimationFinished)
which would do something like:
var myNode = null;
function onAnimationFinished(e) {
if (!myNode) return;
myNode = null;
const elt = myNode.findObject("name");
if (!elt) return;
const b = elt.getDocumentBounds();
myDiagram.scrollToRect(b)
}
Then when you want to call CommandHandler.scrollToPart do something like:
function showNode() {
// pick a Node at random
const arr = myDiagram.model.nodeDataArray;
const data = arr[Math.floor(Math.ceil(Math.random() * arr.length))];
const node = myDiagram.findNodeForData(data);
if (node) {
myNode = node;
myDiagram.select(node);
myDiagram.commandHandler.scrollToPart(node);
}
}