Pre loader

Custom Zoom Out Modifier

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered
0
0

I’ve verified it steps thru the code as I would expect; however, it only ever zooms in further. The intent of this modifier is to only zoom out when the mouse is dragged up and left. I.e.

Mouse down
Drag up/left
Mouse up

    class ZoomOutModifier : ZoomExtentsModifier
{
    double _x;
    double _y;
    MouseButtons _button = MouseButtons.None;

    public override void OnModifierDoubleClick(ModifierMouseArgs e)
    {
        // do not zoom to extents on a double click
        e.Handled = true;
    }

    public override void OnModifierMouseDown(ModifierMouseArgs e)
    {
        base.OnModifierMouseDown(e);

        // where was the mouse button on the chart surface?            
        _x = e.MousePoint.X;
        _y = e.MousePoint.Y;

        // which button was clicked?  we're only going to zoom 
        // out on a left button click.
        _button = e.MouseButtons;
    }

    public override void OnModifierMouseUp(ModifierMouseArgs e)
    {            
        // are we left and up from where the mouse was clicked?
        if (MouseButtons.Left == _button &&
            e.MousePoint.X < _x &&
            e.MousePoint.Y < _y)
        {
            using (var updater = ParentSurface.SuspendUpdates())
            {
                ParentSurface.ZoomExtents();
                ParentSurface.ResumeUpdates(updater);
            }

            e.Handled = true;
        }
        else
            base.OnModifierMouseUp(e);
    }
}
Version
6.1.0.13075
  • You must to post comments
Best Answer
0
0

Andrew. I was able to resolve this using

ParentSurface.AnimateZoomExtents(new System.TimeSpan(0, 0, 0, 0, 250));

in my derived ZoomExtentsModifier class. When I used

ParentSurface.ZoomExtents();

it didn’t zoom out, in fact it continued to zoom in. You think this is because I had setup my chart surface to animate in the XAML?

<s:RubberBandXyZoomModifier IsAnimated="True" IsXAxisOnly="False" />

This may have nothing to do with it but would be curious if it did.

  • You must to post comments
0
0

Hi Chris

The only thing I can see is wrong is this part

        using (var updater = ParentSurface.SuspendUpdates())
        {
            ParentSurface.ZoomExtents();
            ParentSurface.ResumeUpdates(updater);
        }

Firstly, when calling a single call to ZoomExtents, you don’t need to suspend updates. secondly, calling ParentSurface.REsumeUpdates(updater) resumes twice, as the dispose block of updater does exactly this.

The pattern should be

        using (var updater = ParentSurface.SuspendUpdates())
        {
            // TODO
            // lots of updates here where you want to suspend 

            // ParentSurface.ResumeUpdates(updater); // DONT CALL THIS 
        } 

Try just calling ParentSurface.ZoomExtents() or AnimateZoomExtents and see what happens

Best regards,
Andrew

  • Chris Kirkman
    Thanks Andrew. That’s actually where I started. Please see comments below.
  • You must to post comments
0
0

Thanks Andrew. That’s actually what I did originally and it would just zoom in even more. I get the same behavior with e.Handled true or false.

            // are we left and up from where the mouse was clicked?
        if (MouseButtons.Left == _button &&
            e.MousePoint.X < _x &&
            e.MousePoint.Y < _y)
        {
            ParentSurface.ZoomExtents();

            //e.Handled = true;
        }
        else
            base.OnModifierMouseUp(e);
  • You must to post comments
0
0

Please find attached class that I’m using. Unfortunately it’s not working. Maybe you can get it to work.

class ZoomOutModifier : ZoomExtentsModifier
{
    double _x;
    double _y;
    MouseButtons _button = MouseButtons.None;

    public override void OnModifierDoubleClick(ModifierMouseArgs e)
    {
        // do not zoom to extents on a double click
        e.Handled = true;
    }

    public override void OnModifierMouseDown(ModifierMouseArgs e)
    {
        base.OnModifierMouseDown(e);

        // where was the mouse button on the chart surface?            
        _x = e.MousePoint.X;
        _y = e.MousePoint.Y;

        // which button was clicked?  we're only going to zoom 
        // out on a left button click.
        _button = e.MouseButtons;
    }

    public override void OnModifierMouseUp(ModifierMouseArgs e)
    {            
        // are we left and up from where the mouse was clicked?
        if (MouseButtons.Left == _button &&
            e.MousePoint.X < _x &&
            e.MousePoint.Y < _y)
        {
            ParentSurface.ZoomExtents();

            //e.Handled = true;
        }
        else
            base.OnModifierMouseUp(e);
    }
}
  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies