public static void SetAxisZoomWheelAndPan(PlotView plotView) { if (plotView == null) { return; } plotView.Controller = new PlotController(); var zoomWheel = new DelegatePlotCommand <OxyMouseWheelEventArgs>((view, controller, args) => HandleZoomByWheel(view, args)); plotView.Controller.BindMouseWheel(OxyModifierKeys.None, zoomWheel); var zoomWheelCtrl = new DelegatePlotCommand <OxyMouseWheelEventArgs>((view, controller, args) => HandleZoomByWheelAndCtrl(view, args)); plotView.Controller.BindMouseWheel(OxyModifierKeys.Control, zoomWheelCtrl); var zoomWheelShift = new DelegatePlotCommand <OxyMouseWheelEventArgs>((view, controller, args) => HandleZoomByWheelAndShift(view, args)); plotView.Controller.BindMouseWheel(OxyModifierKeys.Shift, zoomWheelShift); var customPanAt = new DelegatePlotCommand <OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new CustomPanManipulator(view, EAxisDescription.XY), args)); plotView.Controller.BindMouseDown(OxyMouseButton.Right, OxyModifierKeys.None, customPanAt); var customPanAtCtrl = new DelegatePlotCommand <OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new CustomPanManipulator(view, EAxisDescription.Y), args)); plotView.Controller.BindMouseDown(OxyMouseButton.Right, OxyModifierKeys.Control, customPanAtCtrl); var customPanAtShift = new DelegatePlotCommand <OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new CustomPanManipulator(view, EAxisDescription.X), args)); plotView.Controller.BindMouseDown(OxyMouseButton.Right, OxyModifierKeys.Shift, customPanAtShift); }
public static Example MouseHandlingExample() { var model = new PlotModel { Title = "Mouse handling example" }; var series = new ScatterSeries(); model.Series.Add(series); // Create a command that adds points to the scatter series var command = new DelegatePlotCommand <OxyMouseDownEventArgs>( (v, c, a) => { a.Handled = true; var point = series.InverseTransform(a.Position); series.Points.Add(new ScatterPoint(point.X, point.Y)); model.InvalidatePlot(true); }); var controller = new PlotController(); controller.BindMouseDown(OxyMouseButton.Left, command); return(new Example(model, controller)); }
public PlotViewCustomZoom() : base() { Controller = new PlotController(); var zoomWheel = new DelegatePlotCommand <OxyMouseWheelEventArgs>((view, controller, args) => HandleZoomByWheel(view, args)); Controller.BindMouseWheel(OxyModifierKeys.None, zoomWheel); var zoomWheelCtrl = new DelegatePlotCommand <OxyMouseWheelEventArgs>((view, controller, args) => HandleZoomByWheelAndCtrl(view, args)); Controller.BindMouseWheel(OxyModifierKeys.Control, zoomWheelCtrl); var zoomWheelShift = new DelegatePlotCommand <OxyMouseWheelEventArgs>((view, controller, args) => HandleZoomByWheelAndShift(view, args)); Controller.BindMouseWheel(OxyModifierKeys.Shift, zoomWheelShift); var customPanAt = new DelegatePlotCommand <OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new CustomPanManipulator(view, EAxisDescription.XY), args)); Controller.BindMouseDown(OxyMouseButton.Right, OxyModifierKeys.None, customPanAt); var customPanAtCtrl = new DelegatePlotCommand <OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new CustomPanManipulator(view, EAxisDescription.Y), args)); Controller.BindMouseDown(OxyMouseButton.Right, OxyModifierKeys.Control, customPanAtCtrl); var customPanAtShift = new DelegatePlotCommand <OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new CustomPanManipulator(view, EAxisDescription.X), args)); Controller.BindMouseDown(OxyMouseButton.Right, OxyModifierKeys.Shift, customPanAtShift); MouseDoubleClick += new MouseButtonEventHandler(OnMouseDoubleClick); }
/// <summary> /// Initializes static members of the <see cref="PlotCommands" /> class. /// </summary> static PlotCommands() { // commands that can be triggered from key events Reset = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandleReset(view)); CopyTextReport = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => view.SetClipboardText(view.ActualModel.CreateTextReport())); CopyCode = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => view.SetClipboardText(view.ActualModel.ToCode())); // commands that can be triggered from mouse down events ResetAt = new DelegatePlotCommand <OxyMouseEventArgs>((view, controller, args) => HandleReset(view)); PanAt = new DelegatePlotCommand <OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new PanManipulator(view), args)); ZoomRectangle = new DelegatePlotCommand <OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new ZoomRectangleManipulator(view), args)); Track = new DelegatePlotCommand <OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new TrackerManipulator(view) { Snap = false, PointsOnly = false }, args)); SnapTrack = new DelegatePlotCommand <OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new TrackerManipulator(view) { Snap = true, PointsOnly = false }, args)); PointsOnlyTrack = new DelegatePlotCommand <OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new TrackerManipulator(view) { Snap = false, PointsOnly = true }, args)); ZoomWheel = new DelegatePlotCommand <OxyMouseWheelEventArgs>((view, controller, args) => HandleZoomByWheel(view, args)); ZoomWheelFine = new DelegatePlotCommand <OxyMouseWheelEventArgs>((view, controller, args) => HandleZoomByWheel(view, args, 0.1)); ZoomInAt = new DelegatePlotCommand <OxyMouseEventArgs>((view, controller, args) => HandleZoomAt(view, args, 0.05)); ZoomOutAt = new DelegatePlotCommand <OxyMouseEventArgs>((view, controller, args) => HandleZoomAt(view, args, -0.05)); // commands that can be triggered from mouse enter events HoverTrack = new DelegatePlotCommand <OxyMouseEventArgs>((view, controller, args) => controller.AddHoverManipulator(view, new TrackerManipulator(view) { LockToInitialSeries = false, Snap = false, PointsOnly = false }, args)); HoverSnapTrack = new DelegatePlotCommand <OxyMouseEventArgs>((view, controller, args) => controller.AddHoverManipulator(view, new TrackerManipulator(view) { LockToInitialSeries = false, Snap = true, PointsOnly = false }, args)); HoverPointsOnlyTrack = new DelegatePlotCommand <OxyMouseEventArgs>((view, controller, args) => controller.AddHoverManipulator(view, new TrackerManipulator(view) { LockToInitialSeries = false, Snap = false, PointsOnly = true }, args)); PanZoomByTouch = new DelegatePlotCommand <OxyTouchEventArgs>((view, controller, args) => controller.AddTouchManipulator(view, new TouchManipulator(view), args)); // commands that can be triggered from key events PanLeft = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandlePan(view, -0.1, 0)); PanRight = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandlePan(view, 0.1, 0)); PanUp = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandlePan(view, 0, -0.1)); PanDown = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandlePan(view, 0, 0.1)); PanLeftFine = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandlePan(view, -0.01, 0)); PanRightFine = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandlePan(view, 0.01, 0)); PanUpFine = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandlePan(view, 0, -0.01)); PanDownFine = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandlePan(view, 0, 0.01)); ZoomIn = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandleZoomCenter(view, 1)); ZoomOut = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandleZoomCenter(view, -1)); ZoomInFine = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandleZoomCenter(view, 0.1)); ZoomOutFine = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => HandleZoomCenter(view, -0.1)); }
public static Example ClickingOnAnAnnotation() { var plotModel = new PlotModel { Title = "Clicking on an annotation", Subtitle = "Click on the rectangles" }; plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom }); plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left }); var annotation1 = new RectangleAnnotation { Fill = OxyColors.Green, Text = "RectangleAnnotation 1", MinimumX = 25, MaximumX = 75, MinimumY = 20, MaximumY = 40 }; plotModel.Annotations.Add(annotation1); var annotation2 = new RectangleAnnotation { Fill = OxyColors.SkyBlue, Text = "RectangleAnnotation 2", MinimumX = 25, MaximumX = 75, MinimumY = 60, MaximumY = 80 }; plotModel.Annotations.Add(annotation2); EventHandler <OxyMouseDownEventArgs> handleMouseClick = (s, e) => { plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)s).Text; plotModel.InvalidatePlot(false); }; annotation1.MouseDown += handleMouseClick; annotation2.MouseDown += handleMouseClick; var controller = new PlotController(); var handleClick = new DelegatePlotCommand <OxyMouseDownEventArgs>( (v, c, e) => { var args = new HitTestArguments(e.Position, 10); var firstHit = v.ActualModel.HitTest(args).FirstOrDefault(x => x.Element is RectangleAnnotation); if (firstHit != null) { e.Handled = true; plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)firstHit.Element).Text; plotModel.InvalidatePlot(false); } }); controller.Bind(new OxyMouseDownGesture(OxyMouseButton.Left), handleClick); return(new Example(plotModel, controller)); }
/// <summary> /// Initializes a new instance of the <see cref="PlotView" /> class. /// </summary> public PlotView() { this.renderContext = new GraphicsRenderContext(); // ReSharper disable DoNotCallOverridableMethodsInConstructor this.DoubleBuffered = true; // ReSharper restore DoNotCallOverridableMethodsInConstructor this.PanCursor = Cursors.Hand; this.ZoomRectangleCursor = Cursors.SizeNWSE; this.ZoomHorizontalCursor = Cursors.SizeWE; this.ZoomVerticalCursor = Cursors.SizeNS; var DoCopy = new DelegatePlotCommand <OxyKeyEventArgs>((view, controller, args) => this.DoCopy(view, args)); this.ActualController.BindKeyDown(OxyKey.C, OxyModifierKeys.Control, DoCopy); }
static PlotCommands() { PanZoomByTouch = new DelegatePlotCommand <OxyTouchEventArgs>((view, controller, args) => controller.AddTouchManipulator(view, new Manipulators.TouchManipulator(view), args)); PanZoomByTouchAxisOnly = new DelegatePlotCommand <OxyTouchEventArgs>((view, controller, args) => controller.AddTouchManipulator(view, new Manipulators.TouchManipulator(view) { IsOnlyAcceptAxisPan = true }, args)); PanZoomByTouchTwoFinger = new DelegatePlotCommand <OxyTouchEventArgs>((view, controller, args) => controller.AddTouchManipulator(view, new Manipulators.TouchManipulator(view) { IsPanByTowFinger = true }, args)); SnapTrackTouch = new DelegatePlotCommand <OxyTouchEventArgs>((view, controller, args) => controller.AddTouchManipulator(view, new Manipulators.TouchTrackerManipulator(view) { Snap = true, PointsOnly = true }, args)); }
/// <summary> /// Initializes static members of the <see cref="PlotCommands" /> class. /// </summary> static PlotCommands() { // commands that can be triggered from key events Reset = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandleReset(view, args)); CopyTextReport = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandleCopyTextReport(view, args)); CopyCode = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandleCopyCode(view, args)); // commands that can be triggered from mouse down events ResetAt = new DelegatePlotCommand<OxyMouseEventArgs>((view, controller, args) => HandleReset(view, args)); PanAt = new DelegatePlotCommand<OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new PanManipulator(view), args)); ZoomRectangle = new DelegatePlotCommand<OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new ZoomRectangleManipulator(view), args)); Track = new DelegatePlotCommand<OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new TrackerManipulator(view) { Snap = false, PointsOnly = false }, args)); SnapTrack = new DelegatePlotCommand<OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new TrackerManipulator(view) { Snap = true, PointsOnly = false }, args)); PointsOnlyTrack = new DelegatePlotCommand<OxyMouseDownEventArgs>((view, controller, args) => controller.AddMouseManipulator(view, new TrackerManipulator(view) { Snap = false, PointsOnly = true }, args)); ZoomWheel = new DelegatePlotCommand<OxyMouseWheelEventArgs>((view, controller, args) => HandleZoomByWheel(view, args)); ZoomWheelFine = new DelegatePlotCommand<OxyMouseWheelEventArgs>((view, controller, args) => HandleZoomByWheel(view, args, 0.1)); ZoomInAt = new DelegatePlotCommand<OxyMouseEventArgs>((view, controller, args) => HandleZoomAt(view, args, 0.05)); ZoomOutAt = new DelegatePlotCommand<OxyMouseEventArgs>((view, controller, args) => HandleZoomAt(view, args, -0.05)); // commands that can be triggered from mouse enter events HoverTrack = new DelegatePlotCommand<OxyMouseEventArgs>((view, controller, args) => controller.AddHoverManipulator(view, new TrackerManipulator(view) { LockToInitialSeries = false, Snap = false, PointsOnly = false }, args)); HoverSnapTrack = new DelegatePlotCommand<OxyMouseEventArgs>((view, controller, args) => controller.AddHoverManipulator(view, new TrackerManipulator(view) { LockToInitialSeries = false, Snap = true, PointsOnly = false }, args)); HoverPointsOnlyTrack = new DelegatePlotCommand<OxyMouseEventArgs>((view, controller, args) => controller.AddHoverManipulator(view, new TrackerManipulator(view) { LockToInitialSeries = false, Snap = false, PointsOnly = true }, args)); // Touch events SnapTrackTouch = new DelegatePlotCommand<OxyTouchEventArgs>((view, controller, args) => controller.AddTouchManipulator(view, new TouchTrackerManipulator(view) { Snap = true, PointsOnly = false }, args)); PointsOnlyTrackTouch = new DelegatePlotCommand<OxyTouchEventArgs>((view, controller, args) => controller.AddTouchManipulator(view, new TouchTrackerManipulator(view) { Snap = true, PointsOnly = true }, args)); PanZoomByTouch = new DelegatePlotCommand<OxyTouchEventArgs>((view, controller, args) => controller.AddTouchManipulator(view, new TouchManipulator(view), args)); // commands that can be triggered from key events PanLeft = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandlePan(view, args, -0.1, 0)); PanRight = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandlePan(view, args, 0.1, 0)); PanUp = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandlePan(view, args, 0, -0.1)); PanDown = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandlePan(view, args, 0, 0.1)); PanLeftFine = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandlePan(view, args, -0.01, 0)); PanRightFine = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandlePan(view, args, 0.01, 0)); PanUpFine = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandlePan(view, args, 0, -0.01)); PanDownFine = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandlePan(view, args, 0, 0.01)); ZoomIn = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandleZoomCenter(view, args, 1)); ZoomOut = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandleZoomCenter(view, args, -1)); ZoomInFine = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandleZoomCenter(view, args, 0.1)); ZoomOutFine = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => HandleZoomCenter(view, args, -0.1)); }
public static Example MouseHandlingExample() { var model = new PlotModel { Title = "Mouse handling example" }; var series = new ScatterSeries(); model.Series.Add(series); // Create a command that adds points to the scatter series var command = new DelegatePlotCommand<OxyMouseEventArgs>( (v, c, a) => { var point = series.InverseTransform(a.Position); series.Points.Add(new ScatterPoint(point.X, point.Y)); model.InvalidatePlot(true); }); var controller = new PlotController(); controller.BindMouseDown(OxyMouseButton.Left, command); return new Example(model, controller); }
public static Example ClickingOnAnAnnotation() { var plotModel = new PlotModel { Title = "Clicking on an annotation", Subtitle = "Click on the rectangles" }; plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom }); plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left }); var annotation1 = new RectangleAnnotation { Fill = OxyColors.Green, Text = "RectangleAnnotation 1", MinimumX = 25, MaximumX = 75, MinimumY = 20, MaximumY = 40 }; plotModel.Annotations.Add(annotation1); var annotation2 = new RectangleAnnotation { Fill = OxyColors.SkyBlue, Text = "RectangleAnnotation 2", MinimumX = 25, MaximumX = 75, MinimumY = 60, MaximumY = 80 }; plotModel.Annotations.Add(annotation2); EventHandler<OxyMouseDownEventArgs> handleMouseClick = (s, e) => { plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)s).Text; plotModel.InvalidatePlot(false); }; annotation1.MouseDown += handleMouseClick; annotation2.MouseDown += handleMouseClick; var controller = new PlotController(); var handleClick = new DelegatePlotCommand<OxyMouseDownEventArgs>( (v, c, e) => { var args = new HitTestArguments(e.Position, 10); var firstHit = v.ActualModel.HitTest(args).FirstOrDefault(x => x.Element is RectangleAnnotation); if (firstHit != null) { e.Handled = true; plotModel.Subtitle = "You clicked " + ((RectangleAnnotation)firstHit.Element).Text; plotModel.InvalidatePlot(false); } }); controller.Bind(new OxyMouseDownGesture(OxyMouseButton.Left), handleClick); return new Example(plotModel, controller); }