Skip to content

Commit 120ce4f

Browse files
committed
Add cursors for viewing subset of F,d data
1 parent 72a009b commit 120ce4f

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

UI/TWOMDataViewer.m

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ function clearPlots(self)
8888
axis(ax, 'tight');
8989
set(ax, 'FontSize', 12);
9090
end
91+
92+
% Add cursors to F,t / d,t plots
93+
self.gui.plotft.cur = cursors(self.gui.plotft.axes, [1 0 0]);
94+
self.gui.plotdt.cur = cursors(self.gui.plotdt.axes, [1 0 0]);
9195
end
9296

9397
function loadFile(self, file)
@@ -169,21 +173,47 @@ function updateData(self)
169173
% << nested functions
170174
end
171175

176+
function updateFdPlot(self)
177+
minT = min(self.gui.plotft.cur.Positions);
178+
maxT = max(self.gui.plotft.cur.Positions);
179+
for i = 1:self.data.length
180+
fd_subset = self.data.items{i}.subset('t', [minT maxT]);
181+
set(self.gui.plotfd.plots(i), ...
182+
'XData', fd_subset.d, 'YData', fd_subset.f);
183+
end
184+
end
185+
172186
function updatePlots(self)
173187
if isempty(self.data)
174188
return
175189
end
176190

191+
% TODO Optimize this: maybe only delete plots / update plot data,
192+
% instead of clearing axes every time, and thus every time
193+
% recreating things like cursors?
177194
self.clearPlots();
178195

196+
% Plot data
197+
self.gui.plotfd.plots = [];
179198
for i = 1:self.data.length
180-
plot(self.gui.plotfd.axes, self.data.items{i}.d, self.data.items{i}.f, '.');
181-
hold(self.gui.plotfd.axes, 'on');
199+
self.gui.plotfd.plots(end+1) = ...
200+
plot(self.gui.plotfd.axes, [NaN], [NaN], '.');
201+
hold(self.gui.plotft.axes, 'on');
182202
plot(self.gui.plotft.axes, self.data.items{i}.t, self.data.items{i}.f, '.');
183203
hold(self.gui.plotft.axes, 'on');
184204
plot(self.gui.plotdt.axes, self.data.items{i}.t, self.data.items{i}.d, '.');
185205
hold(self.gui.plotdt.axes, 'on');
186206
end
207+
208+
% Update cursors
209+
for cur = {self.gui.plotft.cur, self.gui.plotdt.cur}
210+
cur{1}.add(min(self.data.items{i}.t));
211+
cur{1}.add(max(self.data.items{i}.t));
212+
addlistener(cur{1}, 'onDrag', @(h,e) self.onCursorDrag(h,e));
213+
addlistener(cur{1}, 'onReleased', @(h,e) self.onCursorRelease(h,e));
214+
end
215+
216+
self.updateFdPlot();
187217
end
188218

189219
end
@@ -255,6 +285,7 @@ function createGui(self)
255285
% ----- Center, main panel
256286
self.gui.main.panel = uiextras.VBoxFlex('Parent', self.gui.root);
257287

288+
% Create plot axes
258289
self.gui.allaxes = [];
259290
for axesName = {'plotfd', 'plotft', 'plotdt'}
260291
self.gui.(axesName{1}).panel = uiextras.Panel('Parent', self.gui.main.panel);
@@ -360,6 +391,19 @@ function onBrowseBtnClick(self, ~, ~)
360391
end
361392
end
362393

394+
function onCursorDrag(self, h, e)
395+
% Sync cursors in other graph with this one.
396+
if h == self.gui.plotft.cur
397+
self.gui.plotdt.cur.Positions = e.Positions;
398+
else
399+
self.gui.plotft.cur.Positions = e.Positions;
400+
end
401+
end
402+
403+
function onCursorRelease(self, h, e)
404+
self.updateFdPlot();
405+
end
406+
363407
function onDirChange(self, ~, ~)
364408
self.browseTo(self.gui.dirpanel.edit.String);
365409
end

0 commit comments

Comments
 (0)