BALKANGraph / OrgChartJS

OrgChart JS is a simple, flexible and highly customizable organization chart plugin for presenting the structure of your organization and the relationships in an elegant way.
https://balkan.app/orgchartjs
252 stars 84 forks source link

Create Collaps ALL button in OrgChartJS UI #858

Open srhong007 opened 2 months ago

srhong007 commented 2 months ago

Hello.

Because it is implemented as an organization chart provided by OrgChart JS, an expand all button is provided, but a collapse all button is not provided.

Instead of creating a separate Collapse All button, we placed it directly in the OrgChart UI and implemented the source code so that it can only be closed up to the expansion level (-) set in the options.

https://cafe.naver.com/gisapplication/1227

image 계통도펼치기s

  1. Click the Expand All button to open all images. Create a button image.

    • Search for "OrgChart.toolbarUI.expandAllIcon" in the OrgChart.js source. Create "OrgChart.toolbarUI.collapseAllIcon" below it and change x1, y1 to x2, x2 in the svg source indicated by the arrow.
    1. Code the click event of the Collapse All button created in the UI.
      • In OrgChart.js source, find source for existing expand all "o = this.div.querySelector('[data-tlbr="expand"]')" element. Then, insert "oo = this.div.querySelector('[data-tlbr="collapse"]')" to find the element below it.
      • Implement the Collapse All click event below the source code that implemented the click event for the Expand All element above.

o && o.addEventListener("click", function() { l.obj.expand(null, "all"); l.obj.fit(); }), oo && oo.addEventListener("click", function() { //l.obj.collapse(null, "all"); //srhong007 var collapse_level = l.obj.config.collapse.level || 0; collapse_level-=2; Node_collapse(l.obj.roots); l.obj.fit();

        function Node_collapse(_Node){
            for(var ii=0; ii< _Node.length; ii++){
                var _children = _Node[ii].children;
                if(_children && _children.length > 0){
                    Node_collapse(_children);
                }
                var _level = _Node[ii].level;
                var childrenIds = _Node[ii].childrenIds;
                if((_level >= collapse_level) && (childrenIds && childrenIds.length > 0)){
                    l.obj.collapse(_Node[ii].id, _Node[ii].childrenIds, !1);
                }
            }
        }
    })
plamen-peshev commented 2 months ago

It is very neat solution!

Is it possible to implement the same functionality here and to share the link

srhong007 commented 2 months ago

You can include it in the existing source, but I tried it in an additional way. This is a function that uses a simple recursive call. share link https://code.balkan.app/create-collaps-all-button-in-orgchartjs-ui#JS

ZornitsaPesheva commented 2 months ago

Thank you for the code example. You can see here our collapse all example: https://code.balkan.app/org-chart-js/collapse-children-on-expand-and-collapse-all-button#JS

srhong007 commented 2 months ago

Thank you. I already saw it too.

  1. Instead of using only "root" in "Collapse All", I created a new one because separate coding was needed.
  2. I also needed the ability to collapse to the desired "level". So, I tried making it a simple "recursive function" without any additional coding.