question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modifying Container Height After Initialization With Resize()

See original GitHub issue

I have a HTML DOM that looks like:

<div id="my-element"></div>

with the corresponding code to initialize Cytoscape:

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.

After going through the docs, it seems like I should be able to do this with cy.resize().

I have the following bound to a button click action in my code:

$('#my-element').css('height', 'calc(100% - 410px)');
cy.resize();

But the above doesn’t redraw my Cytoscape container with the new height.

What am I missing here?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ianhicommented, Jun 17, 2020

I also found this slightly confusing. In particular I took this line from the documentation for resize(ref)

to have the graph resize and redraw itself

to mean that I should expect the pan and zoom to be modified to fit the graph inside the new dimensions when I called this function. This probably stems from my being newish to javascript and not fully understanding the distinction of viewport and pan and zoom you helpfully described.

@maxkfranz would you be open to adding something like the following to the documentation: This function will only change the viewport extent, it will not modify the pan and zoom to fit the graph inside the new dimensions. To accomplish that you will need to call cy.fit() after this function.

1reaction
pihishcommented, Apr 5, 2017

It had nothing to do with styling. cy.resize() needs to be followed by a call to cy.fit()

$('#my-element').css('height', 'calc(100% - 410px)');
cy.resize();
cy.fit();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cytoscape JS - Modifying Container Height After Initialization
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...
Read more >
vector : : resize() in C++ STL - GeeksforGeeks
The function alters the container's content in actual by inserting or deleting the elements from it.
Read more >
Chart Container - Concepts - Handbook - Apache ECharts
In general, you need to define a <div> node and use the CSS to change the width and height. While initializing, import the...
Read more >
std::vector::resize - CPlusPlus.com
Change size. Resizes the container so that it contains n elements. If n is smaller than the current container size, the content is...
Read more >
std::vector::resize - cppreference.com
[edit] Parameters ; count, -, new size of the container ; value, -, the value to initialize the new elements with ; Type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found