public override void OnModifierKeyDown(ModifierKeyArgs e) { base.OnModifierKeyDown(e); double factor = 0; if ((e.Key == Key.Add || e.Key == Key.OemPlus) && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { // On CTRL+, Zoom In factor = -ZoomFraction; } if ((e.Key == Key.Subtract || e.Key == Key.OemMinus) && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { // On CTRL-, Zoom Out factor = ZoomFraction; } using (ParentSurface.SuspendUpdates()) { // Zoom the XAxis by the required factor XAxis.ZoomBy(factor, factor, TimeSpan.FromMilliseconds(500)); // Zoom the YAxis by the required factor YAxis.ZoomBy(factor, factor, TimeSpan.FromMilliseconds(500)); // Note.. can be extended for multiple YAxis XAxis, just iterate over all axes on the parent surface } }
public override void OnModifierMouseWheel(ModifierMouseArgs e) { e.Handled = true; var usey = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl); var usex = true; var factor = 1 - e.Delta * 0.001; using (ParentSurface.SuspendUpdates()) { var p = TransformMousePoint(GetPointRelativeTo(e.MousePoint, ParentSurface.RenderSurface)); if (usex) { var vr = ParentSurface.XAxis.VisibleRange.AsDoubleRange(); var leftPart = p.X - vr.Min; var rightPart = vr.Max - p.X; leftPart *= factor; rightPart *= factor; ParentSurface.XAxis.VisibleRange = new DoubleRange(p.X - leftPart, p.X + rightPart); } if (usey) { var vr = ParentSurface.YAxis.VisibleRange.AsDoubleRange(); var bottomPart = p.Y - vr.Min; var topPart = vr.Max - p.Y; bottomPart *= factor; topPart *= factor; ParentSurface.YAxis.VisibleRange = new DoubleRange(p.Y - bottomPart, p.Y + topPart); } } }
public override void OnModifierMouseMove(ModifierMouseArgs e) { base.OnModifierMouseMove(e); if (_lastPoint == null) { return; } var currentPoint = e.MousePoint; var xDelta = currentPoint.X - _lastPoint.Value.X; var yDelta = _lastPoint.Value.Y - currentPoint.Y; using (ParentSurface.SuspendUpdates()) { // Scroll the XAxis by the number of pixels since the last update XAxis.Scroll(XAxis.IsHorizontalAxis ? xDelta : -yDelta, ClipMode.None); // Scroll the YAxis by the number of pixels since the last update YAxis.Scroll(YAxis.IsHorizontalAxis ? -xDelta : yDelta, ClipMode.None); // Note.. can be extended for multiple YAxis XAxis, just iterate over all axes on the parent surface } _lastPoint = currentPoint; }
public void FlipAxes(AxisCollection axes) { using (ParentSurface.SuspendUpdates()) { foreach (var axis in axes) { axis.FlipCoordinates = !axis.FlipCoordinates; } } }
public override void OnModifierMouseWheel(ModifierMouseArgs e) { foreach (var axis in YAxes) { // Find the axis under the mouse now var axisBounds = axis.GetBoundsRelativeTo(RootGrid); if (axis.IsHorizontalAxis && axisBounds.Height < MinTouchArea) { axisBounds.Y -= (MinTouchArea - axisBounds.Height) / 2; axisBounds.Height = MinTouchArea; } if (!axis.IsHorizontalAxis && axisBounds.Width < MinTouchArea) { axisBounds.X -= (MinTouchArea - axisBounds.Width) / 2; axisBounds.Width = MinTouchArea; } // Look only for the first axis that has been hit if (axisBounds.Contains(e.MousePoint)) { e.Handled = true; const double mouseWheelDeltaCoef = 120; using (ParentSurface.SuspendUpdates()) { double value = -e.Delta / mouseWheelDeltaCoef; var mousePoint = GetPointRelativeTo(e.MousePoint, ModifierSurface); // Do the zoom on the axis const double GrowFactor = 0.1; double fraction = GrowFactor * value; GrowBy(mousePoint, axis, fraction); } } } }
public IUpdateSuspender SuspendUpdates() { return(ParentSurface.SuspendUpdates()); }