Commit 6bf14d2e authored by James Desjardins's avatar James Desjardins
Browse files

fix ability to use multiple simultaneous scroll plots by moving ve_eegplot...

fix ability to use multiple simultaneous scroll plots by moving ve_eegplot persistent variables into the figure userdata.
parent 813bc346
......@@ -221,11 +221,11 @@ DEFAULT_AXES_POSITION = [0.0964286 0.15 0.842 0.75-(MAXEVENTSTRING-5)/100];
% dimensions of main EEG axes
ORIGINAL_POSITION = [50 50 800 500];
persistent ax0;
persistent ax1;
persistent etime;
persistent eelec;
persistent evalue;
%persistent ax0;
%persistent ax1;
%persistent etime;
%persistent eelec;
%persistent evalue;
if nargin < 1
help ve_eegplot
......@@ -444,7 +444,10 @@ if ~isstr(data) % If NOT a 'noui' call or a callback from uicontrols
% Background axis
% ---------------
ax0 = axes('tag','backeeg','parent',figh,...
% ax0 = axes('tag','backeeg','parent',figh,...
% 'Position',DEFAULT_AXES_POSITION,...
% 'Box','off','xgrid','off', 'xaxislocation', 'top');
g.ax0 = axes('tag','backeeg','parent',figh,...
'Position',DEFAULT_AXES_POSITION,...
'Box','off','xgrid','off', 'xaxislocation', 'top');
......@@ -452,7 +455,7 @@ if ~isstr(data) % If NOT a 'noui' call or a callback from uicontrols
% ---------------
YLabels = num2str((1:g.chans)'); % Use numbers as default
YLabels = flipud(str2mat(YLabels,' '));
ax1 = axes('Position',DEFAULT_AXES_POSITION,...
g.ax1 = axes('Position',DEFAULT_AXES_POSITION,...
'userdata', data, ...% store the data here
'tag','eegaxis','parent',figh,...%(when in g, slow down display)
'Box','on','xgrid', g.xgrid,'ygrid', g.ygrid,...
......@@ -472,7 +475,7 @@ if ~isstr(data) % If NOT a 'noui' call or a callback from uicontrols
if isstruct(g.eloc_file) & length(g.eloc_file) > size(data,1)
g.eloc_file(end) = []; % common reference channel location
end;
ve_eegplot('setelect', g.eloc_file, ax1);
ve_eegplot('setelect', g.eloc_file, g.ax1);
end;
% %%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -658,14 +661,14 @@ if ~isstr(data) % If NOT a 'noui' call or a callback from uicontrols
'Callback','ve_eegplot(''draws'',2)');
cb_normalize = ['g = get(gcbf,''userdata'');if g.normed, disp(''Denormalizing...''); else, disp(''Normalizing...''); end;'...
'ax1 = findobj(''tag'',''eegaxis'',''parent'',gcbf);' ...
'data = get(ax1,''UserData'');' ...
'g.ax1 = findobj(''tag'',''eegaxis'',''parent'',gcbf);' ...
'data = get(g.ax1,''UserData'');' ...
'if isempty(g.datastd), g.datastd = std(data(:,1:min(1000,g.frames),[],2));end;'...
'if g.normed, for i = 1:size(data,1), data(i,:,:) = data(i,:,:)*g.datastd(i);set(gcbo,''string'', ''Norm'');set(findobj(''tag'',''ESpacing'',''parent'',gcbf),''string'',num2str(g.oldspacing));end;' ...
'else, for i = 1:size(data,1), data(i,:,:) = data(i,:,:)/g.datastd(i);end;set(gcbo,''string'', ''Denorm'');g.oldspacing = g.spacing;set(findobj(''tag'',''ESpacing'',''parent'',gcbf),''string'',''5'');end;' ...
'g.normed = 1 - g.normed;' ...
've_eegplot(''draws'',0);'...
'set(gcbf,''userdata'',g);set(ax1,''UserData'',data);clear ax1 g data;' ...
'set(gcbf,''userdata'',g);set(g.ax1,''UserData'',data);clear g.ax1 g data;' ...
've_eegplot(''drawp'',0);' ...
'disp(''Done.'')'];
% Button for Normalizing data
......@@ -1059,13 +1062,13 @@ u(22) = uicontrol('Parent',figh, ...
% %%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot EEG Data
% %%%%%%%%%%%%%%%%%%%%%%%%%%
axes(ax1)
axes(g.ax1)
hold on
% %%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot Spacing I
% %%%%%%%%%%%%%%%%%%%%%%%%%%
YLim = get(ax1,'Ylim');
YLim = get(g.ax1,'Ylim');
A = DEFAULT_AXES_POSITION;
axes('Position',[A(1)+A(3) A(2) 1-A(1)-A(3) A(4)],'Visible','off','Ylim',YLim,'tag','eyeaxes')
axis manual
......@@ -1089,14 +1092,15 @@ u(22) = uicontrol('Parent',figh, ...
h = findobj(gcf, 'tag', 'eegslider');
set(h, 'backgroundcolor', BUTTON_COLOR);
set(figh, 'visible', 'on');
if isempty(etime);
etime = findobj('tag','Etime','parent',figh);
if ~isfield(g,'etime');
g.etime = findobj('tag','Etime','parent',figh);
end;
if isempty(eelec);
eelec = findobj('tag','Eelec','parent',figh);
if ~isfield(g,'eelec');
g.eelec = findobj('tag','Eelec','parent',figh);
end;
if isempty(evalue);
evalue = findobj('tag','Evalue','parent',figh);
if ~isfield(g,'evalue');
g.evalue = findobj('tag','Evalue','parent',figh);
end;
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -1119,7 +1123,7 @@ else
figh = get(figh,'UserData');
end
g = get(figh,'UserData');
data = get(ax1,'UserData');
data = get(g.ax1,'UserData');
ESpacing = findobj('tag','ESpacing','parent',figh); % ui handle
EPosition = findobj('tag','EPosition','parent',figh); % ui handle
if g.trialstag(1) == -1
......@@ -1188,7 +1192,7 @@ else
end;
end;
if strcmpi(g.plotdata2, 'off')
axes(ax1)
axes(g.ax1)
obj_2_clear = findobj('-regexp','tag','text_*','-or','-regexp','tag','marker_*');
cla(obj_2_clear); % clear all except text and markers
end;
......@@ -1199,7 +1203,7 @@ else
end
% plot data
% ---------
axes(ax1)
axes(g.ax1)
hold on
......@@ -1379,44 +1383,45 @@ else
end
end
g.spacing = oldspacing;
set(ax1, 'Xlim',[1 g.winlength*multiplier+1],...
set(g.ax1, 'Xlim',[1 g.winlength*multiplier+1],...
'XTick',[1:multiplier*DEFAULT_GRID_SPACING:g.winlength*multiplier+1]);
set(ax1, 'XTickLabel', num2str((g.time:DEFAULT_GRID_SPACING:g.time+g.winlength)'))
set(g.ax1, 'XTickLabel', num2str((g.time:DEFAULT_GRID_SPACING:g.time+g.winlength)'))
% ordinates: even if all elec are plotted, some may be hidden
set(ax1, 'ylim',[g.elecoffset*g.spacing (g.elecoffset+g.dispchans+1)*g.spacing] );
set(g.ax1, 'ylim',[g.elecoffset*g.spacing (g.elecoffset+g.dispchans+1)*g.spacing] );
if g.children ~= 0
if ~exist('p2')
p2 =[];
end;
ve_eegplot( 'drawp', p1, p2, g.children);
figure(figh);
end;
% draw second data if necessary
if ~isempty(g.data2)
tmpdata = data;
set(ax1, 'userdata', g.data2);
set(g.ax1, 'userdata', g.data2);
g.data2 = [];
g.plotdata2 = 'on';
set(figh, 'userdata', g);
ve_eegplot('drawp', 0);
g.plotdata2 = 'off';
g.data2 = get(ax1, 'userdata');
set(ax1, 'userdata', tmpdata);
g.data2 = get(g.ax1, 'userdata');
set(g.ax1, 'userdata', tmpdata);
set(figh, 'userdata', g);
else
ve_eegplot('drawb');
end;
if g.children ~= 0
if ~exist('p2')
p2 =[];
end;
ve_eegplot( 'drawp', p1, p2, g.children);
figure(figh);
end;
case 'drawb' % Draw background ******************************************************
% Redraw EEG and change position
g = get(gcf,'UserData'); % Data (Note: this could also be global)
% Plot data and update axes
axes(ax0);
axes(g.ax0);
cla;
hold on;
% plot rejected windows
......@@ -1556,11 +1561,11 @@ else
% compute Xticks
% --------------
tagnum = (alltag-1)/g.trialstag+1;
set(ax0,'XTickLabel', tagnum,'YTickLabel', [],...
set(g.ax0,'XTickLabel', tagnum,'YTickLabel', [],...
'Xlim',[0 g.winlength*multiplier],...
'XTick',alltag-lowlim+g.trialstag/2, 'YTick',[], 'tag','backeeg');
axes(ax1);
axes(g.ax1);
tagpos = [];
tagtext = [];
if ~isempty(alltag)
......@@ -1596,23 +1601,23 @@ else
% find corresponding epochs
% -------------------------
tagtext = eeg_point2lat(tagpos, floor((tagpos)/g.trialstag)+1, g.srate, g.limits, 1E-3);
set(ax1,'XTickLabel', tagtext,'XTick', tagpos-lowlim);
set(g.ax1,'XTickLabel', tagtext,'XTick', tagpos-lowlim);
else
set(ax0,'XTickLabel', [],'YTickLabel', [],...
set(g.ax0,'XTickLabel', [],'YTickLabel', [],...
'Xlim',[0 g.winlength*multiplier],...
'XTick',[], 'YTick',[], 'tag','backeeg');
axes(ax1);
set(ax1,'XTickLabel', num2str((g.time:DEFAULT_GRID_SPACING:g.time+g.winlength)'),...
axes(g.ax1);
set(g.ax1,'XTickLabel', num2str((g.time:DEFAULT_GRID_SPACING:g.time+g.winlength)'),...
'XTick',[1:multiplier*DEFAULT_GRID_SPACING:g.winlength*multiplier+1])
end;
% ordinates: even if all elec are plotted, some may be hidden
set(ax1, 'ylim',[g.elecoffset*g.spacing (g.elecoffset+g.dispchans+1)*g.spacing] );
set(g.ax1, 'ylim',[g.elecoffset*g.spacing (g.elecoffset+g.dispchans+1)*g.spacing] );
axes(ax1)
axes(g.ax1)
case 'draws'
% Redraw EEG and change scale
......@@ -1622,7 +1627,7 @@ else
text_h=findobj('-regexp','tag','text_*');delete(text_h);
g = get(gcf,'UserData');
data = get(ax1, 'userdata');
data = get(g.ax1, 'userdata');
ESpacing = findobj('tag','ESpacing','parent',gcf); % ui handle
EPosition = findobj('tag','EPosition','parent',gcf); % ui handle
if g.trialstag(1) == -1
......@@ -1647,8 +1652,8 @@ else
% ---------------
set(ESpacing,'string',num2str(g.spacing,4))
set(gcf, 'userdata', g);
set(ax1,'YLim',[0 (g.chans+1)*g.spacing],'YTick',[0:g.spacing:g.chans*g.spacing])
set(ax1, 'ylim',[g.elecoffset*g.spacing (g.elecoffset+g.dispchans+1)*g.spacing] );
set(g.ax1,'YLim',[0 (g.chans+1)*g.spacing],'YTick',[0:g.spacing:g.chans*g.spacing])
set(g.ax1, 'ylim',[g.elecoffset*g.spacing (g.elecoffset+g.dispchans+1)*g.spacing] );
ve_eegplot('drawp', 0);
......@@ -1772,7 +1777,7 @@ else
end;
eyeaxes = findobj('tag','eyeaxes','parent',figh);
YLim = get(ax1, 'ylim');
YLim = get(g.ax1, 'ylim');
ESpacing = findobj('tag','ESpacing','parent',figh);
g.spacing= str2num(get(ESpacing,'string'));
......@@ -1825,10 +1830,10 @@ else
case 'zoom' % if zoom
fig = varargin{1};
tmpxlim = get(ax1, 'xlim');
tmpylim = get(ax1, 'ylim');
tmpxlim2 = get(ax0, 'xlim');
set(ax0, 'xlim', get(ax1, 'xlim'));
tmpxlim = get(g.ax1, 'xlim');
tmpylim = get(g.ax1, 'ylim');
tmpxlim2 = get(g.ax0, 'xlim');
set(g.ax0, 'xlim', get(g.ax1, 'xlim'));
g = get(fig,'UserData');
% deal with abscissa
......@@ -1924,7 +1929,7 @@ else
fig = varargin{1};
g = get(fig,'UserData');
tmppos = get(ax0, 'currentpoint');
tmppos = get(g.ax0, 'currentpoint');
if g.trialstag ~= -1,
lowlim = round(g.time*g.trialstag+1);
......@@ -1936,10 +1941,10 @@ else
set(fig,'UserData', g);
ve_eegplot('drawb');
else
etime = findobj('tag','Etime','parent',fig);
tmppos = get(ax1, 'currentpoint');
xlims=get(ax1,'XLim');
ylims=get(ax1,'YLim');
g.etime = findobj('tag','Etime','parent',fig);
tmppos = get(g.ax1, 'currentpoint');
xlims=get(g.ax1,'XLim');
ylims=get(g.ax1,'YLim');
global on_data_ax;
if (tmppos(1,1)>xlims(1)&&tmppos(1,1)<xlims(2))&& ...
(tmppos(1,2)>ylims(1)&&tmppos(1,2)<ylims(2))
......@@ -1958,8 +1963,8 @@ else
on_data_ax=1;
end
if g.trialstag ~= -1,
set(etime, 'string', num2str(mod(tmppos(1)+lowlim-1,g.trialstag)/g.trialstag*(g.limits(2)-g.limits(1)) + g.limits(1)));
else set(etime, 'string', num2str((tmppos(1)+lowlim-1)/g.srate)); % put g.time in the box
set(g.etime, 'string', num2str(mod(tmppos(1)+lowlim-1,g.trialstag)/g.trialstag*(g.limits(2)-g.limits(1)) + g.limits(1)));
else set(g.etime, 'string', num2str((tmppos(1)+lowlim-1)/g.srate)); % put g.time in the box
end;
if (tmppos(1,1)<xlims(1)||tmppos(1,1)>xlims(2))|| ...
(tmppos(1,2)<ylims(1)||tmppos(1,2)>ylims(2))
......@@ -1967,19 +1972,19 @@ else
end
tmpelec = round(tmppos(1,2) / g.spacing);
tmpelec = min(max(double(tmpelec), 1),g.chans);
labls = get(ax1, 'YtickLabel');
eelec = findobj('tag','Eelec','parent',fig); % put electrode in the box
labls = get(g.ax1, 'YtickLabel');
g.eelec = findobj('tag','Eelec','parent',fig); % put electrode in the box
if ~g.envelope
set(eelec, 'string', labls(tmpelec+1,:));
set(g.eelec, 'string', labls(tmpelec+1,:));
else
set(eelec, 'string', ' ');
set(g.eelec, 'string', ' ');
end
evalue = findobj('tag','Evalue','parent',fig);
g.evalue = findobj('tag','Evalue','parent',fig);
if ~g.envelope
eegplotdata = get(ax1, 'userdata');
set(evalue, 'string', num2str(eegplotdata(g.chans+1-tmpelec, min(g.frames,max(1,double(round(tmppos(1)+lowlim))))))); % put value in the box
eegplotdata = get(g.ax1, 'userdata');
set(g.evalue, 'string', num2str(eegplotdata(g.chans+1-tmpelec, min(g.frames,max(1,double(round(tmppos(1)+lowlim))))))); % put value in the box
else
set(evalue,'string',' ');
set(g.evalue,'string',' ');
end
end
end;
......@@ -1992,7 +1997,7 @@ else
if ~isstruct(g.eloc_file) || ~isfield(g.eloc_file, 'theta') || isempty( [ g.eloc_file.theta ])
return;
end;
tmppos = get(ax0, 'currentpoint');
tmppos = get(g.ax0, 'currentpoint');
% plot vertical line
yl = ylim;
......@@ -2002,7 +2007,7 @@ else
lowlim = round(g.time*g.trialstag+1);
else, lowlim = round(g.time*g.srate+1);
end;
data = get(ax1,'UserData');
data = get(g.ax1,'UserData');
datapos = max(1, round(tmppos(1)+lowlim));
datapos = min(datapos, g.frames);
......@@ -2066,7 +2071,7 @@ else
fig = varargin{1};
g = get(fig,'UserData');
tmppos = get(ax0, 'currentpoint');
tmppos = get(g.ax0, 'currentpoint');
if strcmp(get(fig, 'SelectionType'),'normal');
g = get(fig,'UserData'); % get data of backgroung image {g.trialstag g.winrej incallback}
if g.incallback ~= 1 % interception of nestest calls
......@@ -2084,7 +2089,7 @@ else
if any(Allwin) % remove the mark or select electrode if necessary
lowlim = find(Allwin==1);
if g.setelectrode % select electrode
tmppos = get(ax1, 'currentpoint');
tmppos = get(g.ax1, 'currentpoint');
tmpelec = g.chans + 1 - round(tmppos(1,2) / g.spacing);
tmpelec = min(max(tmpelec, 1), g.chans);
g.winrej(lowlim,tmpelec+5) = ~g.winrej(lowlim,tmpelec+5); % set the electrode
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment