SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

1
0

Hello,

I have ClipModeX=”ClipAtExtents” on my ZoomPanModifier. I need the same behavior on the y-axis, but there is no “ClipModeY”.

How do I prevent y-axis data from panning off the chart?

Thanks,
Neville

  • You must to post comments
1
0

Hi Neville,

Thanks for your inquiry. We’ve been asked several times for this behavior and we’ve got a solution for you. Fortunately, it can be implemented quite easily. Everything you need is to extend ZoomPanModifier and override the Pan method:

 public class ZoomPanModifierEx : ZoomPanModifier 
{    
    public static readonly DependencyProperty ClipModeYProperty = DependencyProperty.Register("ClipModeY", typeof(ClipMode), typeof(ZoomPanModifierBase), new PropertyMetadata(ClipMode.StretchAtExtents));

    public ClipMode ClipModeY

    {
        get { return (ClipMode)GetValue(ClipModeXProperty); }
        set { SetValue(ClipModeXProperty, value); }
    }

   public ZoomPanModifierEx () : base()  
   {
        this.ZoomExtentsY = false;
   }

    public override void Pan(Point currentPoint, Point lastPoint, Point startPoint)
    {
        base.Pan(currentPoint, lastPoint, startPoint);

        var xDelta = currentPoint.X - lastPoint.X;

        var yDelta = lastPoint.Y - currentPoint.Y;

        // Computation of a new Y-Range
        foreach (var yAxis in YAxes)
        {
            yAxis.Scroll(yAxis.IsHorizontalAxis ? -xDelta : yDelta, ClipModeY);
        }   
    }
}

Please try this code and let us know if it does the trick,

Best regards,
Yuriy

  • Adrian Harwood
    Work around no-longer works on v3 for Xamarin.iOS as it no-longer exposes Pan or OnPanGesture for override. Oh, and you didn’t expose ClipModeY either so now we are truly stuck. Good work.
  • You must to post comments
0
0

Hello Yuriy,

Thanks for the solution. I tried it out and it seemed to work, but it autoscaled my chart as soon as I started panning. Is there a way to prevent it from autoscaling?

This is how I’m calling it: (Note: when ClipModeX and ClipModeY are set to “None”, it doesn’t autoscale the chart)

<localHelpers:ZoomPanModifierEx IsEnabled="True" ExecuteOn="MouseLeftButton" ReceiveHandledEvents="True" ClipModeX="ClipAtExtents" ClipModeY="ClipAtExtents"/>

I have a video showing the behavior, but it’s 1.73Mb and can’t be uploaded. Can you enlarge the max file size to something that would allow videos to be uploaded (e.g., 5Mb)? 1Mb seems quite limiting.

Thanks,
Neville

  • Andrew Burnett-Thompson
    I know I’m late to the party, but I’m investigating this for another support request and I discovered you need to set ZoomExtentsY = false for the ZoomPanModifier to work correctly in this case.
  • You must to post comments
0
1

If anyone comes here looking for a Mobile SDK v2.5.0.946 solution to this issue then based on Yuriy’s answer above I implemented the following. Although this is Xamarin, it will probably be pretty similar for Java/Swift. It disables the fling gesture on Android which wasn’t a big deal for me but might be for others so you will have to re-implement it if you want it.

Xamarin.Android:

public class ZoomPanModifierExt : ZoomPanModifier
{
    public ClipMode ClipModeY { get; set; }

    public ZoomPanModifierExt() : base()
    {
        ZoomExtentsY = false;
    }

    // Suppress the fling actions although you could implement it if you want it
    public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
    {
        return false;
    }

    // Override the scroll action
    public override bool OnScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
    {
        // Scroll X
        foreach (var xAxis in XAxes)
        {
            xAxis.Scroll(!xAxis.IsHorizontalAxis ? distanceY : -distanceX, ClipModeX);
        }

        // Scroll Y
        foreach (var yAxis in YAxes)
        {
            yAxis.Scroll(yAxis.IsHorizontalAxis ? -distanceX : distanceY, ClipModeY);
        }
        return true;
    }
}

Xamarin.iOS:

public class ZoomPanModifierExt : SCIZoomPanModifier
{
    public SCIClipMode ClipModeY { get; set; }
    public CoreGraphics.CGPoint InitTouch { get; private set; }

    public ZoomPanModifierExt() : base()
    {
        ZoomExtentsY = false;
    }

    public override bool OnPanGesture(UIPanGestureRecognizer gesture, UIView view)
    {
        if (gesture.State == UIGestureRecognizerState.Began)
        {
            InitTouch = gesture.TranslationInView(view);
        }
        else if (gesture.State != UIGestureRecognizerState.Cancelled)
        {
            var distance = gesture.TranslationInView(view);
            var distanceX = -distance.X;
            var distanceY = -distance.Y;

            // Scroll X
            foreach (var xAxis in XAxes)
            {
                xAxis.ScrollByPixels(!xAxis.IsHorizontalAxis ? distanceY : -distanceX, ClipModeX);
            }

            // Scroll Y
            foreach (var yAxis in YAxes)
            {
                yAxis.ScrollByPixels(yAxis.IsHorizontalAxis ? -distanceX : distanceY, ClipModeY);
            }
        }
        return true;
    }
}
  • Adrian Harwood
    In v3 of the SDK they have removed OnPanGesture from iOS and still not exposed ClipModeY so we are stuck now.
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.