TreeExpanderButton Animation Question

The way the TreeExpanderButton animates an expanding tree branch without any modification has the child nodes start from on top of the parent node. While this looks fine when the child nodes are the same length or shorter than the parent nodes this looks fine, however when they are longer it looks awkward and derpy, with the back end of the node initially sticking out the back of the parent.


Is there a way to change this by altering the node positions, ports, spots, or link formats? Overriding the actual animation seems like it will be difficult and counterproductive. I would like the animation to start with the child nodes in a location directly adjacent to the parent. It would also be nice to be able to skip it entirely as in nodecollapse, in the case of large diagrams.


Thanks, here is my code. I am basically just trying to get a mindmap type thing set up, which I later hope to integrate with cloud storage and a bunch of other things.

var $ = go.GraphObject.make;

mainDiagram = $(go.Diagram, “mainDiagramDiv”,
<span =“Apple-tab-span” style=“white-space:pre”> {
<span =“Apple-tab-span” style=“white-space:pre”> allowMove: true,
<span =“Apple-tab-span” style=“white-space:pre”> allowCopy: true,
<span =“Apple-tab-span” style=“white-space:pre”> allowDelete: true,
<span =“Apple-tab-span” style=“white-space:pre”> allowHorizontalScroll: true,
<span =“Apple-tab-span” style=“white-space:pre”> layout:
<span =“Apple-tab-span” style=“white-space:pre”> $(go.TreeLayout,
<span =“Apple-tab-span” style=“white-space:pre”> {
<span =“Apple-tab-span” style=“white-space:pre”> angle: 0,
<span =“Apple-tab-span” style=“white-space:pre”> compaction: go.TreeLayout.CompactionNone,
<span =“Apple-tab-span” style=“white-space:pre”> layerSpacing: 60,
<span =“Apple-tab-span” style=“white-space:pre”> layerSpacingParentOverlap: 0,
<span =“Apple-tab-span” style=“white-space:pre”> nodeIndent: 2,
<span =“Apple-tab-span” style=“white-space:pre”> nodeIndentPastParent: 0.88,
<span =“Apple-tab-span” style=“white-space:pre”> nodeSpacing: 2,
<span =“Apple-tab-span” style=“white-space:pre”> setsPortSpot: false,
<span =“Apple-tab-span” style=“white-space:pre”> setsChildPortSpot: false
<span =“Apple-tab-span” style=“white-space:pre”> }
<span =“Apple-tab-span” style=“white-space:pre”> )
<span =“Apple-tab-span” style=“white-space:pre”> }
);

mainDiagram.initialContentAlignment = go.Spot.Center;

mainDiagram.nodeTemplate = $(go.Node, “Horizontal”,
{ selectionAdorned: false }, // no Adornment: instead change panel background color by binding to Node.isSelected
$(go.Panel, “Auto”,
<span =“Apple-tab-span” style=“white-space:pre”> $(go.Shape, “RoundedRectangle”, {fill: “transparent”}),
<span =“Apple-tab-span” style=“white-space:pre”> { position: new go.Point(0, 0) },
new go.Binding(“background”, “isSelected”,
<span =“Apple-tab-span” style=“white-space:pre”> function (s) { return (s ? “lightblue” : “white”); }).ofObject(),
$(go.TextBlock,
<span =“Apple-tab-span” style=“white-space:pre”> new go.Binding(“text”, “key”, function(s) { return " " + s; })
<span =“Apple-tab-span” style=“white-space:pre”> ) //end TextBlock
), // end Horizontal Panel
<span =“Apple-tab-span” style=“white-space:pre”> $(“TreeExpanderButton”)
); // end Node

mainDiagram.linkTemplate = $(go.Link,
<span =“Apple-tab-span” style=“white-space:pre”> {
<span =“Apple-tab-span” style=“white-space:pre”> selectable: false,
<span =“Apple-tab-span” style=“white-space:pre”> corner: 0,
<span =“Apple-tab-span” style=“white-space:pre”> fromEndSegmentLength: 4,
<span =“Apple-tab-span” style=“white-space:pre”> fromSpot: go.Spot.Right,
<span =“Apple-tab-span” style=“white-space:pre”> toSpot: go.Spot.Left
<span =“Apple-tab-span” style=“white-space:pre”> },
<span =“Apple-tab-span” style=“white-space:pre”> $(go.Shape)
);

var nodeDataArray = [
<span =“Apple-tab-span” style=“white-space:pre”> { key: “Home” },
<span =“Apple-tab-span” style=“white-space:pre”> { key: “Research”, parent: “Home” },
<span =“Apple-tab-span” style=“white-space:pre”> { key: “Contact”, parent: “Home” },
<span =“Apple-tab-span” style=“white-space:pre”> { key: “Systems Factorial Technology”, parent: “Research” },
<span =“Apple-tab-span” style=“white-space:pre”> { key: “Fractal Geometry”, parent: “Research” },
<span =“Apple-tab-span” style=“white-space:pre”> { key: “Network Theory”, parent: “Research” },
<span =“Apple-tab-span” style=“white-space:pre”> { key: “Email”, parent: “Contact”},
<span =“Apple-tab-span” style=“white-space:pre”> { key: “Facebook”, parent: “Contact”},
<span =“Apple-tab-span” style=“white-space:pre”> { key: “Phone”, parent: “Contact”},
<span =“Apple-tab-span” style=“white-space:pre”> { key: “LinkedIn”, parent: “Contact”},
];
mainDiagram.model = new go.TreeModel(nodeDataArray);

try setting the Node template’s locationSpot to go.Spot.Center. It is TopLeft by default.

Thank you for responding so quickly.

It doesn’t seem to work - I think the locationSpot of the parent node needs to be temporarily set to Center or Right when expanding. It would make sense that it doesn’t work to change the overall nodeTemplate because it will change change the positioning of the parent and child nodes, resulting in the same issue. And actually, now that I think about it if this is working the way I imagined (the nodes start at the same location), wouldn’t top left align the topleft corners? My problem is that the child nodes are starting with their left corner to the left of the left corner of the parent and expanding to the right.

Would I need to override something in the TreeExpanderButton class to modify a parent nodes location.Spot before playing the animation? Or do you think there is a simpler way to do it? This is my reworked nodeTemplate.

mainDiagram.nodeTemplate = $(go.Node, “Horizontal”,
{ selectionAdorned: false, locationSpot: go.Spot.Center}, // no Adornment: instead change panel background color by binding to Node.isSelected
<span =“Apple-tab-span” style=“white-space:pre”> $(go.Panel, “Auto”,
<span =“Apple-tab-span” style=“white-space:pre”> $(go.Shape, “RoundedRectangle”, {fill: “transparent”}),
<span =“Apple-tab-span” style=“white-space:pre”> { position: new go.Point(0, 0) },
new go.Binding(“background”, “isSelected”,
<span =“Apple-tab-span” style=“white-space:pre”> function (s) { return (s ? “lightblue” : “white”); }).ofObject(),
$(go.TextBlock,
<span =“Apple-tab-span” style=“white-space:pre”> new go.Binding(“text”, “key”, function(s) { return " " + s; })
<span =“Apple-tab-span” style=“white-space:pre”> ) //end TextBlock
), // end Horizontal Panel
<span =“Apple-tab-span” style=“white-space:pre”> $(“TreeExpanderButton”)
); // end Node

Sorry, I was mistaken. That won’t change the point that expanding nodes originate from.

Unfortunately we do not make these positions possible to modify at the moment, but in future releases that may change.

It could look worse. Also I did just read that animations can be turned off all together, but is it possible to turn off only the ExpandTree animation? I may not, because the animation isn’t terrible as it stands, but it would be nice to be able to.

It is not possible right now, but we’ll probably give that option in the future, of turning on/off the three types currently supported: layout, group expansion, tree expansion.

I see. Thanks for being so responsive. I really appreciate the work you guys have done so far. Keep up the good work. I enjoy working with your library as it is and look forward to seeing what you have to offer in the future.

@Walter hey, Any solutions for this? Thank u.

Yes, but it involves an undocumented method on AnimationManager. If you don’t mind that uncertainty, you can override AnimationManager.canStart:

      $(go.Diagram, . . .,
        { . . .,
          "animationManager.canStart": function() {
            return !this.animationReasons.contains("Expand Tree");
          }
        });

This turns off animation when expanding trees, but otherwise continues to perform automatic animations.

@walter Thank you very much!
I’ll have a try.