[visualization-api] Re: Organizational Chart (Node Children)

2014-12-03 Thread Mohamed El Ghandour


Answered by Juvian: http://stackoverflow.com/users/3308055/juvian 

Regarding to the problem of getting children and subchildren of selected, 
you need to deal with recursion: 

Here is an example: http://jsfiddle.net/36gg3ro1/1/

google.visualization.events.addListener(chart, 'select', function(){
  var children=[]
  var selected=chart.getSelection()[0].row;

  function getChilds(index){ // recursive function, adds children of 
index (row)
  var childs=chart.getChildrenIndexes(index); // get children 
indexes of current index
  for(var i = 0; i  childs.length;i++){ // for each children
  children.push(data.getValue(childs[i],0)) // add the title
  getChilds(childs[i]) // and call the function with this 
children index, to get their children and so on  this is recursive
  }
  }

  getChilds(selected) // start recursive function with selected index
  console.log(children)

})





On Tuesday, 2 December 2014 13:05:33 UTC+2, Mohamed El Ghandour wrote:

 Hi,
 I have an organizational chart with many levels, the image below is taken 
 from a part of it.
 I try to get all the childs and sub childs of a selected node, like if 
 Power Business Unit node selected it get all the 3 childs and for every 
 single child do the same. I got the first level but I can't get the depth 
 of the tree to provide the number of loops to reach the last child.

 1- How can I get the last child in the chart? how to get the depth of the 
 tree?
 2- Is there a zoom in/zoom out toolbar or something, that I can add to the 
 chart?

 that is my code of drawing:

  google.load('visualization', '1', { packages: ['table', 
 'orgchart'] });
 google.setOnLoadCallback(drawChart);
 function drawChart() {

 var data = new google.visualization.DataTable();
 data.addColumn('string', 'NODE');
 data.addColumn('string', 'PARENT');
 data.addColumn('string', 'NODEID');

 
 data.addRows(JSON.parse(document.getElementById(%=HiddenField1.ClientID%).value));
 //
 var chart = new 
 google.visualization.OrgChart(document.getElementById('chart_div'));

 function selectHandler() {
 var selectedItem = chart.getSelection()[0];
 if (selectedItem) {
 var oInd = data.getValue(selectedItem.row, 2);

 var arrLoop = 
 chart.getChildrenIndexes(selectedItem.row);
 var arrConcat = 
 chart.getChildrenIndexes(selectedItem.row);


 for (var i = 0; i  arrLoop.length; i++) {
 var arr2 = new 
 Array(chart.getChildrenIndexes(arrLoop[i]).length);
 arr2 = chart.getChildrenIndexes(arrLoop[i]);
 for (var j = 0; j  arr2.length; j++) {
 arrConcat.push(arr2[j]);
 }
 arrConcat.concat(arr2);
 }

 var arrChilds = new Array(arrConcat.length);

 for (var i = 0; i  arrConcat.length; i++) {
 arrChilds[i] = data.getValue(arrConcat[i], 2);
 }
 drawTable(oInd, arrChilds);
 }
 }

 google.visualization.events.addListener(chart, 'select', 
 selectHandler);

 chart.draw(data, { allowHtml: true });

 //for (var i = 0; i  data.getNumberOfRows() ; i++) {
 //chart.collapse(i, true);
 //}
 }





 https://lh4.googleusercontent.com/-VFmgSBVUuNE/VH2ZgKPiKTI/AHI/lk0m4QlzCkw/s1600/OrgChart.JPG


-- 
You received this message because you are subscribed to the Google Groups 
Google Visualization API group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.


[visualization-api] Organizational Chart (Node Children)

2014-12-02 Thread Mohamed El Ghandour


Hi,
I have an organizational chart with many levels, the image below is taken 
from a part of it.
I try to get all the childs and sub childs of a selected node, like if 
Power Business Unit node selected it get all the 3 childs and for every 
single child do the same. I got the first level but I can't get the depth 
of the tree to provide the number of loops to reach the last child.

1- How can I get the last child in the chart? how to get the depth of the 
tree?
2- Is there a zoom in/zoom out toolbar or something, that I can add to the 
chart?

that is my code of drawing:

 google.load('visualization', '1', { packages: ['table', 
'orgchart'] });
google.setOnLoadCallback(drawChart);
function drawChart() {

var data = new google.visualization.DataTable();
data.addColumn('string', 'NODE');
data.addColumn('string', 'PARENT');
data.addColumn('string', 'NODEID');


data.addRows(JSON.parse(document.getElementById(%=HiddenField1.ClientID%).value));
//
var chart = new 
google.visualization.OrgChart(document.getElementById('chart_div'));

function selectHandler() {
var selectedItem = chart.getSelection()[0];
if (selectedItem) {
var oInd = data.getValue(selectedItem.row, 2);

var arrLoop = 
chart.getChildrenIndexes(selectedItem.row);
var arrConcat = 
chart.getChildrenIndexes(selectedItem.row);


for (var i = 0; i  arrLoop.length; i++) {
var arr2 = new 
Array(chart.getChildrenIndexes(arrLoop[i]).length);
arr2 = chart.getChildrenIndexes(arrLoop[i]);
for (var j = 0; j  arr2.length; j++) {
arrConcat.push(arr2[j]);
}
arrConcat.concat(arr2);
}

var arrChilds = new Array(arrConcat.length);

for (var i = 0; i  arrConcat.length; i++) {
arrChilds[i] = data.getValue(arrConcat[i], 2);
}
drawTable(oInd, arrChilds);
}
}

google.visualization.events.addListener(chart, 'select', 
selectHandler);

chart.draw(data, { allowHtml: true });

//for (var i = 0; i  data.getNumberOfRows() ; i++) {
//chart.collapse(i, true);
//}
}




https://lh4.googleusercontent.com/-VFmgSBVUuNE/VH2ZgKPiKTI/AHI/lk0m4QlzCkw/s1600/OrgChart.JPG

-- 
You received this message because you are subscribed to the Google Groups 
Google Visualization API group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.