gojs05

Toggle class name on click in jQuery

by batobolg

HTML

<script src="https://gojs.net/latest/release/go.js"></script>
<div id="d1" style="width:300px; height:200px; border-style: solid;"></div>
<button id="b1">
+
</button>
<button id="b2">
ー
</button>

JavaScript

function showContent() {
	var $go = go.GraphObject.make;  
  let diagramA = $go(go.Diagram, "d1", { "undoManager.isEnabled": true, });
  
	// define the Node template
	diagramA.nodeTemplate =
	  $go(go.Node, "Auto", { resizable: true, resizeObjectName: "BODY" },
		$go(go.Shape, "RoundedRectangle",
		  {
			parameter1: 5,  // the corner has a large radius
			fill: "lightgreen", stroke: "black",
      name: "BODY",
		  },
      new go.Binding("desiredSize", "size", go.Size.parse)
      				.makeTwoWay(go.Size.stringify)
      ),
		  $go(go.TextBlock,{ alignment: go.Spot.TopLeft,},
		  new go.Binding("text").makeTwoWay()),
      new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
      new go.Binding("zOrder").makeTwoWay(),

  );
  
   // Create the Diagram's Model:
  var nodeDataArray = [
        { key: 1, text: "Alpha", color: "lightblue", size:"100 70", loc:"100 100", zOrder: 10 },
        { key: 2, text: "Alpha", color: "lightblue", size:"100 70", loc:"120 120", zOrder: 10 },
        { key: 3, text: "Alpha", color: "lightblue", size:"100 70", loc:"140 140", zOrder: 10 },
  ];
      
  diagramA.model = new go.GraphLinksModel(nodeDataArray);
	diagramA.model.nodeKeyProperty = "key";
	diagramA.model.linkKeyProperty = "key";
  
  diagramA.addModelChangedListener(function(e) {
    // ignore unimportant Transaction events
    if (!e.isTransactionFinished) return;
    if (e.oldValue == "Initial Layout") return;

    //var json = e.model.toIncrementalJson(e);
    let it = diagramA.selection.iterator;
    while (it.next()) {
				var node = it.value;
				var data = node.part.data;
		    console.log(data.zOrder);
		}    		

  });
  
  $("#b1").click(e=>{
  	diagramA.model.startTransaction("aaa");
    let it = diagramA.selection.iterator;
		while (it.next()) {
				var node = it.value;
				var data = node.part.data;
				diagramA.model.setDataProperty(data, "zOrder", data.zOrder + 1);
		}    		
    diagramA.model.commitTransaction("aaa");

  }
 ...