GoJS

repository·master·Indexed 27 days ago

https://github.com/northwoodssoftware/gojs

A professional JavaScript and TypeScript library for creating interactive diagrams, charts, and graphs, such as trees, flowcharts, orgcharts, UML, and BPMN. Version 4.0.3 supports rendering to HTML Canvas or SVG DOM and runs in web browsers, Node.js, or Puppeteer.

Tokens
1.1K
Snippets
4
Records
5
Agent score
44%

What's inside GoJS

  1. Overview of GoJS capabilities

    master

    GoJS is a JavaScript and TypeScript library for creating and manipulating interactive diagrams, charts, and graphs.

    Key Features:

    • Rendering: Renders to an HTML Canvas (with SVG/image export) or directly as SVG DOM.
    • Environments: Runs in web browsers, Node.js, or Puppeteer.
    • Layouts: Includes built-in layouts like tree, force directed, circular, and layered digraph, plus many custom extensions.
    • Data Management: Diagrams are backed by Models, with saving and loading typically via JSON-formatted text.
    • Interactivity: Supports selecting, copying/pasting, dragging, deleting, scrolling, panning, and zooming.
  2. Create a minimal GoJS diagram

    master

    To create a diagram, you need an HTML element to host it, a go.Diagram instance, templates to define how nodes and links look, and a model to provide the data. The following example demonstrates a basic graph with nodes and links using the fluent add() API and data binding.

    <div id="myDiagramDiv" style="width:400px; height:200px;"></div>
    
    <script src="https://cdn.jsdelivr.net/npm/gojs"></script>
    
    <script>
      const myDiagram = new go.Diagram('myDiagramDiv', {
        // create a Diagram for the HTML div element
        'undoManager.isEnabled': true // enable undo & redo
      });
    
      // define a simple Node template
      // the Shape will automatically surround the TextBlock
      myDiagram.nodeTemplate = new go.Node('Auto')
        .add(  // add a Shape and a TextBlock to this "Auto" Panel
          new go.Shape('RoundedRectangle', { strokeWidth: 0, fill: 'white' }) // no border; default fill is white
            .bind('fill', 'color'), // Shape.fill is bound to Node.data.color
          new go.TextBlock({ margin: 8, font: 'bold 14px sans-serif', stroke: '#333' }) // some room around the text
            .bind('text', 'key') // TextBlock.text is bound to Node.data.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' }
        ]
      );
    </script>