ZoomToFit not always working correctly

Hello,

in special situations, the built-in function “ZoomToFit” is not working correctly. After the new scale factor is applied to the diagram, the scrollbars are still visible. The strange thing is, that the width of the scrollbars (17px) is larger than the possible scroll extend (around 10-14px).

In addition, the issue only occurs, when we start with a situation, where the scrollbars are visible before applying “ZoomToFit”. If we start with a small zoom factor (scrollbars not visible) and then apply “ZoomToFit”, the scrollbars stay hidden.

But the computed scale factor is exactly the same in both situations.

It seems as if the computed scrollbar visibility isn’t be updated.

Any idea?

Thanks,
Robert

Is this in WPF or in Silverlight?

In GoWpfDemo I tried several samples where there were scrollbars. The Alt-Z command properly zoomed out, resulting in no scrollbars. (Repeating Alt-Z toggles between the original Position/Scale and the zoomed-to-fit Position/Scale. Note also that Diagram.Stretch might prevent zoom-to-fit.)

Did you invoke the ZoomToFit command, Commands.ZoomToFit or CommandHandler.ZoomToFitCommand, which calls CommandHandler.ZoomToFit()?

It’s in WPF.

I applied ZoomToFit with _diagram.Panel.ZoomToFit().

And I tried it in the ways you suggested (ZoomToFit command, Commands.ZoomToFit or CommandHandler.ZoomToFitCommand), but I couldn’t find any change in behavior.

The problem only occurs when both scrollbars are visible and the zoom-factor is larger than fit-zoom-factor at start.

The strange thing is, if we start in a situation, where no scollbar is visible (lower zoom) and then apply ZoomToFit, the resulting ViewportScale is exactly the same as in the situation above, but the scrollbars stay hidden. Thus, the calculated ViewportScale is sufficient in principle.

1. Zoom: 100%
2. ScrollBars visible
3. ZoomToFit => ViewportScale: 1 => 0.7666963490650045
4. ScrollBars visible

1. Zoom: 50%
2. ScrollBars not visible
3. ZoomToFit => ViewportScale: 0.5 => 0.7666963490650045
4. ScrollBars not visible

OK, I’m able to reproduce the problem. Unfortunately the solution is not obvious, so it will take a while for us to figure it out.

i m facing same problem. ZoomToFit is not working with your given suggestions.

I’ll investigate what has happened since then.

Have you tried the new DLL that I emailed you about?

Is this working for you now?

Was there any specific change for this issue?

We’re doing a default ForceDirectedLayout, then a ZoomToFit. Often shapes are placed off the top/bottom of the screen and no vertical scrollbar is shown. When the layout is saved and the control closed and reloaded using InitialStretch=“Uniform” then the diagram is displayed as i would have expected after the diagram.Panel.ZoomToFit.

Any ideas?

Yes, there were changes made in version 2.2.3.

However, due to the asynchronous nature of WPF, it might be that you are calling ZoomToFit too early. It depends on what you’re doing, of course. That’s why setting InitialStretch=“Uniform” should work better.