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

              
                <body onload="init()">
  <div id="myDiagramDiv" style="border: solid 1px black; width:400px; height:400px"></div>
  <p><a href="https://gojs.net"/>gojs.net<a/></p>
</body>
              
            
!

CSS

              
                
              
            
!

JS

              
                function init() {
  var $ = go.GraphObject.make;
  
  go.Shape.defineFigureGenerator('RoundedCorners', (shape, w, h) => {  // predefined in 2.0
    let param1 = shape ? shape.parameter1 : NaN;
    let param2 = shape ? shape.parameter2 : NaN;
    if (isNaN(param1) || param1 < 0) param1 = 5;  // default corner
    if (isNaN(param2) || param2 < 0) param2 = 5;  // default straight length
    param1 = Math.min(param1, w / 3);
    param1 = Math.min(param1, h / 3);

    const cpOffset = param1 * 4 * ((Math.sqrt(2) - 1) / 3);;
    const geo = new go.Geometry()
      .add(new go.PathFigure(w - param1 - param2, 0, false)
        .add(new go.PathSegment(go.PathSegment.Line, w - param1, 0))
        .add(new go.PathSegment(go.PathSegment.Bezier, w, param1, w - cpOffset, 0, w, cpOffset))
        .add(new go.PathSegment(go.PathSegment.Line, w, param1 + param2))
        .add(new go.PathSegment(go.PathSegment.Move, w, h - param1 - param2))
        .add(new go.PathSegment(go.PathSegment.Line, w, h - param1))
        .add(new go.PathSegment(go.PathSegment.Bezier, w - param1, h, w, h - cpOffset, w - cpOffset, h))
        .add(new go.PathSegment(go.PathSegment.Line, w - param1 - param2, h))
        .add(new go.PathSegment(go.PathSegment.Move, param1 + param2, h))
        .add(new go.PathSegment(go.PathSegment.Line, param1, h))
        .add(new go.PathSegment(go.PathSegment.Bezier, 0, h - param1, cpOffset, h, 0, h - cpOffset))
        .add(new go.PathSegment(go.PathSegment.Line, 0, h - param1 - param2))
        .add(new go.PathSegment(go.PathSegment.Move, 0, param1 + param2))
        .add(new go.PathSegment(go.PathSegment.Line, 0, param1))
        .add(new go.PathSegment(go.PathSegment.Bezier, param1, 0, 0, cpOffset, cpOffset, 0))
        .add(new go.PathSegment(go.PathSegment.Line, param1 + param2, 0)));
    return geo;
  });

  myDiagram =
    $(go.Diagram, "myDiagramDiv",
      {
        initialContentAlignment: go.Spot.Center,
        "undoManager.isEnabled": true
      }
    );
  
  var cornerAdornment =
    $(go.Adornment, "Auto",
      $(go.Shape, "RoundedCorners", { strokeWidth: 2, stroke: "darkgray", strokeCap: "round", fill: null /*, parameter2: 10 */ }),
      $(go.Placeholder, { margin: 3 })
    );

  // define a simple Node template
  myDiagram.nodeTemplate =
    $(go.Node, "Auto",  // the Shape will go around the TextBlock
      {
        selectionAdorned: false,
        selectionChanged: (p) => {
          if (p.isSelected) {
            cornerAdornment.adornedObject = p;
            p.addAdornment("Highlight", cornerAdornment);
          } else {
           p.removeAdornment("Highlight"); 
          }
        }
      },
      $(go.Shape, "RoundedRectangle", { strokeWidth: 0 },
        // Shape.fill is bound to Node.data.color
        new go.Binding("fill", "color")),
      $(go.TextBlock,
        { margin: 8 },  // some room around the text
        // TextBlock.text is bound to Node.data.key
        new go.Binding("text", "key"))
    );
  


  // but use the default Link template, by not setting Diagram.linkTemplate

  // create the model data that will be represented by Nodes and Links
  myDiagram.model = new go.GraphLinksModel(
  [
    { key: "Alpha", color: "lightblue" },
    { key: "Beta", color: "orange" },
    { key: "Gamma", color: "lightgreen" },
    { key: "Delta", color: "pink" }
  ],
  [
    { from: "Alpha", to: "Beta" },
    { from: "Alpha", to: "Gamma" },
    { from: "Beta", to: "Beta" },
    { from: "Gamma", to: "Delta" },
    { from: "Delta", to: "Alpha" }
  ]);
}
              
            
!
999px

Console