Skip to main content

Collapsible Hierarchy

Use JsPlumb's Hierarchy layout with a custom child resolver function to render a dynamically collapsible and expandable hierarchy.
Vanilla JS
React
Angular
Vue
Svelte
Typescript
Language family
Extinct language
Active language
Selected object
JsPlumb, flowcharts, chatbots, bar charts, decision trees, mindmaps, org charts, gantt charts and more

The source code for this demo is available on Github.

Vanilla JS
https://github.com/jsplumb-demonstrations/collapsible-hierarchy

If you haven't got a license for JsPlumb, we offer 30 day evaluations.

Start a free trial
What is a Collapsible Hierarchy?

A collapsible hierarchy is a tree in which you can dynamically expand/collapse the descendants of any given node. With JsPlumb's Hierarchy layout this is easily achieved, by passing in a custom child resolver function, and tracking the collapsed/expanded state of each node.

The dataset is the Italic language family, for which we got the data from here.

How to use the demo?
  • Use the chevrons on nodes that have them to collapse/expand
  • Click the label for a node to load up a related Wikipedia article
  • Click the 'Zoom to dataset' button to zoom out so the entire current dataset is visible
  • Click the 'Pan to current node' button to bring the current node into the center of the view.
How does the expand/collapse work?

This demo works in a similar way to the popups in the Neighbourhood views demonstration that we released recently: we create a Selection that has a generator method, and we supply that selection to the surface we create. The surface will render the contents of the selection rather than of the underlying Toolkit.

When you toggle the expand/collapse button on a node, we update the `collapsed` property of that node in the Toolkit, and then we instruct the selection to reload. The selection traverses down through the Toolkit's dataset from the root node, stopping at nodes that have `collapsed` set to true. Finally, the surface re-renders the dataset in the selection.

How does the Wiki link work?

Our dataset contains a `link` data property for each language. We bind a click listener to each node's label, and then set the URL for that language on the iframe on the right hand side.

Further reading

Read more about JsPlumb's Hierarchy layout on this page: https://docs.jsplumbtoolkit.com/toolkit/7.x/lib/layout-hierarchy

More Demos
See all demos

Flowchart builder application - JsPlumb, industry standard diagramming and rich visual UI Javascript library

Flowchart

Gantt chart builder application - JsPlumb - Angular, React, Vue, Svelte diagramming library

Gantt

Chatbot builder application - JsPlumb, build diagrams and rich visual UIs fast

Chatbot

Callflow builder application - JsPlumb - JavaScript and Typescript diagramming library that fuels exceptional UIs

Call Flow

Kanban application - JsPlumb, flowcharts, chatbots, bar charts, decision trees, mindmaps, org charts, gantt charts and more

Kanban

Network topology diagram builder - JsPlumb - Angular, React, Vue, Svelte diagramming library

Network Topology

Database schema builder application - JsPlumb, build diagrams and rich visual UIs fast

Database Schema

Org Chart application - JsPlumb, industry standard diagramming and rich visual UI Javascript library

Org Chart

Mindmap builder application - JsPlumb - Angular, React, Vue, Svelte diagramming library

Mindmap

Element grouping demonstration - JsPlumb, leading alternative to GoJS, JointJS and ReactFlow

Nested Groups

Path tracing demonstration - JsPlumb - When you've reached the limit with ReactFlow, we can help!

Path Tracing

Hello world demonstration - JsPlumb - When you've reached the limit with ReactFlow, we can help!

Hello World

Image processor application - JsPlumb, industry standard diagramming and rich visual UI Javascript library

Image Processor

Neighbour views dynamic selections demonstration - JsPlumb - When you've reached the limit with ReactFlow, we can help!

Neighbourhood Views

Active filtering demonstration - JsPlumb, flowcharts, chatbots, bar charts, decision trees, mindmaps, org charts, gantt charts and more

Active Filtering

Org chart layout demonstration - JsPlumb - When you've reached the limit with ReactFlow, we can help!

Hierarchy Layout

CAD Drawing tools demonstration - JsPlumb, leading alternative to GoJS, JointJS and ReactFlow

Connector Editors

Force directed layout demonstration, org chart layout demonstration - JsPlumb, industry standard diagramming and rich visual UI Javascript library

Layouts

Collapsible hierarchy Italic language family demonstration - JsPlumb, leading alternative to GoJS, JointJS and ReactFlow

Collapsible Hierarchy

Nested instances desktop example - JsPlumb, leading alternative to GoJS, JointJS and ReactFlow

Nested Instances