Changeset 690 for trunk/src/plot_field.m


Ignore:
Timestamp:
Sep 29, 2013, 1:19:30 PM (11 years ago)
Author:
sommeria
Message:

representation of ancillary data as table improved.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r688 r690  
    112112
    113113%% check input structure
    114 index_2D=[];
    115 index_1D=[];
    116 index_0D=[];
    117114% check the cells of fields :
    118115[CellInfo,NbDimArray,errormsg]=find_field_cells(Data);
    119 %[CellVarIndex,NbDim,CoordType,VarRole,errormsg]=find_field_cells(Data);
    120116if ~isempty(errormsg)
    121117    msgbox_uvmat('ERROR',['input of plot_field/find_field_cells: ' errormsg]);
     
    171167    set(haxes,'YLimMode', 'auto')
    172168end
    173 % if ~isfield(PlotParam.Coordinates,'CheckFixAspectRatio')&& isfield(Data,'CoordUnit')
    174 %     PlotParam.Coordinates.CheckFixAspectRatio=1;% if CoordUnit is defined, the two coordiantes should be plotted with equal scale by default
    175 % end
    176169errormsg='';
    177 %PlotParamOut.Coordinates=[]; %default output
    178170AxeData=get(haxes,'UserData');
    179171
     
    210202
    211203%% text display
    212 if isempty(index_2D) && isempty(index_1D)%text display alone
    213     htext=findobj(hfig,'Tag','TableDisplay');
    214 else  %text display added to plot
    215     htext=findobj(hfig,'Tag','text_display');
    216 end
    217 if ~isempty(htext)
     204
     205htext=findobj(hfig,'Tag','TableDisplay');
     206hchecktable=findobj(hfig,'Tag','CheckTable');
     207% if isempty(index_2D) && isempty(index_1D)%text display alone
     208%     htext=findobj(hfig,'Tag','TableDisplay');
     209% else  %text display added to plot
     210%     %htext=findobj(hfig,'Tag','text_display');
     211% end
     212if ~isempty(htext)&&~isempty(hchecktable)
    218213    if isempty(index_0D)
    219         if strcmp(get(htext,'Type'),'uitable')
    220             set(htext,'Data',{})
    221         else
    222             set(htext,'String',{''})
    223         end
     214        set(htext,'Data',{})
     215        set(htext,'visible','off')
     216        set(hchecktable,'visible','off')
     217        set(hchecktable,'Value',0)
    224218    else
    225         [errormsg]=plot_text(Data,CellInfo(index_0D),htext);
     219        errormsg=plot_text(Data,CellInfo(index_0D),htext);
     220        set(htext,'visible','on')
     221        set(hchecktable,'visible','on')
     222        set(hchecktable,'Value',1)
     223    end
     224    set(hfig,'Unit','pixels');
     225    set(htext,'Unit','pixels')
     226    PosFig=get(hfig,'Position');
     227    % case of no plot with view_field: only text display
     228    if strcmp(get(hfig,'Tag'),'view_field')
     229        if isempty(index_1D) && isempty(index_2D)% case of no plot: only text display
     230            set(haxes,'Visible','off')         
     231            PosTable=get(htext,'Position');
     232            set(hfig,'Position',[PosFig(1) PosFig(2)  PosTable(3) PosTable(4)])
     233        else
     234            set(haxes,'Visible','on')
     235            set(hfig,'Position',[PosFig(1) PosFig(2)  877 677])%default size for view_field
     236        end
    226237    end
    227238end
     
    252263
    253264%-------------------------------------------------------------------
     265% --- plot 0D fields: display data values without plot
     266%------------------------------------------------------------------
    254267function errormsg=plot_text(FieldData,CellInfo,htext)
    255 %-------------------------------------------------------------------
     268
    256269errormsg='';
    257270txt_cell={};
    258271Data={};
     272VarIndex=[];
    259273for icell=1:length(CellInfo)
    260274   
     
    267281        end
    268282    end
    269     VarIndex=find(check_proj);
    270     %
    271     %     VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list data.ListVarName
    272     %     for ivar=1:length(VarIndex)
    273     %         checkancillary=0;
    274     %         if length(FieldData.VarAttribute)>=VarIndex(ivar)
    275     %             VarAttribute=FieldData.VarAttribute{VarIndex(ivar)};
    276     %             if isfield(VarAttribute,'Role')&&(strcmp(VarAttribute.Role,'ancillary')||strcmp(VarAttribute.Role,'coord_tps')...
    277     %                     ||strcmp(VarAttribute.Role,'vector_x_tps')||strcmp(VarAttribute.Role,'vector_y_tps'))
    278     %                 checkancillary=1;
    279     %             end
    280     %         end
    281     %         if ~checkancillary% does not display variables with attribute '.Role=ancillary'
    282     for ivar=1:length(VarIndex)
    283     VarName=FieldData.ListVarName{VarIndex(ivar)};
    284     VarValue=FieldData.(VarName);
    285     if isvector(VarValue')
    286         VarValue=VarValue';% put the different values on a line
    287     end
    288     if numel(VarValue)>1 && numel(VarValue)<10
    289         for ind=1:numel(VarValue)
    290             VarNameCell{1,ind}=[VarName '_' num2str(ilist)];
    291         end
    292     else
    293         VarNameCell={VarName};
    294     end
    295     if numel(VarValue)<10
    296         if isempty(VarValue)
    297             VarValueCell={'[]'};
    298         else
    299             VarValueCell=num2cell(VarValue);
    300         end
    301         if isempty(Data)
    302             Data =[VarNameCell; VarValueCell];
    303         else
    304             Data =[Data [VarNameCell; VarValueCell]];
    305         end
    306     else
    307         if isempty(Data)
    308             Data =[VarNameCell; num2cell(VarValue)];
    309         else
    310         Data =[Data [VarNameCell; {['size ' num2str(size(VarValue))]}]];
    311         end
    312     end
    313     if size(VarValue,1)==1
    314         txt=[VarName '=' num2str(VarValue)];
    315         txt_cell=[txt_cell;{txt}];
    316     end
    317     end
    318 end
    319 if strcmp(get(htext,'Type'),'uitable')
    320     get(htext,'ColumnName')
    321     set(htext,'ColumnName',Data(1,:))
    322     set(htext,'Data',Data(2:end,:))
    323 else
    324     set(htext,'String',txt_cell)
    325     set(htext,'UserData',txt_cell)% for storage during mouse display
    326 end
    327 
    328 
     283    VarIndex=[VarIndex find(check_proj)];
     284end
     285
     286% data need to be displayed in a table
     287if strcmp(get(htext,'Type'),'uitable')% display data in a table
     288    VarNameCell=cell(1,numel(VarIndex));% prepare list of variable names to display (titles of columns)
     289    VarLength=zeros(1,numel(VarIndex));  % default number of values for each variable
     290    for ivar=1:numel(VarIndex)
     291        VarNameCell{ivar}=FieldData.ListVarName{VarIndex(ivar)};
     292        VarLength(ivar)=numel(FieldData.(VarNameCell{ivar}));
     293    end
     294    set(htext,'ColumnName',VarNameCell)
     295    Data=cell(max(VarLength),numel(VarIndex));% prepare the table of data display
     296   
     297    for ivar=1:numel(VarIndex)
     298        VarValue=FieldData.(VarNameCell{ivar});
     299        VarValue=reshape(VarValue,[],1);% reshape values array in a column
     300        Data(1:numel(VarValue),ivar)=num2cell(VarValue);
     301    end
     302    set(htext,'Data',Data)
     303end
     304%         if numel(VarValue)>1 && numel(VarValue)<10 % case of a variable with several values
     305%             for ind=1:numel(VarValue)
     306%                 VarNameCell{1,ind}=[VarName '_' num2str(ind)];% indicate each value by an index
     307%             end
     308%         else
     309%             VarNameCell={VarName};
     310%         end
     311%         if numel(VarValue)<10
     312%             if isempty(VarValue)
     313%                 VarValueCell={'[]'};
     314%             else
     315%                 VarValueCell=num2cell(VarValue);
     316%             end
     317%             if isempty(Data)
     318%                 Data =[VarNameCell VarValueCell];
     319%             else
     320%                 Data =[Data [VarNameCell VarValueCell]];
     321%             end
     322%         else
     323%             if isempty(Data)
     324%                 Data =[VarNameCell; num2cell(VarValue)];
     325%             else
     326%                 Data =[Data [VarNameCell; {['size ' num2str(size(VarValue))]}]];
     327%             end
     328%         end
     329%         if size(VarValue,1)==1
     330%             txt=[VarName '=' num2str(VarValue)];
     331%             txt_cell=[txt_cell;{txt}];
     332%         end
     333%     end
     334% end
     335% if strcmp(get(htext,'Type'),'uitable')% display data in a table
     336%
     337
     338%     set(htext,'Data',Data(2:end,:))
     339% else  % display in a text edit box
     340%     set(htext,'String',txt_cell)
     341%     set(htext,'UserData',txt_cell)% for temporary storage when the edit box is used for mouse display
     342% end
     343
     344
     345%-------------------------------------------------------------------
     346% --- plot 1D fields (usual x,y plots)
    329347%-------------------------------------------------------------------
    330348function CoordinatesOut=plot_profile(data,CellInfo,haxes,Coordinates,CheckHold)
    331 %-------------------------------------------------------------------
    332349
    333350%% initialization
     
    359376% end
    360377if CheckHold
    361      set(haxes,'NextPlot','add')
     378    set(haxes,'NextPlot','add')
    362379else
    363380    set(haxes,'NextPlot','replace')
     
    446463    end
    447464    if ~isempty(MinY)
    448     MinY_cell(icell)=min(MinY);
    449     MaxY_cell(icell)=max(MaxY);
     465        MinY_cell(icell)=min(MinY);
     466        MaxY_cell(icell)=max(MaxY);
    450467    end
    451468end
Note: See TracChangeset for help on using the changeset viewer.