如何在Angularjs中使用gojs禁用DragSelectingTool

时间:2018-05-24 13:11:43

标签: javascript angularjs gojs

我创建了树类结构,但我无法禁用dragselectingTool。我需要修理树箱。请帮我解决这个问题。 我引用了这个链接https://gojs.net/latest/api/symbols/DragSelectingTool.html

enter image description here

 <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Org Chart Static</title>
<meta name="description" content="A larger org chart with an Overview and searching capability." />
<!-- Copyright 1998-2018 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="./release/go.js"></script>
<link href='https://fonts.googleapis.com/css?family=Roboto:400,500' rel='stylesheet' type='text/css'>
<script id="code">
  function init() {
    if (window.goSamples) goSamples();  // init for these samples -- you don't need to call this
    var $ = go.GraphObject.make;  // for conciseness in defining templates

    myDiagram =
      $(go.Diagram, "myDiagramDiv",  // the DIV HTML element
        {
          // Put the diagram contents at the top center of the viewport
          initialDocumentSpot: go.Spot.TopCenter,
          initialViewportSpot: go.Spot.TopCenter,
          // OR: Scroll to show a particular node, once the layout has determined where that node is
          //"InitialLayoutCompleted": function(e) {
          //  var node = e.diagram.findNodeForKey(28);
          //  if (node !== null) e.diagram.commandHandler.scrollToPart(node);
          //},
          layout:
            $(go.TreeLayout,  // use a TreeLayout to position all of the nodes
              {
                treeStyle: go.TreeLayout.StyleLastParents,
                // properties for most of the tree:
                angle: 90,
                layerSpacing: 80,
                // properties for the "last parents":
                alternateAngle: 0,
                alternateAlignment: go.TreeLayout.AlignmentStart,
                alternateNodeIndent: 20,
                alternateNodeIndentPastParent: 1,
                alternateNodeSpacing: 20,
                alternateLayerSpacing: 40,
                alternateLayerSpacingParentOverlap: 1,
                alternatePortSpot: new go.Spot(0.001, 1, 20, 0),
                alternateChildPortSpot: go.Spot.Left
              })
        });

    // define Converters to be used for Bindings
    function theNationFlagConverter(nation) {
      return "https://www.nwoods.com/go/Flags/" + nation.toLowerCase().replace(/\s/g, "-") + "-flag.Png";
    }

    function theInfoTextConverter(info) {
      var str = "";
      if (info.title) str += "Title: " + info.title;
      if (info.headOf) str += "\n\nHead of: " + info.headOf;
      if (typeof info.boss === "number") {
        var bossinfo = myDiagram.model.findNodeDataForKey(info.boss);
        if (bossinfo !== null) {
          str += "\n\nReporting to: " + bossinfo.name;
        }
      }
      return str;
    }



    // define the Node template
    myDiagram.nodeTemplate =
      $(go.Node, "Auto",
        // the outer shape for the node, surrounding the Table
        $(go.Shape, "Rectangle",
          { stroke: null, strokeWidth: 0 },
                                                  /* reddish if highlighted, blue otherwise */
          new go.Binding("fill", "isHighlighted", function(h) { return h ? "#F44336" : "#A7E7FC"; }).ofObject()),
        // a table to contain the different parts of the node
        $(go.Panel, "Table",
          { margin: 6, maxSize: new go.Size(200, NaN) },
          // the two TextBlocks in column 0 both stretch in width
          // but align on the left side
          $(go.RowColumnDefinition,
            {
              column: 0,
              stretch: go.GraphObject.Horizontal,
              alignment: go.Spot.Left
            }),
          // the name
          $(go.TextBlock,
            {
              row: 0, column: 0,
              maxSize: new go.Size(160, NaN), margin: 2,
              font: "500 16px Roboto, sans-serif",
              alignment: go.Spot.Top
            },
            new go.Binding("text", "name")),
          // the country flag
          $(go.Picture,
            {
              row: 0, column: 1, margin: 2,
              imageStretch: go.GraphObject.Uniform,
              alignment: go.Spot.TopRight
            },
            // only set a desired size if a flag is also present:
            new go.Binding("desiredSize", "nation", function(){ return new go.Size(34, 26) }),
            new go.Binding("source", "nation", theNationFlagConverter)),
          // the additional textual information
          $(go.TextBlock,
            {
              row: 1, column: 0, columnSpan: 2,
              font: "12px Roboto, sans-serif"
            },
            new go.Binding("text", "", theInfoTextConverter))
        )  // end Table Panel
      );  // end Node

    // define the Link template, a simple orthogonal line
    myDiagram.linkTemplate =
      $(go.Link, go.Link.Orthogonal,
        { corner: 5, selectable: false },
        $(go.Shape, { strokeWidth: 3, stroke: "#424242" } ));  // dark gray, rounded corner links

        myDiagram.toolManager.dragSelectingTool.isEnabled = false;

    // set up the nodeDataArray, describing each person/position
    var nodeDataArray = [
      { key: 0, name: "Ban Ki-moon 반기문", title: "Secretary-General of the United Nations", headOf: "Secretariat" },
        { key: 1, boss: 0, name: "Patricia O'Brien", title: "Under-Secretary-General for Legal Affairs and United Nations Legal Counsel", headOf: "Office of Legal Affairs" },
          { key: 3, boss: 1, name: "Peter Taksøe-Jensen",  title: "Assistant Secretary-General for Legal Affairs" },
            { key: 9, boss: 3, name: "Other Employees" },
          { key: 4, boss: 1, name: "Maria R. Vicien - Milburn",  title: "General Legal Division Director", headOf: "General Legal Division" },
            { key: 10, boss: 4, name: "Other Employees" },
          { key: 5, boss: 1, name: "Václav Mikulka",  title: "Codification Division Director", headOf: "Codification Division" },
            { key: 11, boss: 5, name: "Other Employees" },
          { key: 6, boss: 1, name: "Sergei Tarassenko",  title: "Division for Ocean Affairs and the Law of the Sea Director", headOf: "Division for Ocean Affairs and the Law of the Sea" },
            { key: 12, boss: 6, name: "Alexandre Tagore Medeiros de Albuquerque",  title: "Chairman of the Commission on the Limits of the Continental Shelf", headOf: "The Commission on the Limits of the Continental Shelf" },
              { key: 17, boss: 12, name: "Peter F. Croker", title: "Chairman of the Committee on Confidentiality", headOf: "The Committee on Confidentiality" },
                { key: 31, boss: 17, name: "Michael Anselme Marc Rosette",  title: "Vice Chairman of the Committee on Confidentiality" },
                { key: 32, boss: 17, name: "Kensaku Tamaki",  title: "Vice Chairman of the Committee on Confidentiality" },
                { key: 33, boss: 17, name: "Osvaldo Pedro Astiz",  title: "Member of the Committee on Confidentiality" },
                { key: 34, boss: 17, name: "Yuri Borisovitch Kazmin",  title: "Member of the Committee on Confidentiality" },
              { key: 18, boss: 12, name: "Philip Alexander Symonds",  title: "Chairman of the Committee on provision of scientific and technical advice to coastal States", headOf: "Committee on provision of scientific and technical advice to coastal States"},
                { key: 35, boss: 18, name: "Emmanuel Kalngui",  title: "Vice Chairman of the Committee on provision of scientific and technical advice to coastal States" },
                { key: 36, boss: 18, name: "Sivaramakrishnan Rajan",  title: "Vice Chairman of the Committee on provision of scientific and technical advice to coastal States" },
                { key: 37, boss: 18, name: "Francis L. Charles",  title: "Member of the Committee on provision of scientific and technical advice to costal States"},
                { key: 38, boss: 18, name: "Mihai Silviu German",  title: "Member of the Committee on provision of scientific and technical advice to costal States"},
              { key: 19, boss: 12, name: "Lawrence Folajimi Awosika",  title: "Vice Chairman of the Commission on the Limits of the Continental Shelf" },
              { key: 20, boss: 12, name: "Harald Brekke",  title: "Vice Chairman of the Commission on the Limits of the Continental Shelf" },
              { key: 21, boss: 12, name: "Yong-Ahn Park",  title: "Vice Chairman of the Commission on the Limits of the Continental Shelf" },
              { key: 22, boss: 12, name: "Abu Bakar Jaafar",  title: "Chairman of the Editorial Committee", headOf: "Editorial Committee" },
              { key: 23, boss: 12, name: "Galo Carrera Hurtado",  title: "Chairman of the Training Committee", headOf: "Training Committee" },
              { key: 24, boss: 12, name: "Indurlall Fagoonee",  title: "Member of the Commission on the Limits of the Continental Shelf" },
              { key: 25, boss: 12, name: "George Jaoshvili",  title: "Member of the Commission on the Limits of the Continental Shelf" },
              { key: 26, boss: 12, name: "Wenzhang Lu",  title: "Member of the Commission on the Limits of the Continental Shelf" },
              { key: 27, boss: 12, name: "Isaac Owusu Orudo",  title: "Member of the Commission on the Limits of the Continental Shelf" },
              { key: 28, boss: 12, name: "Fernando Manuel Maia Pimentel",  title: "Member of the Commission on the Limits of the Continental Shelf" },
          { key: 7, boss: 1, name: "Renaud Sorieul",  title: "International Trade Law Division Director", headOf: "International Trade Law Division" },
            { key: 13, boss: 7, name: "Other Employees" },
          { key: 8, boss: 1, name: "Annebeth Rosenboom",  title: "Treaty Section Chief", headOf: "Treaty Section" },
            { key: 14, boss: 8, name: "Bradford Smith",  title: "Substantive Legal Issues Head", headOf: "Substantive Legal Issues" },
              { key: 29, boss: 14, name: "Other Employees" },
            { key: 15, boss: 8, name: "Andrei Kolomoets",  title: "Technical/Legal Issues Head", headOf: "Technical/Legal Issues" },
              { key: 30, boss: 15, name: "Other Employees" },
            { key: 16, boss: 8, name: "Other Employees" },
        { key: 2, boss: 0, name: "Heads of Other Offices/Departments" }
    ];

    // create the Model with data for the tree, and assign to the Diagram
    myDiagram.model =
      $(go.TreeModel,
        { nodeParentKeyProperty: "boss",  // this property refers to the parent node data
          nodeDataArray: nodeDataArray });
  }

</script>
</head>
<body onload="init()">
<div id="sample" >
  <div id="myDiagramDiv" style="background-color: #696969; border: solid 1px black; width: 1300px; height: 600px"></div>


</div>
</body>
</html>

您可以在此链接中找到代码https://gojs.net/latest/samples/orgChartStatic.html

1 个答案:

答案 0 :(得分:1)

要停用工具,请将 Tool.isEnabled 设置为false。也许: myDiagram.toolManager.dragSelectingTool.isEnabled = false;