Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WPF Graph Zoom Behavior

Hi,

When calling the Zoom method on the WPF graph, all the parameters are "relative". i.e. when refreshing the plots and chart boundaries, the zoom rectangle is defined as relative to the new graph boundaries.

Those were our conclusions after implementing this feature. I've tried and couldn't find any documentation about this behavior.

I would like to know:

  • Where can I find any documentation describing the zoom behavior when refreshing the plots and chart boundaries?
  • Is it possible to define "absolute" zoom boundaries, i.e. zoom in absolute (and not relative) values per axis?
  • Was this behavior changed from the WinForms to the WPF graph?

Thanks in advance!

  Nimrod S.

0 Kudos
Message 1 of 2
(2,110 Views)

The use of “relative coordinates” in the WPF controls follows the use of “virtual coordinates” in the Windows Forms controls (see for example the documentation for the Windows Forms ZoomXY method).

 

Here is the documentation for the WPF Graph Zoom method. Unfortunately, it does not describe the value range, beyond the “relative” parameter names. There is better parameter documentation for the low-level method used to implement pan and zoom, but I agree it is not not very discoverable.

 

There is no existing method to perform an “absolute” zoom, but creating an extension method that takes absolute values is not difficult. For simplicity, I have made the assumption you use double axes (which are the default used by the graph, if none are provided):

public static class GraphExtensions {
    public static void ZoomAbsolute( this IInteractiveGraph graph, Point p1, Point p2, IPlot referencePlot = null ) {
        var plot = referencePlot ?? graph.GetDefaultPlot( );
        Point relative1 = DataToRelative( graph, plot, p1 );
        Point relative2 = DataToRelative( graph, plot, p2 );

        double relativeX, relativeY, relativeWidth, relativeHeight;
        GetRelativeFactors( relative1.X, relative2.X, out relativeX, out relativeWidth );
        GetRelativeFactors( relative1.Y, relative2.Y, out relativeY, out relativeHeight );
        graph.Zoom( relativeX, relativeY, relativeWidth, relativeHeight );
    }

    private static Point DataToRelative( IInteractiveGraph graph, IPlot plot, Point point ) {
        return graph.DataToRelative( plot, new[] { point.X, point.Y } );
    }

    private static void GetRelativeFactors( double relative1, double relative2, out double relativeStart, out double relativeFactor ) {
        double relativeEnd;
        if( relative1 <= relative2 ) {
            relativeStart = relative1;
            relativeEnd = relative2;
        }
        else {
            relativeStart = relative2;
            relativeEnd = relative1;
        }

        relativeFactor = relativeEnd - relativeStart;
    }
}

 

(Given this assumption, you could also set the Range of each axis directly, though it would change the behavior of the undo history.)

~ Paul H
0 Kudos
Message 2 of 2
(2,087 Views)