forked from acsutt0n/Drosophila-larvae_old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaxdrag.m
193 lines (163 loc) · 6.66 KB
/
axdrag.m
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
function axdrag(action)
%AXDRAG Pan and zoom with simple keystrokes
% Use this tool to move quickly around the data displayed in a 2-D plot.
% Make sure the figure has focus, and then press any of the following
% keys to zoom in or out. Clicking and dragging will pan the data.
%
% Keys you can use are:
% z, Z: zoom in, zoom out, in both dimensions
% x, X: zoom in, zoom out, x dimension only
% y, Y: zoom in, zoom out, y dimension only
% arrow keys: pan the data
% a: axis auto
% n: axis normal
% e: axis equal
% g: toggle grid state
% spacebar: toggle axis tick display state
% h: help
%
% Example
% c = pi*(1+sqrt(5))/2;
% x = 0:1000;
% r = 2.72378;
% z = cumsum(exp(i*(c*x.*x + r)));
% plot(real(z),imag(z));
% axdrag
% % Now click, drag, and use special keys ...
% Copyright 2003, The MathWorks, Inc.
% Ned Gulley, March 2003
persistent x0 dx
if nargin < 1,
action = 'initialize';
end
% Use these variables to change the zoom and pan amounts
zoomFactor = 0.9;
panFactor = 0.02;
% Get rid of the help window if it's being displayed
helpTextAxis = findobj(gcbf,'Type','axes','Tag','axdraghelpaxis');
if isempty(helpTextAxis)
helpWasOff = 1;
else
helpWasOff = 0;
delete(helpTextAxis);
end
switch action
case 'initialize'
set(gca,'ButtonDownFcn','axdrag start')
set(gcf,'KeyPressFcn','axdrag keypress')
set(gcf,'DoubleBuffer','on')
case 'start'
set(gcbf,'Units','pixel');
set(gca,'Units','pixel');
set(gcbf,'WindowButtonMotionFcn','axdrag move')
set(gcbf,'WindowButtonUpFcn','axdrag stop')
currentPoint = get(gcbf,'CurrentPoint');
x0 = currentPoint;
axdrag move
case 'move'
currentPoint = get(gcbf,'CurrentPoint');
dx = currentPoint - x0;
x0 = currentPoint;
ap = get(gca,'Position');
xLim = get(gca,'XLim');
yLim = get(gca,'YLim');
set(gca,'XLim',xLim-(diff(xLim)*dx(1)/ap(3)), ...
'YLim',yLim-(diff(yLim)*dx(2)/ap(4)));
case 'stop'
set(gcbf,'WindowButtonMotionFcn','')
set(gcbf,'WindowButtonUpFcn','')
set(gcbf,'Units','normalized');
set(gca,'Units','normalized');
case 'keypress'
currChar = get(gcbf,'CurrentCharacter');
if isempty(currChar)
return
end
if currChar=='a',
axis auto
elseif currChar=='e',
axis equal
elseif currChar=='n',
axis normal
elseif currChar=='g',
grid
elseif currChar==29,
xLim=get(gca,'XLim');
xLimNew = xLim + panFactor*diff(xLim);
set(gca,'XLim',xLimNew)
elseif currChar==28,
xLim=get(gca,'XLim');
xLimNew = xLim - panFactor*diff(xLim);
set(gca,'XLim',xLimNew)
elseif currChar==30,
yLim=get(gca,'YLim');
yLimNew = yLim - panFactor*diff(yLim);
set(gca,'YLim',yLimNew)
elseif currChar==31,
yLim=get(gca,'YLim');
yLimNew = yLim + panFactor*diff(yLim);
set(gca,'YLim',yLimNew)
elseif abs(currChar)==32,
if isempty(get(gca,'XTick')),
set(gca,'XTickMode','auto','YTickMode','auto')
else
set(gca,'XTick',[],'YTick',[],'Box','on')
end
elseif (currChar=='x') || (currChar=='X'),
if currChar == 'X',
zoomFactor=1/zoomFactor;
end
xLim=get(gca,'XLim');
xLimNew = [0 zoomFactor*diff(xLim)] + xLim(1) + (1-zoomFactor)*diff(xLim)/2;
set(gca,'XLim',xLimNew)
elseif (currChar=='y') || (currChar=='Y'),
if currChar == 'Y',
zoomFactor=1/zoomFactor;
end
yLim=get(gca,'YLim');
yLimNew = [0 zoomFactor*diff(yLim)] + yLim(1) + (1-zoomFactor)*diff(yLim)/2;
set(gca,'YLim',yLimNew)
elseif (currChar=='z') || (currChar=='Z'),
if currChar == 'Z',
zoomFactor=1/zoomFactor;
end
xLim=get(gca,'XLim');
yLim=get(gca,'YLim');
xLimNew = [0 zoomFactor*diff(xLim)] + xLim(1) + (1-zoomFactor)*diff(xLim)/2;
yLimNew = [0 zoomFactor*diff(yLim)] + yLim(1) + (1-zoomFactor)*diff(yLim)/2;
set(gca,'XLim',xLimNew,'YLim',yLimNew)
elseif currChar=='h',
if helpWasOff
str = { ...
' '
' AXDRAG. Keys you can use are:'
' '
' z, Z: zoom in, zoom out, both dimensions '
' x, X: zoom in, zoom out, x dimension only '
' y, Y: zoom in, zoom out, y dimension only '
' arrow keys: pan the data'
' a: axis auto'
' n: axis normal'
' e: axis equal'
' g: toggle grid state'
' spacebar: toggle axis tick display state'
' h: help'
' '
' Press ''h'' again to dismiss this message'
' ' ...
};
helpTextAxis = axes( ...
'Tag','axdraghelpaxis', ...
'Units','characters', ...
'Position',[2 3 76 16], ...
'Visible','off');
text(0,1,str, ...
'Parent',helpTextAxis, ...
'VerticalAlignment','top', ...
'BackgroundColor',[1 1 0.8], ...
'FontName','courier', ...
'FontSize',10);
end
end
end
end