Pre loader

ZoomExtentsModifier doesn't honour VisibleRange

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

0
0

I’m using a number of modifiers to allow the user to pan and zoom, including a ZoomExtentsModifier so the user can double-click to “reset” the chart back to its initial layout. However it seems to ignore the VisibleRanges I’ve got on the axes. How can I get it to honour these?

Here is an example of one of my axes, just in case one of its attributes is preventing the modifier from working properly:-

<SciChart:NumericAxis AxisAlignment="Left" AutoRange="False" DrawMajorTicks="False" DrawMinorTicks="False" VisibleRange="{Binding YAxisRange, Mode=TwoWay}" DrawMinorGridLines="False" DrawLabels="True" AxisTitle="Foo"/>

(I seem to remember being told a while ago that the VisibleRange binding must be TwoWay otherwise it won’t work. Is that correct?)

Thanks in advance
Andy

  • You must to post comments
1
0

Hi again,

I thought a bit and found better solution for your case. We don’t need to inherit from ZoomExtentsModifier (because we need to override its behavior completely), so lets create own modifier:

    public class CustomZoomExtentsModifier : ChartModifierBase
    {
        IRange InitialXRange
        { get; set; }

        TimeSpan Duration
        { get; set; }

        public CustomZoomExtentsModifier()
        {
            ExecuteOn = ExecuteOn.MouseDoubleClick;
            Duration = TimeSpan.FromMilliseconds(500);

            // Can be set in XAML
            InitialXRange = new DoubleRange(-10, 10);
        }

        public override void OnModifierDoubleClick(ModifierMouseArgs e)
        {
            XAxis.AnimateVisibleRangeTo(InitialXRange, Duration);

            // Animate Y VisibleRange to extents on given X range (includes GrowBy)
            ParentSurface.ZoomExtentsY(InitialXRange, Duration);

            // or
            // YAxis.AnimateVisibleRangeTo(InitialYRange, Duration);
        }
    }

Please, let us know if this helps!

Best regards,
Yuriy

  • andyste1
    That helped me to find a solution, thanks. I now take a copy of the VisibleRanges when the VM first creates the chart data, then in the event handler of my custom zoom extents modifier (the original one, not your second suggestion) I use AnimateVisibleRangeTo() to action the change:- XAxis.AnimateVisibleRangeTo(_viewModel.OriginalXAxisRange, new TimeSpan(0, 0, 1)); YAxis.AnimateVisibleRangeTo(_viewModel.OriginalYAxisRange, new TimeSpan(0, 0, 1)); Am I right in saying that VisibleRange must use TwoWay binding? What's the reason for this? If it supported OneWay then the solution would have been simpler - I wouldn't need to take a copy of the original values, and could probably have just updated the binding using .UpdateTarget() as in my earlier post.
  • Yuriy Zadereckiy
    Hi, I'm glad you've solved it! This requirement to use TwoWay binding is mandatory if you are going to interact with a chart(use modifiers, for example). Basically, most of visible range changes are performed as axis.VisibleRange=[newVisibleRange] internally, and this overrides every binding except TwoWay. If you are aware of SetCurrentValue(...) method, we cannot use it, because it doesn't exist in Silverlight and there seems not to be any workaround, but we want to keep the source code working in same way for both WPF and SL. Best regards, Yuriy
  • You must to post comments
0
0

I wanted to add an answer after playing with. First I wanted to be able to bind initial values in xaml and Yuri’s response doesn’t use dependency properties. I also wanted to be able to animate to both the y and x initial ranges. So in view model I generate what the initial values should be and then bind to them. Please do not use same binding of the x and y axis with mode set to two way as it will change your values to the current range. Here is class

public class CustomZoomExtentsModifierSingleAxis : ChartModifierBase
{
    public IRange InitialXRange
    {
        get => (IRange) GetValue(InitialXRangeProperty);
        set => SetValue(InitialXRangeProperty, value);
    }

    public static readonly DependencyProperty InitialXRangeProperty =
        DependencyProperty.Register(nameof(InitialXRange), typeof(IRange), typeof(CustomZoomExtentsModifierSingleAxis), new PropertyMetadata(new DateRange()));

    public IRange InitialYRange
    {
        get => (IRange) GetValue(InitialYRangeProperty);
        set => SetValue(InitialYRangeProperty, value);
    }

    public static readonly DependencyProperty InitialYRangeProperty =
        DependencyProperty.Register("InitialYRange", typeof(IRange), typeof(CustomZoomExtentsModifierSingleAxis), new PropertyMetadata(new DoubleRange()));

    public TimeSpan Duration
    {
        get => (TimeSpan) GetValue(DurationProperty);
        set => SetValue(DurationProperty, value);
    }

    public static readonly DependencyProperty DurationProperty =
        DependencyProperty.Register("Duration", typeof(TimeSpan), typeof(CustomZoomExtentsModifierSingleAxis), new PropertyMetadata(TimeSpan.FromMilliseconds(0)));


    public CustomZoomExtentsModifierSingleAxis()
    {
        ExecuteOn = ExecuteOn.MouseDoubleClick;
    }

    public override void OnModifierDoubleClick(ModifierMouseArgs e)
    {
        if (InitialXRange == null)
            ParentSurface.ZoomExtentsX();
        if (InitialXRange != null)
            XAxis?.AnimateVisibleRangeTo(InitialXRange, Duration);
        if (InitialYRange == null)
            ParentSurface.ZoomExtentsY();
        if (InitialYRange != null)
            YAxis?.AnimateVisibleRangeTo(InitialYRange, Duration);
    }
}

Here is the xaml

<sciChartHelpers:CustomZoomExtentsModifierSingleAxis InitialXRange="{Binding Path=OriginalXRange, 
                                                                                             NotifyOnSourceUpdated=True}"
                                                                                             InitialYRange="{Binding Path=OriginalYRange, NotifyOnSourceUpdated=True}"
                                                                                             Duration="00:00:01"/>
  • You must to post comments
0
0

Hi there,

As I understand, you want to perform zoom extents to initial ranges. ZoomExtentsModifier performs it to extents of data instead. What I can suggest you is to rise an event after zoom extents performed and set VisibleRanges to desired ranges in a handler. Please, take a look at Zoom including annotations thread, there is the example how to achieve it. in this case you should bind ChartModifier to ViewModel, create modifiers and handle the event there.

Please, feel free to ask if you need further assistance – we are glad to help!

Best regards,
Yuriy

  • andyste1
    Hi Yuriy, thanks for the reply. I've created a custom ZoomExtentsModifier as per your link, but I'm not sure what code to put in the "OnUserZoomExtents" event handler to apply the required VisibleRanges. I've tried refreshing the bindings like this:- BindingOperations.GetBindingExpression(XAxis, NumericAxis.VisibleRangeProperty).UpdateTarget(); BindingOperations.GetBindingExpression(YAxis, NumericAxis.VisibleRangeProperty).UpdateTarget(); The event handler is getting called after the chart has zoomed out to the extents of data, but the above code has no effect, i.e. it isn't readjusting the chart extents based on the VisibleRanges. What am I doing wrong?
  • You must to post comments
0
0

Is there any update to handle it in an easy way?
Tried to make a custom ViewportManager, but the example under following link didn’t work https://www.scichart.com/questions/question/zoom-including-annotations/#post-3504.
I just wanna zoom back to the VisibleRange i have set in the YAxis.

  • Markus Rüfenacht
    Okay I solved it. I saw that I have to assign GrowBy to the YAxis. Now it works all fine.
  • 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