microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.34k stars 301 forks source link

Is there a method to fit the width of a graph to the viewer's Width #353

Open wvdvegt opened 12 months ago

wvdvegt commented 12 months ago

Is there a method to fit the width of a graph to the viewer's Width and leave the aspect ratio as is (so a Fit to Width option). I need it for readability purposes.

Now, by default, the graph seems to be made completely visible while maintaining the aspect ratio. Now I have to zoom in/out everytime i load/create a graph.

levnach commented 12 months ago

What viewer do you use?

wvdvegt commented 12 months ago

Using informs so I think it's the gdi one.

levnach commented 12 months ago

There is proprety GViewer.ZoomF that can set the scale. Also have a look at GViewer.ShowGroup(), and GViewer.ShowBBox(). The latter can zoom in on anything on the graph.

wvdvegt commented 11 months ago

ZoomF I already found, but what i want is to fit the with of the bounding box to be the width of the viewer (so only the width and derive the height from the graph width & aspect ratio).

Currently the code fits the whole graph to the viewer which in my case results in a narrow stripe containing the graph in the middle of the viewer.

This is what i get: image

And this is how i would like it (preferable with a vertical scrollbar): image

levnach commented 11 months ago

Have you looked at https://github.com/microsoft/automatic-graph-layout/blob/722cd8105a66605adf23dd2fa3fafbbeeb179854/GraphLayout/tools/GraphViewerGDI/GViewer.cs#L1675? I think this method will work for you. You need to call it with bb having the width and the top-left taken from the geometry graph bounding box. The height you need to calculate from the aspect ratio of the client rectangle. I do not remember why there is no scrollbar. Probably it can be enabled.