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;

  myDiagram =
    $(go.Diagram, "myDiagramDiv",
      {
        // default text editor is now a SelectBox
        'textEditingTool.defaultTextEditor': window.TextEditorSelectBox, // defined in textEditorSelectBox.js
        'textEditingTool.starting': go.TextEditingStarting.SingleClick,
        "undoManager.isEnabled": true
      }
    );

  // define a simple Node template
  myDiagram.nodeTemplate =
    $(go.Node, "Auto",  // the Shape will go around the TextBlock
      $(go.Shape, "RoundedRectangle", { strokeWidth: 0 },
        // Shape.fill is bound to Node.data.color
        new go.Binding("fill", "color")),
      $(go.TextBlock,
        { margin: 8, editable: true, text: 'Alpha' },  // some room around the text
        new go.Binding('choices'))
    );

  // 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", choices: ['Alpha', 'Beta', 'Gamma', 'Theta'] },
    { key: "Beta", color: "orange", choices: ['Alpha', 'Beta', 'Gamma', 'Theta'] },
    { key: "Gamma", color: "lightgreen", choices: ['Alpha', 'Beta', 'Gamma', 'Theta'] },
    { key: "Delta", color: "pink", choices: ['Alpha', 'Beta', 'Gamma', 'Theta'] }
  ],
  [
    { from: "Alpha", to: "Beta" },
    { from: "Alpha", to: "Gamma" },
    { from: "Beta", to: "Beta" },
    { from: "Gamma", to: "Delta" },
    { from: "Delta", to: "Alpha" }
  ]);
}

/*
 *  Copyright (C) 1998-2024 by Northwoods Software Corporation. All Rights Reserved.
 */
/*
 * This is an extension and not part of the main GoJS library.
 * Note that the API for this class may change with any version, even point releases.
 * If you intend to use an extension in production, you should copy the code to your own source directory.
 * Extensions can be found in the GoJS kit under the extensions or extensionsJSM folders.
 * See the Extensions intro page (https://gojs.net/latest/intro/extensions.html) for more information.
 */

// HTML + JavaScript text editor using an HTML Select Element and HTMLInfo.
// This file exposes one instance of HTMLInfo, window.TextEditorSelectBox
// Typical usage is:
// ```js
//   new go.Diagram(...,
//      {
//        "textEditingTool.defaultTextEditor": window.TextEditorSelectBox,
//        . . .
//      })
// ```
// or:
// ```js
//    myDiagram.toolManager.textEditingTool.defaultTextEditor = window.TextEditorSelectBox;
// ```
// or:
// ```js
//   $(go.Node, . . .,
//     . . .
//       $(go.TextBlock, { textEditor: window.TextEditorSelectBox, . . . })
//     . . .
//   )
// ```
// see /samples/customTextEditingTool.html
// see also textEditorRadioButton.js for another custom editor
// see also textEditor.html for a re-implementation of the default text editor
((window) => {
    const customEditor = new go.HTMLInfo();
    const customSelectBox = document.createElement('select');
    customEditor.show = (textBlock, diagram, tool) => {
        if (!(textBlock instanceof go.TextBlock))
            return;
        // Populate the select box:
        customSelectBox.innerHTML = '';
        let list = textBlock.choices;
        // Perhaps give some default choices if textBlock.choices is null
        if (list === null)
            list = ['Default A', 'Default B', 'Default C'];
        const l = list.length;
        for (let i = 0; i < l; i++) {
            const op = document.createElement('option');
            op.text = list[i];
            op.value = list[i];
            if (list[i] === textBlock.text)
                op.selected = true;
            customSelectBox.add(op);
            // consider also adding the current value, if it is not in the choices list
        }
        // After the list is populated, set the value:
        customSelectBox.value = textBlock.text;
        customSelectBox.addEventListener('change', (e) => {
          tool.acceptText(go.TextEditingAccept.Tab);
        });
        // Do a few different things when a user presses a key
        customSelectBox.addEventListener('keydown', (e) => {
            if (e.isComposing)
                return;
            const code = e.code;
            if (code === 'Enter') {
                // Accept on Enter
                tool.acceptText(go.TextEditingAccept.Enter);
            }
            else if (code === 'Tab') {
                // Accept on Tab
                tool.acceptText(go.TextEditingAccept.Tab);
                e.preventDefault();
            }
            else if (code === 'Escape') {
                // Cancel on Esc
                tool.doCancel();
                if (tool.diagram)
                    tool.diagram.focus();
            }
        }, false);
        const loc = textBlock.getDocumentPoint(go.Spot.TopLeft);
        const pos = diagram.transformDocToView(loc);
        customSelectBox.style.left = pos.x + 'px';
        customSelectBox.style.top = pos.y + 'px';
        customSelectBox.style.position = 'absolute';
        customSelectBox.style.zIndex = (100).toString(); // place it in front of the Diagram
        if (diagram.div !== null)
            diagram.div.appendChild(customSelectBox);
        customSelectBox.focus();
    };
    customEditor.hide = (diagram, tool) => {
        if (diagram.div !== null)
            diagram.div.removeChild(customSelectBox);
    };
    customEditor.valueFunction = () => customSelectBox.value;
    window.TextEditorSelectBox = customEditor;
})(window);

              
            
!
999px

Console