Cytoscape JS - Modifying Container Height After Initialization

↘锁芯ラ 提交于 2020-06-13 05:58:51

问题


I initialize Cytoscape with something that looks like the following:

var cy = cytoscape({
    container: $('#my-element'),
    height: 500px
});

I would like to change the height of the container element to something other than the original 500px value when an user commits an action.

How would I do this with Cytoscape? There is a height() method in the main Cytoscape object, but this only functions as a getter.


回答1:


There is a documented method cy.resize() that you can call to redraw the graph to fit within the context of the current container's height / width. You won't however get the desired results just by calling this method. You'll also have to call the cy.fit() function afterwards to get the new graph view you want.

So your function to resize the container should look something like this:

function resizeContainer(newContainerHeight){
    $('#my-element').css('height', newContainerHeight);
    cy.resize();
    cy.fit();
}


来源:https://stackoverflow.com/questions/43194851/cytoscape-js-modifying-container-height-after-initialization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!