0

I am building a tree diagram and looking into making the tree diagram interactive. I want to collapase a node when clicked and let the other nodes move closer to the collapsed node and when clicked(opened) let the other nodes move away so they do not overlap.

The whole tree needs to be interactive because the data will be loaded on demand.

Can someone give me some tips/advise?

I looked into the jQuery position property

I tried out(code):

<div id="svgContainer">
    <div id="el-a" class="one"></div>
    <div class="Container">
        <div id="el-b" class="tiles two"></div>
        <div id="el-c" class="tiles three"></div>
        <div id="el-d" class="tiles four"></div>
    </div>
</div>

CSS

.one{
    height: 100px;
    width: 100px;
    position: absolute;
    top: 50px;
    left: 500px;
    background-color: #42647F;
    border-radius: 4px;
    transition: .2s;
}
.two{
    height: 100px;
    width: 100px;
    position: absolute;
    top: 200px;
    left: 600px;
    background-color: #42647F;
    border-radius: 4px;
    transition: .2s;
    cursor: pointer;
}
.three{
    height: 100px;
    width: 100px;
    position: absolute;
    top: 200px;
    left: 600px;
    background-color: #42647F;
    border-radius: 4px;
    transition: .2s;
    cursor: pointer;
}
.four{
    height: 100px;
    width: 100px;
    position: absolute;
    top: 200px;
    left: 400px;
    background-color: #42647F;
    border-radius: 4px;
    transition: .2s;
    cursor: pointer;
}
.collapse{
    height: 10px;
    width:10px;
    margin-left: 45px;
}

jQuery

  jQuery(document).ready(function() {
                $("#svgContainer").HTMLSVGconnect({
            paths: [
                { start: "#el-a", end: "#el-b"},
                { start: "#el-a", end: "#el-c"},
                { start: "#el-a", end: "#el-d"}
            ]
        });

        $(".tiles").click(function

(){
        $(this).toggleClass("collapse");
    });

        $(".two").position({
            my: "right middle",
            at: "left+25 middle",
            of: ".Container",
            collision:"none",
            using: using
        });
        $(".three").position({
            my: "center middle",
            at: "center middle",
            of: ".Container",
            using: using
        });
        $(".four").position({
            my: "left middle",
            at: "right-25 middle",
            of: ".Container",
            collision: "none",
            using: using
        });
    });
user234562
  • 631
  • 9
  • 20

1 Answers1

0

I think this might help you: jQuery UI: Accordeon

You will have to apply your own styles to it, but the code should be okay ...