Giter Site home page Giter Site logo

muskanmahajan37 / ngflowchart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thingsboard/ngflowchart

0.0 0.0 0.0 606 KB

ngFlowchart enables drag&drop modelling of graphs in web applications

Home Page: http://one-logic.github.io/ngFlowchart/dist/

License: MIT License

JavaScript 95.45% HTML 4.33% CSS 0.23%

ngflowchart's Introduction

ngFlowchart Bower version Build Status Dependency Status

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

  • Native AngularJS support
  • An easy way to customize the look of nodes, by writing your own template
  • Automatically adjusts size to its graph
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="bower_components/ngFlowchart/dist/flowchart.css" type="text/css">

Include script:

<script src="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

  • model The model.
  • selected-objects The selected nodes and edges as objects. Example: [{id: 1, name: "First node", {...}}, {source: 1, destination: 2}]
  • edge-style "line" or "curved".
  • automatic-resize If true the canvas will adjust its size while node dragging and allow "endless" dragging.
  • drag-animation Either repaint (default) or shadow where repaint repaints the whole flowchart including edges according to new position while shadow show the new position only by showing a shadow of the node at the new position and repaints the edges only at the end of dragging.
  • callbacks Object with callbacks.
    • edgeAdded will be called if an edge is added by ngFlowchart.
    • edgeDoubleClick(event, edge) will be called when an edge is doubleclicked.
    • edgeMouseOver(event, edge) will be called if the mouse hovers an edge.
    • isValidEdge(sourceConnector, destinationConnector) will be called, when the user tries to connect to edges. Returns true if this is an valid edge in your application or false otherwise.
    • edgeRemoved(edge) will be called if an edge has been removed
    • nodeRemoved(node) will be called if a node has been removed
    • nodeCallbacks an object which will be available in the scope of the node template. This is usefull, to register a doubleclick handler on a node or similiar things. Every method that is handed into the nodeCallbacks will be available in the node template via the callbacks attribute.

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:

  • node The node object from the model.
  • modelservice The modelservice instance of this canvas.
  • underMouse true when the mouse hovers this node, false otherwise.
  • selected true if this node is selected, false otherwise.
  • mouseOverConnector The connector object from the model witch is hovered by the mouse or null.
  • draggedNode The node object from the model witch is dragged.
  • nodeCallbacks The object you assigned to nodeCallbacks on the callbacks attribute of fc-canvas.

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.

ngflowchart's People

Contributors

perfuchs avatar ikulikov avatar dahaiz avatar sebastianhenneberg avatar vvlladd28 avatar mathiasmoeller avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.