OrgChart icon indicating copy to clipboard operation
OrgChart copied to clipboard

Center orgchart

Open cargie opened this issue 7 years ago • 17 comments

I have an issue on a very large chart. How will I put the chart to center or fit to screen so it will be easy to zoomout/in? Thank you

cargie avatar May 06 '17 19:05 cargie

I would also love this. Very painful to have to scroll to the middle every time it loads.

clickstudio avatar May 21 '17 04:05 clickstudio

What's your favorite vertical-horizontal alignment ? top-center or middle-center ?

dabeng avatar Jun 10 '17 12:06 dabeng

Another thing, does it make sense to scale a huge orgchart to make it fit to screen? It will be a mass.

dabeng avatar Jun 10 '17 14:06 dabeng

Here is the issue I'm facing with chart charts

https://www.awesomescreenshot.com/image/2573365/91eb33cb2f7fd4740a516f854f3ca765

See the top person in the chart is always off page and a long way to the right. It would be great to have a way to center the chart and even have a way to set the initial zoom so it fits on the page.

another great feature would be a way to select a name from a drop down and the person can be located without having to scroll around looking for them.

clickstudio avatar Jun 10 '17 21:06 clickstudio

This is a good example of how the top level node is always centered https://www.basicprimitives.com/index.php?option=com_local&view=local&Itemid=40&lang=en

This is a good example of being able to search for a node http://www.getorgchart.com/Demos

clickstudio avatar Jun 10 '17 22:06 clickstudio

Hi @cargie @clickstudio , I created a Demo for you. Hope you like it :blush:

dabeng avatar Jul 14 '17 05:07 dabeng

Thanks @dabeng. Much appreciated!!

clickstudio avatar Jul 14 '17 06:07 clickstudio

Hi dabeng thanks for OrgChart, maybe not the same problem but when you collapse a node where is to deep some times it lost from screen, i made this, hope helps to solve the problem..


 $('.verticalEdge').on('click', function()
              {
                  setTimeout( function()
                  {
                      centerChart();
                  }  , 500 );
              });

  function centerChart()
            {
                    // Do something after 1 second
                    var parent = $('#chart-container');
                    var child = $('.orgchart');

                    child.css("position","absolute");
                    child.css("top", ((parent.height() - child.outerHeight()) / 2) + parent.scrollTop() + "px");
                    child.css("left", ((parent.width() - child.outerWidth()) / 2) + parent.scrollLeft() + "px");
                    child.css("transform",'matrix(1, 0, 0, 1, 0,0)');            
            }

GeekWiinik avatar Oct 03 '17 17:10 GeekWiinik

@dabeng Is there a way you can make a 'l2r' center position? Just like this Demo

moreishi avatar Jan 19 '18 14:01 moreishi

@dabeng your Demo works fine for static data only when initCompleted is fired. I would like the same thing for dynamic loaded data. Is there a way to detect that data is loaded and i can handle this event?

cppmyjob avatar Jan 25 '18 19:01 cppmyjob

Hi @doarsal Your demo looks very nice Can you please share you code behind? Regards

hadihashem avatar Jul 31 '18 18:07 hadihashem

Hello @doarsal Thank you for sharing

I noticed one issue which I'm also facing: data loading doesn't work on IE I'm facing the same problem due to the use of custom templates https://rawgit.com/dabeng/OrgChart/master/demo/custom-template.html

Besides, I'm struggeling with html2canvas, more precisly with unicode font rendering https://github.com/niklasvh/html2canvas/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3AUnicode Did you experience such problem before?

I appreciate you help Regards

hadihashem avatar Aug 01 '18 05:08 hadihashem

This is a good example of how the top level node is always centered https://www.basicprimitives.com/index.php?option=com_local&view=local&Itemid=40&lang=en

This is a good example of being able to search for a node http://www.getorgchart.com/Demos

Hi @clickstudio, you could do the search?

dromeroDev avatar Feb 19 '19 04:02 dromeroDev

i use this function on each change to center orgchart:

function setContainerMiddle(){
    // set positopn of scrollbar middle
    var outerContent = $('#chart-container');
    var innerContent = $('#chart-container > div');
    outerContent.scrollLeft((innerContent.width() - outerContent.width()) / 2);
    outerContent.scrollTop((innerContent.height() - outerContent.height()) / 2);
}

emf-developer avatar Mar 13 '19 13:03 emf-developer

nice solution! thks

FreezeSoul avatar Aug 31 '19 00:08 FreezeSoul

The functions above did not work for me... perhaps something to do with panning?? I'm not sure, anyway, the below works:


function centerChart()
            {
                    var parent = $('#chart-container');
                    var child = $('.orgchart');
		var childX = child.outerHeight() / -2;
		var childY = (parent.height() / 2) - (child.outerWidth() / 2);
                   	child.css("position","absolute");
                    child.css("transform", 'matrix3d(-6.12323e-17, 1, -1.22465e-16, 0, 1, 6.12323e-17, 0, 0, 7.4988e-33, -1.22465e-16, -1, 0,' + childX + ', ' + childY + ' , 0, 1)');        
            }
	  

You may need to switch childX and childY depending on your charts orientation.

GaryFrewin avatar Sep 30 '19 13:09 GaryFrewin

.orgchart{ display: flex!important; display: flex; align-items: center; justify-content: center; }

abasina09 avatar Apr 13 '22 09:04 abasina09

@abasina09 Simple, I like it. Have you looked into getting an auto-zoom as well by any chance? (centered with a zoom level that shows the whole chart as a starting point)

sabatale avatar Nov 10 '22 00:11 sabatale

.orgchart{ display: flex! important; display: flex; align-items: center; justify-content: center; }

export to does not work when this CSS is applied

vinit-poojary avatar Feb 28 '23 09:02 vinit-poojary