How to render nodes incrementally using cytoscapejs’ layout method?

I am currently using cytoscapejs for my UI to render a graph. I have a big graph that I want to render on-demand or incrementally to avoid performance bottleneck issues. My server sends the graphs in chunks as and when requested.

What I want to do:

  1. Fetch the first chunk from the backend and render it with dagre layout or any layout that is easier for the user to understand. We can call this graph as G0
  2. Fetch the next chunk when the user requests neighbouring subgraph. (Assume that the size of the subgraph is fixed as of now) The fetched graph can be referred as G1
  3. Render G1 with respect to G0 such that the overall result is consistent and looks like as if both G1 and G0 were rendered together.

What is happening:

When I render the G1 graph using the answer given on this page: Cytoscape: apply layout only to newly added nodes
the new nodes overlap the nodes of G0. In other words, the layout function is not taking the previously rendered graph G0 into consideration.

What have I tried:

I looked around and came across this library: https://github.com/iVis-at-Bilkent/cytoscape.js-layout-utilities?tab=readme-ov-file which has been developed for the exact same purpose (incrementing layout adjustments). But when I tried this library (by referencing demo.html, I did not get the expected results. The nodes of G1 still overlap G0 nodes. Here is the snippets of my code:

  1. The api initialisation:
 api = cy.layoutUtilities({
                desiredAspectRatio: 1.0,
                polyominoGridSizeFactor: 1.0,
                utilityFunction: 1,
                componentSpacing: 80
            })
  1. Rendering the initial chunks (3 chunks):
        async function loadInitialChunks() {
            for (let i = 0; i < 3; i++) {
                // this function fetches an object containing two arrays
                // {nodes, edges} and stores it in a variable `preloadedchunks`
                await getChunk(chunkIndex++, chunkSize); 
            }
            renderChunks();
        }

        function renderChunks() {

            preloadedChunks.forEach(chunk => {
                chunk.nodes.forEach(node => {
                    cy.add({
                        group: 'nodes',
                        data: node.data,
                        position: node.position
                    });
                });
                cy.add(chunk.edges);
            });

           // This code has been referred from the demo.html file I mentioned above
           // More specifically, this code is present at line 299 in demo.html 
            var subgraphs = []
            cy.$().forEach(chunk => {
                var subgraph = {}
                subgraph.nodes = []
                subgraph.edges = []
                chunk.nodes().forEach(node => {
                    var boundingBox = node.boundingBox();
                    subgraph.nodes.push({
                        x: boundingBox.x1,
                        y: boundingBox.y1,
                        width: boundingBox.w,
                        height: boundingBox.h
                    })
                });

                chunk.edges().forEach(edge => {
                    subgraph.edges.push({
                        startX: edge.sourceEndpoint().x,
                        startY: edge.sourceEndpoint().y,
                        endX: edge.targetEndpoint().x,
                        endY: edge.targetEndpoint().y
                    })
                });
                subgraphs.push(subgraph);
            })

            var result = api.packComponents(subgraphs, true);
            cy.$().forEach((component, index) => {
                component.nodes().layout({
                    name: 'fcose',
                    animate: 'true',
                    fit: false,
                    transform: (node) => {
                        let position = {};
                        position.x = node.position('x') + result.shifts[index].dx;
                        position.y = node.position('y') + result.shifts[index].dy;
                        return position;
                    }
                }).run();
            });

            let currentZoom = cy.zoom();
            let currentPan = cy.pan();

            const layout = cy.layout({
                name: 'fcose',
                avoidOverlap: true,
                nodeDimensionsIncludeLabels: true
            });
            layout.run();

        }    

  1. Requesting additional chunks:
function renderAdditionalChunks(chunk, chunkIndex) {
            try {
                // This approach is given at line #398 in the demo.html file
                var newNodes = cy.collection();
                chunk.nodes.forEach(node => {
                    if (!loadedNodes.has(node.data.id)) {
                        node.data.chunkId = chunkIndex
                        var newEles = cy.add({
                            group: 'nodes',
                            data: node.data,
                        });
                        newNodes.merge(newEles.nodes());
                        loadedNodes.add(node.data.id);

                    }
                });

                chunk.edges.forEach(edge => {
                    edge.data.chunkId = chunkIndex
                    cy.add({
                        group: 'edges',
                        data: edge.data,

                    });
                });
                let elementF = cy.elements("node[chunkId=" + chunkIndex + "],edge[chunkId=" + chunkIndex + "]");
                console.log("Elements filtered out: ", elementF)

                elementF.layout({
                    name: 'fcose',
                    // fit: false,
                    animate: true,
                    avoidOverlap: true,
                    nodeDimensionsIncludeLabels: true
                }).run();

                api.placeNewNodes(newNodes);

                cy.zoom(currentZoom);
                cy.pan(currentPan);

            } catch (error) {
                console.log(chunk)
                console.error('Error:', error);
            }

        }

It would be really great if anyone can help me figure out what am I missing here or if there are any other better alternatives to do so. Thanks.

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