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
- forl forl asked 11 months ago
- last edited 11 months ago
- You must login to post comments
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
- Joeri R answered 11 months ago
- You must login to post comments
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?
}
}
- forl forl answered 11 months ago
- last edited 11 months ago
-
Comments are enabled after 50 rep. This is to prevent spam! https://www.scichart.com/changes-to-the-scichart-forum-permissions/
- You must login to post comments
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.
- forl forl answered 11 months ago
-
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!
-
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
-
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 login to post comments
Please login first to submit.