-
Notifications
You must be signed in to change notification settings - Fork 976
Expand file tree
/
Copy pathPlotCommands.cs
More file actions
291 lines (249 loc) · 14.5 KB
/
Copy pathPlotCommands.cs
File metadata and controls
291 lines (249 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PlotCommands.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// <summary>
// Defines common commands for the plots.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace OxyPlot
{
/// <summary>
/// Defines common commands for the plots.
/// </summary>
public static class PlotCommands
{
/// <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));
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));
}
/// <summary>
/// Gets the reset axes command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> Reset { get; private set; }
/// <summary>
/// Gets the reset axes command (for mouse events).
/// </summary>
public static IViewCommand<OxyMouseEventArgs> ResetAt { get; private set; }
/// <summary>
/// Gets the copy code command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> CopyCode { get; private set; }
/// <summary>
/// Gets the pan/zoom touch command.
/// </summary>
public static IViewCommand<OxyTouchEventArgs> PanZoomByTouch { get; private set; }
/// <summary>
/// Gets the pan command.
/// </summary>
public static IViewCommand<OxyMouseDownEventArgs> PanAt { get; private set; }
/// <summary>
/// Gets the zoom rectangle command.
/// </summary>
public static IViewCommand<OxyMouseDownEventArgs> ZoomRectangle { get; private set; }
/// <summary>
/// Gets the zoom by mouse wheel command.
/// </summary>
public static IViewCommand<OxyMouseWheelEventArgs> ZoomWheel { get; private set; }
/// <summary>
/// Gets the fine-control zoom by mouse wheel command.
/// </summary>
public static IViewCommand<OxyMouseWheelEventArgs> ZoomWheelFine { get; private set; }
/// <summary>
/// Gets the tracker command.
/// </summary>
public static IViewCommand<OxyMouseDownEventArgs> Track { get; private set; }
/// <summary>
/// Gets the snap tracker command.
/// </summary>
public static IViewCommand<OxyMouseDownEventArgs> SnapTrack { get; private set; }
/// <summary>
/// Gets the snap tracker command.
/// </summary>
public static IViewCommand<OxyTouchEventArgs> SnapTrackTouch { get; private set; }
/// <summary>
/// Gets the points only tracker command.
/// </summary>
public static IViewCommand<OxyMouseDownEventArgs> PointsOnlyTrack { get; private set; }
/// <summary>
/// Gets the points only tracker command.
/// </summary>
public static IViewCommand<OxyTouchEventArgs> PointsOnlyTrackTouch { get; private set; }
/// <summary>
/// Gets the mouse hover tracker.
/// </summary>
public static IViewCommand<OxyMouseEventArgs> HoverTrack { get; private set; }
/// <summary>
/// Gets the mouse hover snap tracker.
/// </summary>
public static IViewCommand<OxyMouseEventArgs> HoverSnapTrack { get; private set; }
/// <summary>
/// Gets the mouse hover points only tracker.
/// </summary>
public static IViewCommand<OxyMouseEventArgs> HoverPointsOnlyTrack { get; private set; }
/// <summary>
/// Gets the pan left command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> PanLeft { get; private set; }
/// <summary>
/// Gets the pan right command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> PanRight { get; private set; }
/// <summary>
/// Gets the pan up command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> PanUp { get; private set; }
/// <summary>
/// Gets the pan down command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> PanDown { get; private set; }
/// <summary>
/// Gets the fine control pan left command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> PanLeftFine { get; private set; }
/// <summary>
/// Gets the fine control pan right command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> PanRightFine { get; private set; }
/// <summary>
/// Gets the fine control pan up command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> PanUpFine { get; private set; }
/// <summary>
/// Gets the fine control pan down command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> PanDownFine { get; private set; }
/// <summary>
/// Gets the zoom in command.
/// </summary>
public static IViewCommand<OxyMouseEventArgs> ZoomInAt { get; private set; }
/// <summary>
/// Gets the zoom out command.
/// </summary>
public static IViewCommand<OxyMouseEventArgs> ZoomOutAt { get; private set; }
/// <summary>
/// Gets the zoom in command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> ZoomIn { get; private set; }
/// <summary>
/// Gets the zoom out command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> ZoomOut { get; private set; }
/// <summary>
/// Gets the fine control zoom in command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> ZoomInFine { get; private set; }
/// <summary>
/// Gets the fine control zoom out command.
/// </summary>
public static IViewCommand<OxyKeyEventArgs> ZoomOutFine { get; private set; }
/// <summary>
/// Handles the reset event.
/// </summary>
/// <param name="view">The view to reset.</param>
/// <param name="args">The <see cref="OxyInputEventArgs" /> instance containing the event data.</param>
private static void HandleReset(IPlotView view, OxyInputEventArgs args)
{
args.Handled = true;
view.ActualModel.ResetAllAxes();
view.InvalidatePlot(false);
}
/// <summary>
/// Handles the copy code event.
/// </summary>
/// <param name="view">The view.</param>
/// <param name="args">The <see cref="OxyInputEventArgs"/> instance containing the event data.</param>
private static void HandleCopyCode(IPlotView view, OxyInputEventArgs args)
{
args.Handled = true;
var code = view.ActualModel.ToCode();
view.SetClipboardText(code);
}
/// <summary>
/// Zooms the view by the specified factor at the position specified in the <see cref="OxyMouseEventArgs" />.
/// </summary>
/// <param name="view">The view.</param>
/// <param name="args">The <see cref="OxyMouseWheelEventArgs" /> instance containing the event data.</param>
/// <param name="delta">The zoom factor.</param>
private static void HandleZoomAt(IPlotView view, OxyMouseEventArgs args, double delta)
{
var m = new ZoomStepManipulator(view) { Step = delta, FineControl = args.IsControlDown };
m.Started(args);
}
/// <summary>
/// Zooms the view by the mouse wheel delta in the specified <see cref="OxyKeyEventArgs" />.
/// </summary>
/// <param name="view">The view.</param>
/// <param name="args">The <see cref="OxyMouseWheelEventArgs" /> instance containing the event data.</param>
/// <param name="factor">The zoom speed factor. Default value is 1.</param>
private static void HandleZoomByWheel(IPlotView view, OxyMouseWheelEventArgs args, double factor = 1)
{
var m = new ZoomStepManipulator(view) { Step = args.Delta * 0.001 * factor, FineControl = args.IsControlDown };
m.Started(args);
}
/// <summary>
/// Zooms the view by the key in the specified factor.
/// </summary>
/// <param name="view">The view.</param>
/// <param name="args">The <see cref="OxyInputEventArgs" /> instance containing the event data.</param>
/// <param name="delta">The zoom factor (positive zoom in, negative zoom out).</param>
private static void HandleZoomCenter(IPlotView view, OxyInputEventArgs args, double delta)
{
args.Handled = true;
view.ActualModel.ZoomAllAxes(1 + (delta * 0.12));
view.InvalidatePlot(false);
}
/// <summary>
/// Pans the view by the key in the specified vector.
/// </summary>
/// <param name="view">The view.</param>
/// <param name="args">The <see cref="OxyInputEventArgs" /> instance containing the event data.</param>
/// <param name="dx">The horizontal delta (percentage of plot area width).</param>
/// <param name="dy">The vertical delta (percentage of plot area height).</param>
private static void HandlePan(IPlotView view, OxyInputEventArgs args, double dx, double dy)
{
args.Handled = true;
dx *= view.ActualModel.PlotArea.Width;
dy *= view.ActualModel.PlotArea.Height;
view.ActualModel.PanAllAxes(dx, dy);
view.InvalidatePlot(false);
}
}
}