DaHaiz / ngFlowchart

ngFlowchart enables drag&drop modelling of graphs in web applications
http://one-logic.github.io/ngFlowchart/dist/
MIT License
103 stars 64 forks source link

ngFlowchart Bower version Build Status Dependency Status

ngFlowchart is an easy and customizable way to draw flowchart graphs using AngularJS. Its main features are:

Live Demo

Visit the live demo

Getting Started

Install ngFlowchart via bower with bower install ngFlowchart

Run gulp in the ngFlowchart directory to start an interactive demo.

Table of Contents

Integration

Add stylesheet:

<link rel="stylesheet" href="https://github.com/DaHaiz/ngFlowchart/blob/master/bower_components/ngFlowchart/dist/flowchart.css" type="text/css">

Include script:

<script src="https://github.com/DaHaiz/ngFlowchart/raw/master/bower_components/ngFlowchart/dist/ngFlowchart.js"></script>

Use the fc-canvas directive to display the graph:

<fc-canvas model="model" selected-objects="flowchartselected" edge-style="line"></fc-canvas>

Add model and selectedObjects to your scope:

model = {
  nodes: [
    { 
      id: 1, 
      x: 10, 
      y: 10, 
      name: "My first node", 
      connectors: [
        {
          id: 1, 
          type: bottomConnector
        }
      ]
    },
    { 
      id: 2, 
      x: 50, 
      y: 50, 
      name: "My seconde node", 
      connectors: [
        {
          id: 2, 
          type: topConnector
        }
      ]
    }
  ],
  edges: [
    {
      source: 1, 
      destination: 2,
      active: false
    }
  ]
};

flowchartselected = [];

Your site should now show your first flowchart with two connected nodes.

Api

The model

{
  nodes: [Node],
  edges: [Edge]
}

Node

{
  id: integer,
  name: string,
  x: integer, // x-coordinate of the node relative to the canvas.
  y: integer, // y-coordinate of the node relative to the canvas.
  connectors: [Connector]
}

Connector

{
  id: integer,
  type: string
}

Edge

{
 source: Connector.id
 destination: Connector.id
 active: boolean
}

fc-canvas attributes

The Node template

Easily change the look and feel of the graph by writing your own node template. This is a simple AngularJS template registered with our NodeTemplatePath provider:

angular.module('yourApp', ['flowchart'])
  .config(function(NodeTemplatePathProvider) {
    NodeTemplatePathProvider.setTemplatePath("path/to/your/template/node.html");
  })

The $scope in this template includes following variables:

Modelservice

Our Modelfactory could contain some interesting functions for you to use. Instantiate it with Modelfactory(model, selectedObjects) with model and selectedObjects as references to the same objects you gave the canvas.

Browser Support

ngFlowchart supports Chrome, Firefox, Opera and IE10+. Safari is not supported. PRs to expand support are welcome.

Right now it is only possible to have one canvas per site, this may changes in future.

Sponsors

Thanks to BrowserStack for kindly helping us improve cross browser support.