Pre loader

Custom ZoomExtentsModifier to enable AutoRange on Realtime Chart

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

3
0

I have a realtime linear chart with multiple x/y axes. When I am zooming the surface, I am changing the X/Y AutoRange mode from AutoRange.Always to AutoRange.Never, which allows me to have Modifiers zooming and panning on a realtime AutoRange chart.

After, I want to re-enable AutoRange when ZoomExtents (double click) occurs.

See below:

    public class ZoomExtentsXAxesModifier : ZoomExtentsModifier
    {
        private Point _startPoint;
        private bool _isMouseDoubleClick;

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

            if(e.Modifier == MouseModifier.Ctrl) return;

            if (e.MouseButtons == MouseButtons.Left)
                _startPoint = e.MousePoint;

            _isMouseDoubleClick = false;
        }

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

            if (e.Modifier == MouseModifier.Ctrl) return;

            if (e.MouseButtons != MouseButtons.Left || _startPoint == e.MousePoint || _isMouseDoubleClick) return;

            using (ParentSurface.SuspendUpdates())
            {
                foreach (var axise in XAxes.Where(axise => axise.AutoRange != AutoRange.Never))
                {
                    axise.AutoRange = AutoRange.Never;
                    axise.Zoom(_startPoint.X, e.MousePoint.X);
                }

                foreach (var axise in YAxes.Where(axise => axise.AutoRange != AutoRange.Never))
                {
                    axise.AutoRange = AutoRange.Never;
                    axise.Zoom(_startPoint.Y, e.MousePoint.Y);
                }
            }
        }

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

            if (e.Modifier == MouseModifier.Ctrl) return;

            foreach (var axise in XAxes)
                axise.AutoRange = AutoRange.Always;

            foreach (var axise in YAxes)
                axise.AutoRange = AutoRange.Always;

            _isMouseDoubleClick = true;
        }
    }

For the one chart it is working ok, but when I have more then 2 charts, it is zooming incorect? What can I solve this? I need to recieve one event, when user is zooming, panning or resizing chart. Is it possible?

Thanks,
Arthur

  • You must to post comments
4
0

Hi,

Please, try translating the mouse point relative to ModifierSurface before using it. Refer to the following code:

_startPoint = GetPointRelativeTo(e.MousePoint, ModifierSurface);

Thing are done in this way in modifiers code. Also, maybe you need to play around with the ReceiveHandledEvents property (if your modifiers are connected together via MouseEventGroup).

Regarding the second question, we don’t provide such an event, but there is the SciChartSurface.Rendered event, which will be fired after each redraw (initiated either by pan, or zoom, or resize operation). Alternatively, you can subscribe to the AxisBase.VisibleRangeChanged event or extend modifiers classes and introduce your own events for them. So in this case you need to subscribe to the SizeChanged event.

Hope this helps,

Best regards,
Yuriy

  • You must to post comments
2
0

You can also check if the mouse is on a specific Axis, or on the main chart area by using this technique: ChartModifierBase Get Notification of MouseDown on Axis or Chart

We also explain how to translate points relative to the central chart area (the Modifier Surface) here: ChartModifierBase OnModifierMouseDown reports coordinates incorrectly.

Hope this helps!
Andrew

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.