Home
Softono
ng-diagram

ng-diagram

Open source Apache-2.0 TypeScript
531
Stars
36
Forks
4
Issues
2
Watchers
1 week
Last Commit

About ng-diagram

ngDiagram โ€“ An open-source Angular library for creating rich, interactive diagramming experiences. Designed for flexibility and performance, it lets you build everything from simple flows to advanced visual editors with ease

Platforms

Web Self-hosted

Languages

TypeScript

ng-diagram

npm version License: Apache 2.0

A robust Angular library for building interactive diagrams, node-based editors, and visual programming interfaces. Designed with Angular and TypeScript, it offers a complete toolkit to create sophisticated, customizable, and high-performance diagramming applications.

Unlike generic diagramming libraries, ng-diagram is Angular-first - built on Angular signals and templates for seamless integration and performance.

โœจ Features

  • ๐ŸŽฏ Interactive Elements: Draggable, resizable, and rotatable nodes
  • ๐Ÿ”— Customizable Connections: Flexible edges with various routing options (polyline, curved, orthogonal)
  • ๐ŸŽจ Consistent Styling: Built-in design system with CSS variables and themes
  • ๐Ÿงฉ Custom Templates: Define own Angular templates for nodes and edges to create tailored visuals and behaviors
  • ๐Ÿ“ฆ Groups: Container nodes that can be moved together with automatic sizing
  • ๐Ÿ”Œ Extensible Architecture: Plugin-based system for custom behaviors and business logic
  • โšก Reactive State Management: Built on Angular signals for optimal performance
  • ๐ŸŽจ Embedded Palette: Built-in drag-and-drop palette system for adding nodes to diagrams
  • ๐ŸŽ›๏ธ Rich Interactions: Selection, rotation, resizing, panning, zooming, and more

๐Ÿ“š What You Can Build

With ng-diagram, you can create:

  • Flow Diagrams: Process flows, decision trees, and workflow visualizations
  • Node-Based Editors: Visual programming interfaces and data flow editors
  • Network Diagrams: System architectures and network topologies
  • Mind Maps: Hierarchical information structures and brainstorming tools
  • Circuit Diagrams: Electronic schematics and technical drawings
  • Custom Visualizations: Any diagram type with custom node and edge templates

See our Templates for production-ready examples you can fork and customize.

๐ŸŽฎ Try the Demo

See ng-diagram in action: Live Demo | Source Code

๐Ÿงฉ Templates

Production-ready starter kits built with ng-diagram. Fork, customize, ship.

Template Description Demo Source
Org Chart Interactive organizational chart with drag-and-drop reordering, expand/collapse, ELK.js layout, dark/light theme, minimap Live Demo Source

๐Ÿš€ Quick Start

Installation

npm install ng-diagram

Import Styles

โš ๏ธ Important: You must import the required styles for the diagram to display correctly. Because the library uses CSS variables, import the stylesheet in your global file (e.g. src/styles.scss), not inside a component.

/* src/styles.scss */
@import 'ng-diagram/styles.css';

Create Your First Diagram

import { Component } from '@angular/core';
import { NgDiagramComponent, initializeModel, provideNgDiagram } from 'ng-diagram';

@Component({
  imports: [NgDiagramComponent],
  providers: [provideNgDiagram()],
  template: ` <ng-diagram [model]="model" /> `,
  styles: `
    :host {
      flex: 1;
      display: flex;
      height: 100%;
    }
  `,
})
export class MyDiagramComponent {
  model = initializeModel({
    nodes: [
      { id: '1', position: { x: 100, y: 150 }, data: { label: 'Node 1' } },
      { id: '2', position: { x: 400, y: 150 }, data: { label: 'Node 2' } },
    ],
    edges: [
      {
        id: '1',
        source: '1',
        sourcePort: 'port-right',
        targetPort: 'port-left',
        target: '2',
        data: {},
      },
    ],
  });
}

That's it! You now have a working diagram with default node and edge templates.

๐ŸŽจ Customization

Custom Nodes

Create custom node components with any Angular template:

@Component({
  selector: 'app-custom-node',
  template: `
    <div class="custom-node">
      <h3>{{ node.data.title }}</h3>
      <p>{{ node.data.description }}</p>
      <ng-diagram-port id="input" position="left" type="target"> </ng-diagram-port>
      <ng-diagram-port id="output" position="right" type="source"> </ng-diagram-port>
    </div>
  `,
  styles: [
    `
      .custom-node {
        background: #fff;
        border: 2px solid #333;
        border-radius: 8px;
        padding: 16px;
        min-width: 200px;
      }
    `,
  ],
})
export class CustomNodeComponent implements NgDiagramNodeTemplate {
  node = input.required<Node>();
}

Custom Edges

Create custom edge components with unique visual styles:

@Component({
  selector: 'app-custom-edge',
  template: `
    <ng-diagram-base-edge [path]="path" [markerEnd]="markerEnd" [style]="edgeStyle"> </ng-diagram-base-edge>
  `,
})
export class CustomEdgeComponent implements NgDiagramEdgeTemplate {
  edge = input.required<Edge>();

  get path() {
    // Custom path calculation
    return this.calculateCustomPath();
  }
}

๐Ÿ› ๏ธ Core Components

Main Components

  • NgDiagramComponent: The main diagram component
  • NgDiagramPortComponent: Connection points on nodes
  • NgDiagramBaseEdgeComponent: Base edge component for custom edges
  • NgDiagramPaletteItemComponent: Drag-and-drop palette items
  • NgDiagramPaletteItemPreviewComponent: Live preview during drag operations

Services

  • NgDiagramService: Main service providing access to all diagram functionality
  • NgDiagramModelService: Model management and state
  • NgDiagramNodeService: Node operations and manipulation
  • NgDiagramGroupsService: Group node operations and management
  • NgDiagramSelectionService: Selection state management
  • NgDiagramViewportService: Panning and zooming controls
  • NgDiagramClipboardService: Copy, paste, and clipboard operations

Directives

  • NgDiagramNodeSelectedDirective: Node selection styling
  • NgDiagramGroupHighlightedDirective: Group highlighting styling

๐Ÿ‘ฉโ€๐Ÿ’ป About the Creators

ng-diagram is built and maintained by Synergy Codes - a team of developers whoโ€™ve spent over a decade designing and delivering diagramming solutions for clients worldwide.

We are continuously distilling everything we know about building interactive diagrams, editors, and visual tools into this library. Our goal is simple: to empower Angular developers to create diagramming applications faster, easier, and with confidence.

When you use this library, you can be sure youโ€™re in good hands - backed by a team that knows diagrams inside out.

๐Ÿ“– Documentation

For comprehensive documentation, examples, and API reference, visit:

๐Ÿ“š Full Documentation

The documentation includes:

  • Detailed API reference
  • Interactive examples
  • Customization guides
  • Best practices
  • Advanced use cases

๐Ÿค– MCP Server

Use AI assistants like Claude, Cursor, or Windsurf to search ng-diagram docs and API directly from your editor. No browser needed.

{
  "mcpServers": {
    "ng-diagram-docs": {
      "command": "npx",
      "args": ["-y", "@ng-diagram/mcp"]
    }
  }
}

See @ng-diagram/mcp for setup details and Windows configuration.

๐Ÿ”ง Requirements

  • Angular: 18.0.0 or higher
  • TypeScript: 5.6.0 or higher
  • Node.js: 18.19.1 or higher

๐Ÿ“„ License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

๐Ÿ”— Links

๐Ÿ†˜ Support


Built with โค๏ธ by the Synergy Codes team