Quiero hacer que el árbol agregue un nuevo nodo siempre en el lado derecho de la lista por alguna razón por la que lo puso desde el lado izquierdo. mi diagrama init se ve así. ¿Hay una opción para hacerlo SIN comparador?
"toolManager.mouseWheelBehavior": go.ToolManager.WheelZoom, "undoManager.isEnabled": true, initialContentAlignment: go.Spot.TopCenter, initialAutoScale: go.Diagram.Uniform, hasHorizontalScrollbar: true, allowDelete: false, layout: $(go.TreeLayout, { angle: 90, nodeSpacing: 100, }), model: $(go.GraphLinksModel, { linkKeyProperty: "key", // IMPORTANT! must be defined for merges and data sync when using GraphLinksModel }), });No veo por qué no querrías configurar TreeLayout.comparer .
Pero una solución simple es configurar TreeLayout.sorting para go.TreeLayout.SortingReverse . Por ejemplo:
<!DOCTYPE html> <html> <head> <title>Minimal GoJS Sample</title> <!-- Copyright 1998-2022 by Northwoods Software Corporation. --> </head> <body> <div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:600px"></div> <button id="myTestButton">Test</button> <script src="https://unpkg.com/gojs"></script> <script id="code"> const $ = go.GraphObject.make; const myDiagram = $(go.Diagram, "myDiagramDiv", { layout: $(go.TreeLayout, { angle: 90, sorting: go.TreeLayout.SortingReverse }) }); myDiagram.nodeTemplate = $(go.Node, "Auto", { locationSpot: go.Spot.Top }, $(go.Shape, { fill: "white" }, new go.Binding("fill", "color")), $(go.TextBlock, { margin: 8 }, new go.Binding("text")) ); myDiagram.model = new go.GraphLinksModel( [ { key: 1, text: "Alpha", color: "lightblue" }, { key: 2, text: "Beta", color: "orange" }, { key: 3, text: "Gamma", color: "lightgreen" }, { key: 4, text: "Delta", color: "pink" } ], [ { from: 1, to: 2 }, { from: 1, to: 3 }, { from: 3, to: 4 }, ]); document.getElementById("myTestButton").addEventListener("click", e => { let node = myDiagram.selection.first(); if (!node) node = myDiagram.nodes.first(); if (node instanceof go.Node) { myDiagram.model.commit(m => { const d = { text: "New Node", color: go.Brush.randomColor() }; m.addNodeData(d); const n = myDiagram.findNodeForData(d); if (n) n.location = node.location; m.addLinkData( { from: node.key, to: n.key }); }); } }); </script> </body> </html>Haga clic en el botón "Probar" para agregar un nodo de árbol secundario al nodo seleccionado.