Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@swimlane/ngx-graph

swimlane86.9kMIT9.0.1TypeScript support: included

Graph visualization for angular

angular, graph, viz, svg, dataviz, visualization, tree, force-directed, directed acyclic graph, dag

readme

ngx-graph

Join the chat at https://gitter.im/swimlane/ngx-graph

A Graph visualization for angular

Documentation & Demos

https://swimlane.github.io/ngx-graph/

Installation

  1. npm install @swimlane/ngx-graph --save
  2. Import NgxGraphModule into your module
  3. Use the ngx-graph component in your components

Usage

Simple

<ngx-graph
  class="chart-container"
  [view]="[500, 200]"
  [links]="[
    {
      id: 'a',
      source: 'first',
    target: 'second',
      label: 'is parent of'
    }, {
      id: 'b',
      source: 'first',
      target: 'third',
      label: 'custom label'
    }
  ]"
  [nodes]="[
    {
      id: 'first',
      label: 'A'
    }, {
      id: 'second',
      label: 'B'
    }, {
      id: 'third',
      label: 'C'
    }
  ]"
  (select)="onNodeSelect($event)"
>
</ngx-graph>

Custom Templates

<ngx-graph
  class="chart-container"
  [view]="[500, 550]"
  [links]="[
    {
      id: 'a',
      source: 'first',
      target: 'second',
      label: 'is parent of'
    }, {
      id: 'b',
      source: 'first',
      target: 'c1',
      label: 'custom label'
    }, {
      id: 'd',
      source: 'first',
      target: 'c2',
      label: 'custom label'
    }, {
      id: 'e',
      source: 'c1',
      target: 'd',
      label: 'first link'
    }, {
      id: 'f',
      source: 'c1',
      target: 'd',
      label: 'second link'
    }
  ]"
  [nodes]="[
    {
      id: 'first',
      label: 'A'
    }, {
      id: 'second',
      label: 'B'
    }, {
      id: 'c1',
      label: 'C1'
    }, {
      id: 'c2',
      label: 'C2'
    }, {
      id: 'd',
      label: 'D'
    }
  ]"
  [clusters]="[
    {
      id: 'third',
      label: 'Cluster node',
      childNodeIds: ['c1', 'c2']
    }
  ]"
  layout="dagreCluster"
>
  <ng-template #defsTemplate>
    <svg:marker id="arrow" viewBox="0 -5 10 10" refX="8" refY="0" markerWidth="4" markerHeight="4" orient="auto">
      <svg:path d="M0,-5L10,0L0,5" class="arrow-head" />
    </svg:marker>
  </ng-template>

  <ng-template #clusterTemplate let-cluster>
    <svg:g class="node cluster">
      <svg:rect
        rx="5"
        ry="5"
        [attr.width]="cluster.dimension.width"
        [attr.height]="cluster.dimension.height"
        [attr.fill]="cluster.data.color"
      />
    </svg:g>
  </ng-template>

  <ng-template #nodeTemplate let-node>
    <svg:g
      (click)="onNodeClick($event)"
      (dblclick)="onNodeClick($event)"
      class="node"
      ngx-tooltip
      [tooltipPlacement]="'top'"
      [tooltipType]="'tooltip'"
      [tooltipTitle]="node.label"
    >
      <svg:rect
        [attr.width]="node.dimension.width"
        [attr.height]="node.dimension.height"
        [attr.fill]="node.data.color"
      />
      <svg:text alignment-baseline="central" [attr.x]="10" [attr.y]="node.dimension.height / 2">
        {{node.label}}
      </svg:text>
    </svg:g>
  </ng-template>

  <ng-template #linkTemplate let-link>
    <svg:g class="edge">
      <svg:path class="line" stroke-width="2" marker-end="url(#arrow)"></svg:path>
      <svg:text class="edge-label" text-anchor="middle">
        <textPath
          class="text-path"
          [attr.href]="'#' + link.id"
          [style.dominant-baseline]="link.dominantBaseline"
          startOffset="50%"
        >
          {{link.label}}
        </textPath>
      </svg:text>
    </svg:g>
  </ng-template>
</ngx-graph>

Data

Nodes

[
  {
    id: '1',
    label: 'Node A'
  },
  {
    id: '2',
    label: 'Node B'
  },
  {
    id: '3',
    label: 'Node C'
  },
  {
    id: '4',
    label: 'Node D'
  },
  {
    id: '5',
    label: 'Node E'
  },
  {
    id: '6',
    label: 'Node F'
  }
];

Edges

[
  {
    id: 'a',
    source: '1',
    target: '2'
  },
  {
    id: 'b',
    source: '1',
    target: '3'
  },
  {
    id: 'c',
    source: '3',
    target: '4'
  },
  {
    id: 'd',
    source: '3',
    target: '5'
  },
  {
    id: 'e',
    source: '4',
    target: '5'
  },
  {
    id: 'f',
    source: '2',
    target: '6'
  }
];

Clusters

[
  {
    id: 'cluster0',
    label: 'Cluster node',
    childNodeIds: ['2', '3']
  }
];

Building ngx-graph

To get started with development, clone a fork of the repository and run yarn.

Development server

Run yarn start to serve Storybook at http://localhost:6006/. Storybook serves as the development and test environment for ngx-graph.

Building

Run yarn build:storybook to build Storybook to check for production issues. The build artifacts will be stored in the dist/ directory.

Run yarn build:lib to build ngx-graph.

Running tests

Run yarn test to execute the linter.

Release

  • Checkout master (git checkout master)
  • Pull master (git pull)
  • Run tests (yarn ci)
  • Examine log to determine next version (X.Y.Z)
  • Run git checkout -b release/X.Y.Z
  • Update version in projects/swimlane/ngx-graph/package.json.
  • Update changelog in CHANGELOG.md
  • Run yarn package to check the package format
  • Run git commit -am "(release): X.Y.Z"
  • Run git tag X.Y.Z
  • Run git push origin HEAD --tags
  • Run yarn publish:lib
  • Submit PR

Credits

ngx-graph is a Swimlane open-source project; we believe in giving back to the open-source community by sharing some of the projects we build for our application. Swimlane is an automated cyber security operations and incident response platform that enables cyber security teams to leverage threat intelligence, speed up incident response and automate security operations.

SecOps Hub is an open, product-agnostic, online community for security professionals to share ideas, use cases, best practices, and incident response strategies.

changelog

Changelog

9.0.1

  • Fix: Restore versions in package.json to last 4 Angular

9.0.0

  • Breaking: Fix issues with load due to asynchronous node dimension handling
  • Chore: Updated peer dependencies to support angular 18 and newer dependencies
  • Chore: Updated documentation portal to run on Storybook

This release causes possible breaking changes to how ngx-graph displays on load. The changes should make ngx-graph load more reliably.

If you have developed in the repository previously, you may need to delete your node_modules and run yarn after updating to the latest on master. This repository switched from npm to yarn. Multiple development commands in the package.json have moved. See the README.md for an up to date reference.

8.4.0

  • Fix: Fixes a styling issue when using ngx-graph and ngx-charts on the same page
  • Chore: Updated peer dependencies to support new angular versions

8.3.0

  • Feature: new ZoomOptions gives users the ability to force update zoom to fit by omitting internal check and combining auto center to reduce chance of flicker.

  • Feature: enablePreUpdateTransform @Input allows users to disable extra call to updateTransform internally, reducing chance of flicker.

  • Feature: stateChange @Output emits changes in state, allowing users to check status of the graph.

  • Feature: hasGraphDims, hasDims, hasNodeDims, and hasCompoundNodeDims allow users to check elements have dimension.

  • Chore: Update docs.

  • Bug: Update graph dimensions before zoom because sometimes they were out of sync.

  • Bug: Format README instructions.

8.2.4

  • Bug: Position was offset by default (#539)

8.2.3

  • Feature: centerNodesOnPositionChange Input when set to false will ignore dimensions when positioning nodes. Default is set to true to replicate existing behavior.

8.2.2

  • Bug: Getting right values for edge midPoints (#511)

8.2.1

  • Bug: When using deferDisplayUntilPosition compound nodes and clusters may not be displayed (#511)

8.2.0

  • Feature: Update Angular 16 as a peer dependency (#499)
  • Feature: Use deferDisplayUntilPosition Input to display nodes after position returned by layout (#509)

8.1.0

  • Feature: Support Elk Compound Nodes (#502) (#506)
  • Bug: Fix issues with the build (#507)

8.0.3

  • Chore: Bump d3 dependencies (#477)
  • Bug: Fix an issue where fixing a node position would not work (#463)

8.0.2

  • Chore: Add angular 14 as a peer dependency

8.0.1

  • Chore: Add rxjs 7 as a peer dependency
  • Chore: Bump msagl tp 0.0.51 and update msagl layout

8.0.0

  • Chore; Upgrade to angular 13

8.0.0-rc.1

  • Breaking: Remove dependency on ngx-charts (removes the legend input) (#363)
  • Chore: Update angular to 11

7.2.0

  • Chore: Update angular to 10.1

7.1.2

  • Bug: Fix center and fit to screen functionality

7.1.1

  • Chore: Remove console.log

7.1.0

  • Feature: Add Minimap (#324)
  • Bug: Remove extra call to update() on initial render (#303)

7.0.1

  • Chore: update dependecies

7.0.0

  • Bug: Fix pan to node (#288)
  • Bug: Set min and max zoom incase zoom is out of bounce and remove EmptyError (#297)
  • Chore: Update angular to 9.1

7.0.0-rc.1

  • Enhancement: Implement animation of cluster nodes (#234)
  • Enhancement: Support in track pad navigation instead of zoom (#241)
  • Bug: Update events in mouse wheel directive (#232)

6.2.0

  • Enhancement: Support in output click handler for graph clicks (#229)
  • Bug: Fix error when using fullTemplateTypeCheck (#237)
  • Docs: Fix custom curve demo

6.1.0

  • Enhancement: Update dependencies to Angular 8 (#211)
  • Bug: Fix issue with wrong transformation matrix calculated when nodes list is empty (#196)
  • Bug: Update midpoint UI to be updated on drag + update org tree example with mid point UI (#202)
  • Bug: Add parameter check for update mid point function (#209)
  • Docs: add a custom curve demo + create demo components folder (#198)
  • Chore: Added panning enum, enforced types and updated docs (#195)

6.0.1

  • Fix: Added readme and licence files to npm package

6.0.0

  • Breaking: Changed the data format, removed inputs. Please refer to the docs to see what the newly available inputs are.
  • Feature: Added support for different layouts, as well as custom layouts
  • Feature: Improved animations
  • Feature: Added support for clusters

5.5.0

  • Feature: Support multiple links between two nodes (#159)
  • Enhancement: Update layout to spread orphan nodes in a grid (#161)
  • Bug: Fix pan on zoom (#157)
  • Bug: Fix flickering problem with the link data UI. (#160)

5.4.1

  • Bug: Fixes issue where the node width is ignored when setting a custom width (#151)

5.4.0

  • Feature: Adding ability to have custom width and height per each node. (#148)

5.3.0

  • Feature: Adds zoomChange output (#141)
  • Feature: Adds dagre layout options input (#146)
  • Enhancement: Calculates biggest bounding box of tall text fields in node (#84)
  • Bug: Fixes issue not being able to zoom if the current zoom goes out of the min/max zoom range (#146)

5.2.1

  • Fix: Restore the HTML content inside the component (#140)

5.2.0

  • Add new user template in order to show UI data on the link (#138)
  • Feature: Adds zoom to node functionality (#133)
  • Bug: Fixes panning to a location and centering the graph

5.1.2

  • Chore: Update dependencies

5.1.1

  • Bug: TouchEvent not defined in dev mode for non-Chrome browsers (#99)

5.1.0

  • Feature: Allow panning on touch events (#86)
  • Bug: Fix panning speed (#88)

5.0.1

  • Chore: Update dagre version

5.0.0

  • Chore: Upgrade to Angular 6

4.3.0

  • Feature: Add update$, center$, and zoomToFit$ inputs

4.2.0

  • Feature: Add autoCenter and autoZoom inputs (#51)

4.1.0

  • Feature: Allow enable/disable zooming (#64)
  • Feature: Pan to cursor on zoom (#53)
  • Docs: Use ng-template instead of template (#48)

4.0.2

  • Fix: Error in Firefox when trying to render diagram when it is hidden

4.0.1

  • Fix: Fix build for AOT projects.

4.0.0

  • Breaking: Renamed the npm package to @swimlane/ngx-graph
  • Breaking: Renamed the module to NgxGraph
  • Breaking: Renamed the component selector to ngx-graph
  • Docs: Updated readme