www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mvgraph1d/set.m
function gr=set(gr,varargin) %SET SET interface for the Graph1D object. % Set interface for the graph1d object % Valid properties are: % 'Position' - 4 element position vector in pixels % 'Visible' - 'on' or 'off' % 'Data' - matrix of data with a column for each factor % 'Factors' - cell array of strings corresponding to each factor % 'Title' - set title on plot % 'Parent' - change parent figure (useful for saving a copy of graph) % 'Histogram' - 'on' or 'off' % 'Histogramcolor' - Change colour of bars on histogram: % 2*3 double for shaded bars from top to bottom, % 1*3 double for solid colour bars. % 'Callback' - Callback function called when factor is changed % % Plus a load of other HG properties that are visible by getting the handles. % Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. % Bail if we've not been given a graph1d object if ~isa(gr,'mvgraph1d') error(message('mbc:mvgraph1d:InvalidObject')) end % flags to signal a factorsort, graphlim, plot and histplot redraws=[0 0 0 0]; % loop over varargin for n=1:2:(nargin-2) drawreqs=[0 0 0 0]; switch lower(varargin{n}) case 'position' newpos = varargin{n+1}; set(gr.panel, 'Position', newpos); ud = get(gr.axes, 'UserData'); oldpos = ud.Position; ud.Position = newpos; set(gr.axes, 'UserData', ud); % Update position of items within the panel if required if any(oldpos(3:4)~=newpos(3:4)) [gr,drawreqs]=i_position(gr,newpos); end case 'visible' set(gr.panel, 'Visible', varargin{n+1}); case {'data','value','number'} [gr,drawreqs]=i_data(gr,varargin{n+1}); case 'factors' [gr,drawreqs]=i_factors(gr,varargin{n+1}); case 'title' set(get(gr.axes,'XLabel'),'String',varargin{n+1}); case 'parent' set(gr.panel,'Parent',varargin{n+1}); case 'histogram' [gr,drawreqs]=i_hist(gr,varargin{n+1}); case 'histogramcolor' [gr,drawreqs]=i_histcolor(gr,varargin{n+1}); case 'histogrambars' [gr,drawreqs]=i_histbars(gr,varargin{n+1}); case 'backgroundcolor' [gr,drawreqs]=i_backclr(gr,varargin{n+1}); case 'limits' [gr,drawreqs]=i_limits(gr,varargin{n+1}); case 'frame' [gr,drawreqs]=i_frame(gr,varargin{n+1}); case 'callback' ud = get(gr.axes, 'UserData'); ud.callback = varargin{n+1}; set(gr.axes, 'UserData', ud); case 'datatags' % 1D Graph does not support this property case 'customdatatags' % 1D Graph does not support this property end redraws= (redraws | drawreqs); end if redraws(1) pr_factorsort(gr); end if redraws(2) pr_graphlim(gr); end if redraws(3) pr_plot(gr); end if redraws(4) pr_histplot(gr); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% i_position - alter position of object in figure window %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [gr,drawreqs]=i_position(gr,newpos) ud = get(gr.axes, 'UserData'); % Adjust rectangle to account for the border width newpos(3:4) = newpos(3:4)-2; drawreqs=[0 0 0 0]; % if position is too small, display an image indicating this! mnsz=minsize(gr); if newpos(3)<mnsz(1) || newpos(4)<mnsz(2) % go to blackout mode % need to calc position of icon impos=[max(floor(newpos(3:4).*0.5)-15, [1 1]), min([32 32],newpos(3:4))]; impos = mbcgui.util.clipRect(impos); set([gr.axes;gr.line;gr.factorsel;gr.factortext;gr.hist.axes;gr.hist.patch],'Visible','off'); set(gr.badim, 'Position', impos, 'Visible', 'on'); else Yzero = 0; if ~ud.HistOptions.Show Yzero = newpos(4)/2-75; end % work out positions % axes set(gr.axes, 'Position', [30 Yzero+100 newpos(3)-60 5]); %ui's % text set(gr.factortext, 'Position', [(newpos(3)/2)-70 Yzero+30 70 16]); % popupmenu set(gr.factorsel, 'Position', [newpos(3)/2 Yzero+30 70 20]); if ud.HistOptions.Show % Histogram axes set(gr.hist.axes,'Position',[28 130 newpos(3)-56 newpos(4)-160]); drawreqs(4)=1; end set(gr.badim,'Visible','off'); % Set objects' visibility set([gr.axes;gr.line;gr.factorsel;gr.factortext],'Visible','on'); if ud.HistOptions.Show set([gr.hist.axes;gr.hist.patch],'Visible','on'); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% i_data - insert data into object %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [gr,drawreqs]=i_data(gr,data) % interesting one. Need to plot nth column of data if there are labels % defined and they don't go outside the defined data ud = get(gr.axes, 'UserData'); ud.Data = data; set(gr.axes, 'UserData', ud); drawreqs=[1 1 1 ud.HistOptions.Show]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% i_factors - insert factors into object %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [gr,drawreqs]=i_factors(gr,factors) ud = get(gr.axes, 'UserData'); ud.Labels = factors; set(gr.axes, 'UserData', ud) drawreqs=[1 0 1 ud.HistOptions.Show]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% i_hist - turn histogram on and off %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [gr,drawreqs]=i_hist(gr,status) ud = get(gr.axes, 'UserData'); % convert to 0/1 if strcmp(status,'on') status=true; elseif strcmp(status,'off') status=false; else return end drawreqs=[0 0 0 0]; if ud.HistOptions.Show==status return else ud.HistOptions.Show = status; set(gr.axes, 'UserData', ud); drawreqs(4) = status; % Need to reposition everything [gr req]=i_position(gr,ud.Position); drawreqs = (drawreqs | req); if ~status set([gr.hist.axes;gr.hist.patch],'Visible','off'); else set([gr.hist.axes;gr.hist.patch],'Visible',get(gr.axes, 'Visible')); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% i_histcolor - change color of histogram bar %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [gr,drawreqs]=i_histcolor(gr,col) % place color in patch userdata, update histogram if size(col,2)~=3 || size(col,1)>2 || ~isnumeric(col) return end ud=get(gr.axes,'UserData'); ud.HistOptions.Colours=col; set(gr.axes,'UserData',ud); drawreqs=[0 0 0 1]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% i_histbars - change number of histogram bar %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [gr,drawreqs]=i_histbars(gr,n) if ~isempty(n) if ischar(n) if strcmp(n,'auto') n=[]; else error(message('mbc:mvgraph1d:InvalidPropertyValue')); end elseif ~isnumeric(n) || n<0 || floor(n)~=n error(message('mbc:mvgraph1d:InvalidPropertyValue')); end end ud=get(gr.axes,'UserData'); ud.HistOptions.NumBars=n; set(gr.axes,'UserData',ud); drawreqs=[0 0 0 1]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% i_backclr - change background colour %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [gr,drawreqs]=i_backclr(gr,col) set(gr.panel,'BackgroundColor',col); set(gr.factortext,'BackgroundColor',col); % If the frame is off then we need to set the panel border to the same % colour ud=get(gr.axes,'UserData'); if ~ud.HistOptions.Frame set(gr.panel,'HighlightColor',col); end drawreqs=[0 0 0 0]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% i_limits - set explicit limits on the factors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function[ gr,drawreqs]=i_limits(gr,lim) if iscell(lim) ud = get(gr.axes, 'UserData'); ud.Limits = lim; set(gr.axes, 'UserData', ud); end drawreqs=[0 1 0 0]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% i_frame - turn bounding frame on/off %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function[ gr,drawreqs]=i_frame(gr,state) ud=get(gr.axes,'UserData'); if strcmp(state,'on') set(gr.panel,'HighlightColor','k'); ud.HistOptions.Frame = true; else set(gr.panel,'HighlightColor',get(gr.panel, 'BackgroundColor')); ud.HistOptions.Frame = false; end set(gr.axes,'UserData',ud); drawreqs=[0 0 0 0];