Pre loader

Custom Undo/Redo operation

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

1
0

I’m using the ZoomHistoryManager in my application which works great!

But how can I add my own entry to the undo/redo stack?

On my viewmodel I have

 /// <summary>
/// XAxisRange
/// </summary>
public DoubleRange? XAxisRange
{
    get => _xAxisRange;
    set => SetProperty(ref _xAxisRange, value);
}

private DoubleRange? _xAxisRange = null;

/// <summary>
/// YAxisRange
/// </summary>
public DoubleRange? YAxisRange
{
    get => _yAxisRange;
    set => SetProperty(ref _yAxisRange, value);
}

private DoubleRange? _yAxisRange = null;

and I want to implement something like :

 public void CustomRangeUpdate()
{
    if (RenderableSeries.Count > 0)
    {

        XAxisRange = new DoubleRange(x1, x2);
        YAxisRange = new DoubleRange(y1, y2);

        ZoomHistoryManager.SaveLatestRange(new AxisKey("DefaultAxisId", true), XAxisRange);
        ZoomHistoryManager.SaveLatestRange(new AxisKey("YAxis", false), YAxisRange);
        ZoomHistoryManager.PushAll();
    }
}

But it looks like I am using it incorrectly as it doesn’t add any entries. I’ve also tried Push() with no luck

Version
7
  • You must to post comments
1
0

Hi there,

Thanks for your inquiry.

Unfortunately, ZoomHistoryManager API doesn’t allow adding ranges manually. It had been designed to handle only ranges pushed during SciChartSurface lifetime. So if you want to fill the zooming history before a ZoomHistoryManager is attached to a SciChartSurface, the ranges won’t be added.

Could you please describe your use-case in more details? Maybe we will be able to suggest an alternative solution.

Best Regards,
Joeri

  • You must to post comments
1
0

For some reason, I am still not allowed to add comments to your reply … so will add an answer

The ZoomHistoryManager would already be attached.

The use case is that we have buttons in our UI that set specific X and Y ranges on the axes when the button is pressed. We’d like to be able to undo/redo these ranges just like we can with Panning/Zooming.

e.g

  • User pans
  • Users zooms
  • User clicks our custom “SetRangeCommand” button which sets a new X and Y Range
  • User zooms
  • User zooms

we’d like the 3rd user operation to be part of the undo stack.

    <s:SciChartSurface ZoomHistoryManager="{Binding ZoomHistoryManager }">
   <s:SciChartSurface.XAxes>
      <s:NumericAxis  VisibleRange="{Binding XVisibleRange }" />
   </s:SciChartSurface.XAxes>
</s:SciChartSurface>




    public class ViewModel
{
     public ICommand SetRangeCommand => SetRange();

     public ZoomHistoryManager ZoomHistoryManager { get; } = new();

     public DoubleRange XVisibleRange { get; set; }

     public void SetRange()
     {
         // we would like this to be an undo/redo step, just like how the chart modifiers work
         XVisibleRange = new XVisibleRange();   

         // ZoomHistoryManager.... Add Step?    
     }

}
  • You must to post comments
1
0

Ok, I have this working now, turns out you can’t use the Axes Ids. You have to pass in the actual instance of the axis …

 ZoomHistoryManager.SaveLatestRange(new AxisKey(ZoomHistoryManager.ParentSurface.YAxes[0]), YAxisRange);
        ZoomHistoryManager.PushAll();

It would be great if there were clear examples for this stuff! .. I seem to waste a lot of time figuring it out by trial and error.

  • Andrew Burnett-Thompson
    Hi fori! As yuriy said we didn’t design ZoomHistoryManager for this hence why no examples of this use-case. I’m glad you figured it out though and possibly useful info to other users in case they want to do the same. Thanks!
  • forl forl
    Hi Andrew. I’m not sure what you mean by ZoomHistoryManager not being designed for this? this seems like a very common case. Something that you would need to do for example if you wanted to create your own ChartModifier that supported Undo/Redo. I feel like there should be clear examples for this, given that you advertise users can make their own ChartModifiers
  • Andrew Burnett-Thompson
    You are literally the first person in 10 years who asked for modifying the undo/redo stack – not so common! But it seems you have figured this out and it’s possible? The question here will serve as a landmark for anyone else wanting to do the same. If you have any further questions, please feel free to ask. Best regards, Andrew
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.