Creation organisation tree with options like 1 Parent to Multiple Children, Multiple Parents to Multiple Children, – Multiple Parents to one Child

I want to make organisation tree below is my code

<div class="mt-5">
    <div class="flex justify-center">
        <div class="w-56 HRInfo rounded-lg shadow-xl bg-white relative" id="item0">
            <div class="flex gap-10 p-1 py-2 items-center borderTop">
                <div class="flex gap-2 items-center ml-3">
                    <h2 class="font-semibold text-sm overflow-hidden whitespace-nowrap w-32 text-ellipsis">Node 1</h2>
                </div>
            </div>
        </div>
    </div>

    <div class="w-56 HRInfo rounded-lg shadow-xl bg-white relative" id="item1">
        <div class="flex gap-10 p-1 py-2 items-center borderTop">
            <div class="flex gap-2 items-center ml-3">
                <h2 class="font-semibold text-sm overflow-hidden whitespace-nowrap w-32 text-ellipsis">Node 2</h2>
            </div>
        </div>
    </div>

    <div class="w-56 HRInfo rounded-lg shadow-xl bg-white relative" id="item2">
        <div class="flex gap-10 p-1 py-2 items-center borderTop">
            <div class="flex gap-2 items-center ml-3">
                <h2 class="font-semibold text-sm overflow-hidden whitespace-nowrap w-32 text-ellipsis">Node 3</h2>
            </div>
        </div>
    </div>

    <div class="w-56 HRInfo rounded-lg shadow-xl bg-white relative" id="item3">
        <div class="flex gap-10 p-1 py-2 items-center borderTop">
            <div class="flex gap-2 items-center ml-3">
                <h2 class="font-semibold text-sm overflow-hidden whitespace-nowrap w-32 text-ellipsis">Node 4</h2>
            </div>
        </div>
    </div>

    <div class="w-56 HRInfo rounded-lg shadow-xl bg-white relative" id="item3">
        <div class="flex gap-10 p-1 py-2 items-center borderTop">
            <div class="flex gap-2 items-center ml-3">
                <h2 class="font-semibold text-sm overflow-hidden whitespace-nowrap w-32 text-ellipsis">Node 5</h2>
            </div>
        </div>
    </div>
</div>

<!-- Include required libraries -->
<script src="https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsPlumb/2.15.6/js/jsplumb.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>

<script>
    document.addEventListener('DOMContentLoaded', function () {
        jsPlumb.ready(function () {
            jsPlumb.setContainer(document.body);

            // Make nodes draggable
            interact('.HRInfo').draggable({
                onmove: function (event) {
                    var target = event.target;
                    var x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx;
                    var y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;

                    target.style.transform = 'translate(' + x + 'px, ' + y + 'px)';
                    target.setAttribute('data-x', x);
                    target.setAttribute('data-y', y);
                },
                inertia: true
            });

            // Add endpoints for each node
            document.querySelectorAll('.HRInfo').forEach(function (el) {
                jsPlumb.addEndpoint(el, {
                    anchor: 'Continuous',
                    isSource: true,
                    isTarget: true,
                    endpoint: 'Dot'
                });
            });

            var selectedNodes = [];

            // Node selection logic
            document.querySelectorAll('.HRInfo').forEach(function (card) {
                card.addEventListener('click', function (event) {
                    var target = event.target.closest('.HRInfo');
                    if (target) {
                        selectNode(target);
                    }
                });
            });

            function selectNode(node) {
                if (selectedNodes.includes(node)) {
                    selectedNodes = selectedNodes.filter(n => n !== node);
                    node.style.border = "";
                } else {
                    selectedNodes.push(node);
                    node.style.border = "2px solid blue";
                }
            }

            // Function to connect selected nodes
            function connectSelectedNodes() {
                if (selectedNodes.length < 2) {
                    alert('Select at least two nodes to connect.');
                    return;
                }

                for (var i = 0; i < selectedNodes.length - 1; i++) {
                    jsPlumb.connect({
                        source: selectedNodes[i],
                        target: selectedNodes[i + 1],
                        overlays: [
                            ["Arrow", { location: 1 }]
                        ]
                    });
                }

                // Clear selection after connecting
                selectedNodes.forEach(n => n.style.border = "");
                selectedNodes = [];
            }

            // Add a button to connect nodes
            var connectButton = document.createElement('button');
            connectButton.textContent = 'Connect Nodes';
            connectButton.style.marginTop = '20px';
            connectButton.addEventListener('click', connectSelectedNodes);
            document.body.appendChild(connectButton);

            // Add a button to clear all connections
            var clearButton = document.createElement('button');
            clearButton.textContent = 'Clear Connections';
            clearButton.style.marginTop = '20px';
            clearButton.addEventListener('click', function () {
                jsPlumb.deleteEveryConnection();
                selectedNodes.forEach(n => n.style.border = "");
                selectedNodes = [];
            });
            document.body.appendChild(clearButton);
        });
    });
</script>

In the above code I have 5 nodes please establish connection between these nodes So that users know which node is connected to other.

The relationship is as follows:

– 1 Parent to Multiple Children
– Multiple Parents to Multiple Children
– Multiple Parents to one Child

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật