Zoom History
Ok, so as I had not had a reply,I have managed to slog this out and I have created a customRubberBandXyZoomModifier.
In this I keep a copy of all the VisibleRanges on the mouse down and on the mouse up ( if it was dragging) I copy these ranges into a list of ranges in my ViewModel (parent) see below.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Abt.Controls.SciChart; using AVR_HMI.ViewModels; namespace AVR_HMI.Charting { public class customRubberBandXyZoomModifier : RubberBandXyZoomModifier { AnalogueChartViewModel _parent; IRange _tempOldXRange; List<IRange> _tempOldYRange = new List<IRange>(); public customRubberBandXyZoomModifier(AnalogueChartViewModel parent) { _parent = parent; } public override void OnModifierMouseDown(ModifierMouseArgs e) { _tempOldXRange = XAxis.VisibleRange; _tempOldYRange.Clear(); foreach (NumericAxis na in YAxes) { _tempOldYRange.Add(na.VisibleRange); } base.OnModifierMouseDown(e); } public override void OnModifierMouseUp(ModifierMouseArgs e) { if (IsDragging) { if (_tempOldXRange != null) { _parent.OldXRange = _tempOldXRange; _parent.XRangeHistory.Add(_tempOldXRange); _tempOldXRange = null; } if (_tempOldYRange.Count != 0) { int n = 0; foreach (IRange ra in _tempOldYRange) { if (_parent.YRangeHistories[n] != null) { _parent.YRangeHistories[n].RangeHistory.Add(_tempOldYRange[n]); } else { break; } n++; } } _parent.ZoomBack.RaiseCanExecuteChanged(); _parent.AutoRangeEnable = false; } base.OnModifierMouseUp(e); } } }
Then in the view model, I have an unzoom button which takes the last set of Ranges off the list and restores these ranges as below
List<IRange> _xRangeHistory = new List<IRange>(); public List<IRange> XRangeHistory { get { return _xRangeHistory; } set { _xRangeHistory = value; } } List<YRangeHistory> _yRangeHistories = new List<YRangeHistory>(); public List<YRangeHistory> YRangeHistories { get { return _yRangeHistories; } set { _yRangeHistories = value; } } DelegateCommand _zoomBack; public DelegateCommand ZoomBack { get { if (_zoomBack == null) { _zoomBack = new DelegateCommand( this.OnZoomBackCommandExecute, this.OnZoomBackChangedCommandCanExecute); } return _zoomBack; } } private bool OnZoomBackChangedCommandCanExecute(object obj) { if (YRangeHistories.Count == 0 || YRangeHistories[0].RangeHistory.Count == 0) { return false; } return true; } private void OnZoomBackCommandExecute(object obj) { if (XRangeHistory.Count != 0) { XAxis.VisibleRange = XRangeHistory[XRangeHistory.Count-1]; XRangeHistory.Remove(XAxis.VisibleRange); } if (YRangeHistories.Count != 0) { int n=0; foreach (NumericAxis na in YAxes) { int offset = YRangeHistories[n].RangeHistory.Count; if(offset > 0) { na.VisibleRange = YRangeHistories[n].RangeHistory[offset - 1]; YRangeHistories[n].RangeHistory.Remove(na.VisibleRange); } n++; } } if (YRangeHistories.Count == 0 || YRangeHistories[0].RangeHistory.Count == 0) { AutoRangeEnable = true; } ZoomBack.RaiseCanExecuteChanged(); VPManager.InvalidateParentSurface(RangeMode.None); }
On adding a new YAxis, I add a new YRangeHistory
YAxes.Add(numericAxis); YRangeHistories.Add(new YRangeHistory());
YRangeHistory Class
using System.Collections.Generic; using System.Linq; using System.Text; using Abt.Controls.SciChart; namespace AVR_HMI.Charting { public class YRangeHistory { List<IRange> _RangeHistory; public List<IRange> RangeHistory { get { return _RangeHistory; } set { _RangeHistory = value; } } public YRangeHistory() { _RangeHistory = new List<IRange>(); } } }
Hope this helps others, and if there is a better/easier way of doing this, please get back to me, I know I am on the demo version of SciChart at the moment, but we are intending to buy it and I worry about the lack of good documentation/support. I don't want to start looking elsewhere.
- wilx asked 11 years ago
- You must login to post comments
Please login first to submit.