Giter Club home page Giter Club logo

orgchartts's Introduction

OrgChart

Foreword

  • First of all, this is a porting to typescript of dabeng's great work -- OrgChart.js. So I've to thank him for that.
  • Secondarily: I've extended the compatibility of this component to IE11/Edge and improved some issues related to zoom and pan.
  • The rest of this readme it's a copy of the original one.
  • Font Awesome provides us with administration icon, second level menu icon and loading spinner.

Features

  • Supports both local data and remote data (JSON).
  • Smooth expand/collapse effects based on CSS3 transitions.
  • Align the chart in 4 orientations.
  • Allows user to change orgchart structure by drag/drop nodes.
  • Allows user to edit orgchart dynamically and save the final hierarchy as a JSON object.
  • Supports exporting chart as a picture.
  • Supports pan and zoom
  • Users can adopt multiple solutions to build up a huge organization chart(please refer to multiple-layers or hybrid layout sections)
  • touch-enabled plugin for mobile divice

Browser compatibility

  • Chrome
  • Firefox
  • IE11
  • Edge
  • Safari

Getting started

Build

npm install
gulp build

Serve

gulp serve

Now, you can try out all the demos on http://localhost:3000.

Note: your nodejs version should be 4+.

Usage

Instantiation Statement

let orgchart = new OrgChart(options);

Structure of Datasource

{
  'id': 'rootNode', // It's a optional property which will be used as id attribute of node
  // and data-parent attribute, which contains the id of the parent node
  'className': 'top-level', // It's a optional property which will be used as className attribute of node.
  'nodeTitlePro': 'Lao Lao',
  'nodeContentPro': 'general manager',
  'relationship': relationshipValue, // Note: when you activate ondemand loading nodes feature,
  // you should use json datsource (local or remote) and set this property.
  // This property implies that whether this node has parent node, siblings nodes or children nodes.
  // relationshipValue is a string composed of three "0/1" identifier.
  // First character stands for wether current node has parent node;
  // Scond character stands for wether current node has siblings nodes;
  // Third character stands for wether current node has children node.
  'children': [ // The property stands for nested nodes. "children" is just default name you can override.
    { 'nodeTitlePro': 'Bo Miao', 'nodeContentPro': 'department manager', 'relationship': '110' },
    { 'nodeTitlePro': 'Su Miao', 'nodeContentPro': 'department manager', 'relationship': '111',
      'children': [
        { 'nodeTitlePro': 'Tie Hua', 'nodeContentPro': 'senior engineer', 'relationship': '110' },
        { 'nodeTitlePro': 'Hei Hei', 'nodeContentPro': 'senior engineer', 'relationship': '110' }
      ]
    },
    { 'nodeTitlePro': 'Yu Jie', 'nodeContentPro': 'department manager', 'relationship': '110' }
  ],
  'otherPro': anyValue
};

Options

NameTypeRequiredDefaultDescription
chartContainerstringyesselector usded to query the wrapper element of orgchart. It could be an id or an unique className.
datajson or stringyesdatasource usded to build out structure of orgchart. It could be a json object or a string containing the URL to which the ajax request is sent.
panbooleannofalseUsers could pan the orgchart by mouse drag&drop if they enable this option.
zoombooleannofalseUsers could zoomin/zoomout the orgchart by mouse wheel if they enable this option.
directionstringno"t2b"The available values are t2b(implies "top to bottom", it's default value), b2t(implies "bottom to top"), l2r(implies "left to right"), r2l(implies "right to left").
verticalDepthintegernoUsers can make use of this option to align the nodes vertically from the specified depth.
toggleSiblingsRespbooleannofalseOnce enable this option, users can show/hide left/right sibling nodes respectively by clicking left/right arrow.
ajaxURLjsonnoIt inclueds four properites -- parent, children, siblings, families(ask for parent node and siblings nodes). As their names imply, different propety provides the URL to which ajax request for different nodes is sent.
depthpositive integerno999It indicates the level that at the very beginning orgchart is expanded to.
nodeTitlestringno"name"It sets one property of datasource as text content of title section of orgchart node. In fact, users can create a simple orghcart with only nodeTitle option.
parentNodeSymbolstringno"fa-users"Using font awesome icon to imply that the node has child nodes.
nodeContentstringnoIt sets one property of datasource as text content of content section of orgchart node.
nodeIdstringno"id"It sets one property of datasource as unique identifier of every orgchart node.
createNodefunctionnoIt's a callback function used to customize every orgchart node. It recieves two parament: "$node" stands for jquery object of single node div; "data" stands for datasource of single node.
exportButtonbooleannofalseIt enable the export button for orgchart.
exportFilenamestringno"Orgchart"It's filename when you export current orgchart as a picture.
chartClassstringno""when you wanna instantiate multiple orgcharts on one page, you should add diffent classname to them in order to distinguish them.
draggablebooleannofalseUsers can drag & drop the nodes of orgchart if they enable this option. **Note**: this feature doesn't work on IE due to its poor support for HTML5 drag & drop API.
dropCriteriafunctionnoUsers can construct their own criteria to limit the relationships between dragged node and drop zone. Furtherly, this function accept three arguments(draggedNode, dragZone, dropZone) and just only return boolen values.
fullHeightbooleannoIt sets the height of chartContainer to fullfil the window.

Methods

I'm sure that you can grasp the key points of the methods below after you try out demo -- edit orgchart.

let orgchart = new OrgChart(options);

Embeds an organization chart in designated container. Accepts an options object and you can go through the "options" section to find which options are required.

.addParent(root, data)

Adds parent node(actullay it's always root node) for current orgchart.

NameTypeRequiredDefaultDescription
rootdom nodeyesroot node of designated orgchartoptions used for overriding initial options
datajson objectyesdatasource for building root node
##### .addSiblings(node, data) Adds sibling nodes for designated node.
NameTypeRequiredDefaultDescription
nodedom nodeyeswe'll add sibling nodes based on this node
datajson objectyesdatasource for building sibling nodes
##### .addChildren(node, data) Adds child nodes for designed node.
NameTypeRequiredDefaultDescription
nodedom nodeyeswe'll add child nodes based on this node
datajson objectyesdatasource for building child nodes
##### .removeNodes(node) Removes the designated node and its descedant nodes.
NameTypeRequiredDefaultDescription
nodedom nodeyesnode to be removed
##### .getHierarchy() This method is designed to get the hierarchy relationships of orgchart for further processing. For example, after editing the orgchart, you could send the returned value of this method to server-side and save the new state of orghcart. ##### .hideChildren(node) This method allows you to hide programatically the children of any specific node(.node element), if it has
Name Type Required Default Description
node dom node Yes None It's the desired dom node that we'll hide its children nodes
##### .showChildren(node) This method allows you to show programatically the children of any specific node(.node element), if it has
Name Type Required Default Description
node dom node Yes None It's the desired dom node that we'll show its children nodes
##### .hideSiblings(node, direction) This method allows you to hide programatically the siblings of any specific node(.node element), if it has
Name Type Required Default Description
node dom node Yes None It's the desired dom node that we'll hide its siblings nodes
direction string No None Possible values:"left","rigth". Specifies if hide the siblings at left or rigth. If not defined hide both of them.
##### .showSiblings(node, direction) This method allows you to show programatically the siblings of any specific node(.node element), if it has
Name Type Required Default Description
node dom node Yes None It's the desired dom node that we'll show its siblings nodes
direction string No None Possible values:"left","rigth". Specifies if hide the siblings at left or rigth. If not defined hide both of them.
##### .getNodeState(node, relation) This method returns you the display state of the related nodes.
Name Type Required Default Description
node dom node Yes None It's the desired dom node that we wanna know its related nodes' display state.
relation String Yes None Possible values: "parent", "children" and "siblings". Specifies the desired relation to return.
The returning object will have the next structure: ```js { "exists": true|false, //Indicates if has parent|children|siblings "visible":true|false, //Indicates if the related nodes are visible } ``` ##### .getRelatedNodes(node, relation) This method returns you the nodes related to the specified node
Name Type Required Default Description
node dom node Yes None It's the desired that we wanna get its related nodes
relation String Yes None Possible values: "parent", "children" and "siblings". Specifies the desired relation to return.

Events

Event TypeAttached DataDescription
nodedropped.orgchartdraggedNode, dragZone, dropZoneThe event's handler is where you can place your customized function after node drop over. For more details, please refer to example drag & drop.

orgchartts's People

Contributors

davidere 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.