iVis-at-Bilkent / cytoscape.js-fcose

fCoSE: a fast Compound Spring Embedder
MIT License
137 stars 25 forks source link

Struggling to set aspect ratio #16

Closed geotheory closed 4 years ago

geotheory commented 4 years ago

This is a really great layout, but I'm struggling to set the aspect ratio for bigger/more densly connected graphs. This jsfiddle ilustrates. Am I missing something in the parameters? Adjusting desiredAspectRatio by swapping width and height has no effect.

hasanbalci commented 4 years ago

@geotheory It seems that adding utilityFunction: 2 as an option to layout-utilities extension solves your issue. I think this option offers an alternative between giving priority to maximum fullness (by setting it to 1) and showing more respect to aspect ratio (by setting it to 2). You can find more detailed information about the layout-utilities extension here.

geotheory commented 4 years ago

Thanks @hasanbalci but I can't seem to get this to work - I've tried putting that line in layoutUtilities({ ... }) as well as this.layout({ ... }) to no effect. Are you possibly able to demo with the jsfiddle above?

hasanbalci commented 4 years ago

@geotheory In this jsfiddle, I set options of layout-utilities as desiredAspectRatio: this.width()/this.height() and utilityFunction: 2. Since cy.width()/cy.height is equal to 100 / 50 = 2, in the resulting layout I can obtain an aspect ratio close to 2 as shown below:

image

In this one, however, I set options of layout-utilities as desiredAspectRatio: this.height()/this.width() and utilityFunction: 2. Since cy.height()/cy.width is equal to 50 / 100 = 0.5, in the resulting layout I can obtain an aspect ratio close to 0.5 as shown below:

image

If I set desiredAspectRatio: 1 and utilityFunction: 2 as in this example, then I can obtain an aspect ratio close to 1:

image

I hope this helps for your issue.

geotheory commented 4 years ago

Thanks for your assistance Hasan. To be honest I think the solution is only limited to smaller graphs. Whenever I increase the nodes/edges it still ends up as a cube! Perhaps worth considering if further development could fix so calculated node positions could be rescaled to hard-code aspect ratio. But I appreciate if there are other priorities.

ugurdogrusoz commented 4 years ago

@geotheory as pointed out earlier, this layout extension makes use of this extension to pack components of disconnected graphs. Neither that layout utility extension nor this layout extension will perform a layout on a connected subgraph to result in a layout with desired aspect ratio but rather will pack already laid out components of a disconnected graph in a way to be close to the desired aspect ratio. So, if you're aiming for a desired aspect ratio of 0.5, and your graph has 2 components, 1 very big and 1 very small component with bounding boxes of aspect ratio close to 1, the 2 components will be packed as one on top of the other, and the final layout will not be very close to your desired aspect ratio as this is the best that can be done with such 2 components.

geotheory commented 4 years ago

Thanks for this, and again for you help. I've implemented fcose so maybe been to do a bit more back end or cy.filter work to de-densify (©) the graph.

ugurdogrusoz commented 4 years ago

@geotheory if you think your graphs are very dense and would like to manage their complexity through some complexity management operations, you might want to consider using this extension and this one.