GoJS简单示例

一个人想着一个人 提交于 2019-12-05 17:07:52

 

<!DOCTYPE html>


<html>

<head>
  <meta charset="utf-8">
  <title>GoJS实例--修改节点名称</title>
  <style>
    #myDiagramDiv {
      width: 400px;
      height: 500px;
      background-color: #DAE4E4;
    }
  </style>
  <script src="https://unpkg.com/gojs/release/go-debug.js"></script>
</head>

<body>
  <div id="myDiagramDiv"></div>

  <script>
    var diagram = new go.Diagram("myDiagramDiv");
    var $ = go.GraphObject.make;
    diagram.add(
      $(go.Node, "Auto",
        $(go.Shape, "RoundedRectangle", {
          fill: "lightblue"
        }),
        $(go.TextBlock, "Hello!", {
          margin: 5
        })
      ));

    diagram.nodeTemplate =
      $(go.Node, "Auto",
        { locationSpot: go.Spot.Center },
        $(go.Shape, "RoundedRectangle",
          { // default values if the data.highlight is undefined:
            fill: "yellow", stroke: "orange", strokeWidth: 2
          },
          new go.Binding("fill", "highlight", function (v) { return v ? "pink" : "lightblue"; }),
          new go.Binding("stroke", "highlight", function (v) { return v ? "red" : "blue"; }),
          new go.Binding("strokeWidth", "highlight", function (v) { return v ? 3 : 1; })),
        $(go.TextBlock,
          { margin: 5 },
          new go.Binding("text", "name"))
      );

    diagram.model.nodeDataArray = [
      { key: "Alpha", name: "how are you?", highlight: false }  // just one node, and no links
    ];

    function flash() {
      // all model changes should happen in a transaction
      diagram.model.commit(function (m) {
        var data = m.nodeDataArray[0];  // get the first node data
        m.set(data, "highlight", !data.highlight);
        console.log(data);
        m.set(data, "name", 'I am doing well');
      }, "flash");
    }
    function loop() {
      setTimeout(function () { flash(); loop(); }, 2000);
    }
    loop();
  </script>
</body>

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!