Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="https://gojs.net/latest/release/go.js"></script>
  <script src="https://gojs.net/latest/extensions/DragCreatingTool.js"></script>
<body>

  <div id="myDiagramDiv" style="border: solid 3px red; width:600px; height:500px"></div>
  <p><a href="https://gojs.net"/>gojs.net<a/></p>
  <label><input id="ToolEnabled" type="checkbox" checked="checked" onclick="toolEnabled()" />DragCreatingTool enabled</label>
</body>
              
            
!

CSS

              
                
              
            
!

JS

              
                    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",
          {
            // Define the template for Nodes, just some text inside a colored rectangle
            nodeTemplate:
              $(go.Node, "Position",
                { resizable: true, resizeObjectName: 'pic' },
                new go.Binding("position", "pos", go.Point.parse).makeTwoWay(go.Point.stringify),
                // temporarily put selected nodes in Foreground layer
                new go.Binding("layerName", "isSelected", function(s) { return s ? "Foreground" : ""; }).ofObject(),
                $(go.Picture,
                  {
                    //source: "https://gojs.net/latest/samples/images/55x55.png",
                    desiredSize: new go.Size(60, 20),
                    minSize: new go.Size(60, 20),
                    name: 'pic',
                    background: 'red'
                  },
                  new go.Binding("source", "src"),
                  new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify)
                )
              ),
            "undoManager.isEnabled": true
          });

      myDiagram.add(
        $(go.Part,
          { layerName: "Grid", location: new go.Point(0, 0) },
          $(go.TextBlock, "Mouse-down and then drag in the background\nto add a Node there with the drawn size.",
            { stroke: "brown" })
        ));

      // Add an instance of the custom tool defined in DragCreatingTool.js.
      // This needs to be inserted before the standard DragSelectingTool,
      // which is normally the third Tool in the ToolManager.mouseMoveTools list.
      // Note that if you do not set the DragCreatingTool.delay, the default value will
      // require a wait after the mouse down event.  Not waiting will allow the DragSelectingTool
      // and the PanningTool to be able to run instead of the DragCreatingTool, depending on the delay.
      myDiagram.toolManager.mouseMoveTools.insertAt(2,
        $(DragCreatingTool,
          {
            isEnabled: true,  // disabled by the checkbox
            delay: 0,  // always canStart(), so PanningTool never gets the chance to run
            box: $(go.Part,
                   { layerName: "Tool" },
                   $(go.Shape,
                     { name: "SHAPE", fill: null, stroke: "cyan", strokeWidth: 2 })
                 ),
            archetypeNodeData: { color: "white" }, // initial properties shared by all nodes
            insertPart: function(bounds) {  // override DragCreatingTool.insertPart
              // use a different color each time
              this.archetypeNodeData.color = go.Brush.randomColor();
              // call the base method to do normal behavior and return its result
              return DragCreatingTool.prototype.insertPart.call(this, bounds);
            }
          }));



      myDiagram.model = go.Model.fromJSON({ "class": "go.GraphLinksModel",
"nodeDataArray": [ {"category":"picture", "color":"#99ccff", "key":-1, "pos":"-716.03125 -234.515625", "loc":"-716.03125 -234.515625", "src":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB8AAAAUCAIAAAD6C3GtAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAdUSURBVEhLDZL7V9IJGsb5C3bn1GwzY5tToDDeQJCLXL4gchURRREFFRTFC4jcLwJfEFAxb2glGkY6ZZepsfKKpqZ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6Qfh/SQ9Y7qiFGw1CyKcUWbc9VWfLerbtUrW/HIJi2F86Ak4pCMGwpmHZK1TtV22L1+1LI5BE7Z5VP2insD1odh56pfudGv+euA4fWIfUoveHXK9WLU+fJL8MkJM2SjszK2NmLk3+tRRr3l69213wTUC46SRyHzSqs8ZjDilM67ZLF3+tuZjhfnezYG7G8vHd0+6Xs/F969M/7L0siCt2ZryPbdudb7veo1X+X2Mf3zEUeMnbDl/+zVPbPG0bqtAAAAAElFTkSuQmCC"} ],
"linkDataArray": []})
    }

    function toolEnabled() {
      var enable = document.getElementById("ToolEnabled").checked;
      var tool = myDiagram.toolManager.findTool("DragCreating");
      if (tool !== null) tool.isEnabled = enable;
    }

init();
              
            
!
999px

Console