Recently, an internal project needs to be used.Organization chart(Organization chart), looking for some open-source projects and their class libraries, found that there is no ready-made JS class libraries available for use, find some simple JS implementations, but the interface and its operations are simple, but the effort is not enough, after several days of domestic and foreign searches, I found a very good solution. Here I will share it with you.
Javascript InfoVis tools
This open-source javascript class library can generate very cool structures and graphics. I chose one of the spacetree types as the basis of my organizational structure. This type of graphics supports the following features:
Allows you to expand charts in the upper, lower, and left directions.
Support for Child node Extension
Supports chart drag and drop
Supports chart Scaling
The entire class library is exceptionally powerful and is suitable for complex graphic functional requirements, as shown below:
Copy to ClipboardReference: [www.bkjia.com] // Create a new instance
Var st = new $ jit. ST ({
'Injectinto': 'orgchar ',
// Set duration for the animation
Duration: 800,
// Set animation transition type
Transition: $ jit. Trans. Quart. easeInOut,
LevelDistance: 50,
LevelsToShow: 1,
Node :{
Height: 45,
Width: 120,
Type: 'nodeline ',
Color: '# 23A4FF ',
LineWidth: 2,
Align: "center ",
Overridable: false
},
Edge :{
Type: 'nginx ',
LineWidth: 2,
Color: '# 23A4FF ',
Overridable: true
},
// Retrieve the json data from database and create json objects for org chart
Request: function (nodeId, level, onComplete ){
// Generate sample data
If (nodeId! = 'Peter wang '& nodeId! = 'William chen '){
Var data = [{fullname: 'Peter wang ', title: 'engine'}, {fullname: 'William chen', title: 'Senior engine'}];
Var objs = [];
For (var I = 0; I <data. length; I ++ ){
Var tmp = data [I];
Var obj = {"id": data [I]. fullname, "name": "<div class = 'orgchartnode'>" + data [I]. fullname + "</div> (" + data [I]. title + ")"};
Objs. push (obj );
}
Var nodeobjs = {};
Nodeobjs. id = nodeId;
Nodeobjs. children = objs;
OnComplete. onComplete (nodeId, nodeobjs );
} Else {
Var nodeobjs = {};
OnComplete. onComplete (nodeId, nodeobjs );
}
},
The above Code creates an instance. Pay attention to the request section. This code is used to retrieve the byte points to be displayed after a node is clicked. in actual application, we inject the data retrieved from the database into the json object to generate subnodes.
Copy to ClipboardReference: [www.bkjia.com] // Change chart direction
$ ("# Top"). click (function (){
$ ("# Orgchartori"). fadeOut ();
St. switchPosition ($ ("# top"). attr ("id"), "animate ",{
OnComplete: function (){
$ ("# Orgchartori"). fadeIn ();
}
});
});
$ ("# Bottom"). click (function (){
$ ("# Orgchartori"). fadeOut ();
St. switchPosition ($ ("# bottom"). attr ("id"), "animate ",{
OnComplete: function (){
$ ("# Orgchartori"). fadeIn ();
}
});
});
$ ("# Right"). click (function (){
$ ("# Orgchartori"). fadeOut ();
St. switchPosition ($ ("# left"). attr ("id"), "animate ",{
OnComplete: function (){
$ ("# Orgchartori"). fadeIn ();
}
});
});
$ ("# Left"). click (function (){
$ ("# Orgchartori"). fadeOut ();
St. switchPosition ($ ("# right"). attr ("id"), "animate ",{
OnComplete: function (){
$ ("# Orgchartori"). fadeIn ();
}
});
});
The above code is used to controlOrganization chartThe graphic display direction. For more information about the effect, see the demo.
Online Demo online debugging
For a demonstration of drag-and-drop and zoom effects, see the following application cases.
Application Case: http://www.triplifes.com
Related materials: http://thejit.org/
Source: Javascript ization Chart)