Search code examples
vue.jscanvashierarchical-trees

best way to make a hierarchical tree


I need to create a hierarchical tree according to a design provided by our designer.
I want to use Vue.js to do this.
Basically, a user is responsible for a team, and within that team, there are also managers of other teams.
In short, it's a basic hierarchical tree, but there are interactions, for example, in each node, there is a "see more" button that opens a modal on the details of the targeted user, and each user responsible for a team below him has a "see more" button that reveals his team.

enter image description here

There are also links that connect the parent to the child, of course. Just like what the "org chart" of gojs.net offers.

I wonder what the best way is to make this kind of hierarchical tree.
Using HTML, CSS, and JavaScript (what I'm currently doing), I have more accessibility for my content, it is readable from screen readers, I can maximize interactions, like allowing the user to copy text, but the display is not great, if I have too many children, the scroll position is hard to manage and keep, and we lose in practicality and user experience. For example, when I want to expand a user's team, everything moves and I lose focus on what I was looking at.

enter image description here

I know that we can do this kind of thing with a canvas, just like GoJS does. We lose in accessibility and interaction, but we gain in practicality.

Do you have any opinions/suggestions please? I don't really know where to go or how to proceed.

And if the idea is to stick with HTML/CSS/JS, how can I keep the scroll position on the targeted element? Or do you have any leads, examples of what already exists?


Solution

  • Ok, I found a solution without going through the canvas.
    Without going into details, the idea is to get all data and display them, but in opacity 0 and reveal those which must be.
    The scroll therefore takes the entire width, then you just have to put the scroll on the main element on initialization.
    Thus, when the children are revealed, there is no change in content size, so the scroll does not move.
    Accessibility and practicality is better.

    Here, I created fake divs to preserve the content size, as I have a need to align the child content. The blue line = the fake content enter image description here

    enter image description here