Skip to content

Overview

A comprehensive overview of ngDiagram’s core concepts, helping you understand the library’s capabilities without reading the entire documentation.

The simplest way to start is by installing the library, importing the required styles, and creating a component with the NgDiagramComponent and provideNgDiagram() in its providers. The diagram component needs a model with nodes and edges to display.

Quick Start Guide for step-by-step setup

ngDiagram uses a reactive model to manage diagram state. You initialize the model with nodes and edges, each having required properties like ID and position. The model is the single source of truth for your diagram’s data.

Key concepts:

You can also implement custom model adapters to connect to external data sources like databases or real-time services.

State Management → | Custom Model Example → | Model initialization →

Every diagram requires provideNgDiagram() in its component’s providers array, which supplies all necessary services with proper scope isolation. This architecture allows you to have multiple independent diagrams on the same page, each with its own state and services.

Benefits:

  • Isolated service instances per diagram
  • Independent state management
  • Multiple diagrams on one page
  • No conflicts between instances

Architecture Documentation →

ngDiagram provides default nodes that work out of the box with built-in features like selection, dragging, and ports. Default nodes display a label and have standard connection points.

Default node features:

  • Automatic rendering with label (shows node data label or falls back to node ID)
  • Built-in selection and hover states
  • Drag to reposition
  • Two bidirectional connection ports (left and right)
  • Resize handles
  • Rotation handle
  • Automatic port hover indicators
  • Automatic sizing by default (autoSize: true) - nodes resize to fit their content

For specific requirements, you can create custom nodes with any Angular template, form controls, or visual elements you need.

Components for custom nodes:

Nodes Documentation → | Custom Nodes →

Groups are special nodes that can contain other nodes, helping organize complex diagrams into logical sections. They support nesting and group-aware interactions.

Group capabilities:

  • Container for other nodes
  • Nested groups support
  • Visual hierarchy
  • Group-aware dragging
  • NgDiagramGroupHighlightedDirective - Apply highlight styling to custom group nodes during drag-over operations

Groups Documentation →

Edges connect nodes through ports. Default edges automatically calculate paths between nodes and support different routing algorithms. Like nodes, you can create custom edge templates for specialized visualizations.

Edge features:

  • Automatic path calculation
  • Three routing modes (orthogonal, straight, bezier)
  • Labels support (default edges support labels out of the box)
  • Custom arrowheads (customizable using SVG markers)
  • Custom edge templates
  • Selection and hover states

Edges Documentation → | Custom Edges →

Ports define where edges can connect to nodes. Default nodes have two ports (left and right), but you can define custom ports with specific positions and connection rules in custom node templates.

Port system:

  • Default ports: port-left, port-right (bidirectional)
  • Four possible sides: top, right, bottom, left
  • Three connection types: source (outgoing only), target (incoming only), both (bidirectional)
  • Custom port positions and IDs in custom node templates
  • Visual hover indicators when dragging connections

Ports Documentation →

The viewport is the interactive space where all diagram elements are rendered and manipulated. It determines what part of the diagram is visible and supports navigation and scaling.

Viewport features:

  • Zoom in/out for detail or overview
  • Pan to navigate large diagrams
  • All elements are positioned relative to the viewport’s coordinate system

Viewport Features →

The diagram background can display visual patterns to help with alignment and spatial awareness. The NgDiagramBackgroundComponent needs to be added to your diagram template to display the background.

Background capabilities:

Background Documentation →

Custom edges can display labels for showing information along connections. You can add multiple labels with different positions in your custom edge templates. Arrowheads are customizable using SVG markers.

Visual enhancements:

  • Edge labels in custom edges
  • Multiple labels per edge
  • Custom arrowhead designs
  • SVG-based customization for arrowheads

Labels Documentation → | Arrowheads →

Nodes can be configured for different interaction modes. Enable resizing to allow users to change node dimensions, rotation for angular adjustments. Selection state is tracked automatically, but custom components need to implement visual feedback.

Interaction options:

Selection → | Resizing → | Rotation → | Keyboard Shortcuts →

Most diagram behavior is configurable through the config object passed to the diagram component.

Configurable aspects:

  • background - Background dot spacing, cell size, and major lines frequency
  • boxSelection - Box selection behavior (partial inclusion, real-time selection)
  • computeEdgeId - Function to generate unique edge IDs
  • computeNodeId - Function to generate unique node IDs
  • debugMode - Enable additional console logging
  • edgeRouting - Default routing algorithm (orthogonal, bezier, polyline) and routing-specific settings
  • grouping - Rules for which nodes can be grouped together
  • linking - Edge creation validation, snap distance, and custom edge builders
  • nodeRotation - Rotation snapping angles and default rotatable state
  • resize - Minimum node size constraints and default resizable state
  • selectionMoving - Edge panning behavior when dragging near viewport edges
  • snapping - Grid snapping for dragging and resizing with customizable snap points
  • zIndex - Layer management for selected elements and edge-node relationships
  • zoom - Min/max zoom levels, zoom step, and zoom-to-fit settings

ngDiagram provides injectable services for all diagram operations. Services are the only way to safely update the model and control diagram behavior programmatically.

Core services:

Services use Angular signals for reactive state management, making it easy to build reactive UI components.

Services Documentation →

The diagram emits events for user interactions and state changes. Subscribe to these events to react to user actions or synchronize with external systems.

Available events:

Events can be subscribed to via @Output bindings on the ng-diagram component or programmatically through NgDiagramService.addEventListener().

Edges support multiple routing algorithms for different visual styles. You can control how edges are drawn between nodes using both automatic and manual approaches.

Built-in routing algorithms:

  • Orthogonal - Right-angle paths between nodes
  • Polyline - Straight line segments between points
  • Bezier - Smooth curved connections with control points

Routing modes:

Set routing per edge with the routing property, or globally through configuration with edgeRouting.defaultRouting. For complete custom routing algorithms, use NgDiagramService.registerRouting().

Routing Documentation →

The palette system enables drag-and-drop node creation. Build your own palette container using the provided components to let users drag items onto the diagram.

Palette components:

Palette features:

  • Drag-and-drop to create nodes at drop location
  • Custom item templates and preview templates
  • Support for creating both regular nodes and group nodes
  • Visual feedback with live preview during drag

Palette Documentation → | Palette Example →

ngDiagram uses a middleware system that allows you to intercept and modify any state changes. Register custom middleware via NgDiagramService.registerMiddleware() to override any aspect of the application and create low-level features.

Middleware capabilities:

  • Intercept all state updates before they’re applied
  • Modify or cancel operations
  • Add custom side effects
  • Implement complex business logic
  • Create custom behaviors and constraints

Middleware Documentation →

ngDiagram provides a comprehensive CSS variable system for theming and customization. You can override colors, borders, and other visual properties to match your application’s design.

Styling Guide →


Explore our Examples to see these concepts in action.