Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing JavaScript Visualization Toolkit Spacetree Node

I saw many people recommend JavaScript Visualization Toolkit (The JIT) for org chart. I am trying to use SpaceTree of JavaScript InfoVis Toolkit for org chart. The nodes in my org chart is like a component in itself that has employee profile pic, two different icons that show up overlays on click and some 3 lines of simple text having name, title, and number of reports ... each line is separated by a light horizontal line. Something like:

My question is, is it possible to customize the spacetree nodes to such an extent? Can I have Node almost like another "component" or JavaScript object that has its own render method?

I researched on forums and some options I considered are:

  1. $jit.ST.NodeTypes.implement() ... but based on examples I saw, this seem to be helping in customizing node in terms of shapes etc but not like layout drawn above. I am referring to customization something like: http://groups.google.com/group/javascript-information-visualization-toolkit/browse_thread/thread/a4a059cbeb10ba23/ebf472366cdbbdef?lnk=gst&q=spacetree+nodetype#ebf472366cdbbdef
  2. I tried to set innerHtml in onCreateLabel method in example5.js at: but it seems to be doing nothing. Although, I'm not sure if that will be a good way of node customization. Example5 is at the JIT website (I am not allowed to post more than one hyperlink)
  3. Extending Graph.Node ... I am still looking into this option and it this point of time, I don't know how complicated it is to have space tree use Graph.myNode and what will Graph.myNode even look like? I need to think more on those lines and see if it is even feasible.
like image 285
ram Avatar asked Dec 15 '10 21:12

ram


2 Answers

The Spacetree can be customized very much. The nodes can display images or anything we want. We can have custom click events for the nodes. To have custom events, you will have to redraw the whole tree in the onclick event.

Here is an example. On the success function of the click event. Here I have called the click event on the class "clickable"

      $.ajaxSetup({ cache: false });             
           $(".clickable").live("click", function () {              
            $.ajax({
                url: url + "?id=" + parentId + "&ts=" + new Date().getMilliseconds(),
                type: "POST",
                cache: false,
                dataType: "html",
                success: function (html) {                       
                    init(html);                        
                }
              });
            });

The name property can be used to give the image like this:

{id:"90", name:"<a href='javascript:;' class='clickable' name='90'><img src='images/picture.gif' width='30' height='30' alt='pic' /></a>", data:{}, children:[]}

Mark as Answer if useful. thanks.

like image 175
Sunil Raj Avatar answered Oct 26 '22 10:10

Sunil Raj


You could make yourNode the prototype ancestor of Graph.node, set up the slots you want, then add the appropriate render / force code customizations.

like image 26
Cris Stringfellow Avatar answered Oct 26 '22 09:10

Cris Stringfellow