Changeset 14463


Ignore:
Timestamp:
03/21/13 10:58:38 (12 years ago)
Author:
Mathieu Morlighem
Message:

CHG: single patch if numticks=1, + centered text

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/plot/scaleruler.m

    r14343 r14463  
    66
    77%get options
    8 structure=getfieldvalue(options,'scaleruler');
    9 fontsize=getfieldvalue(options,'scaleruler_fontsize',16);
     8structure  = getfieldvalue(options,'scaleruler');
     9fontcolor  = getfieldvalue(options,'fontcolor','k');
     10fontweight = getfieldvalue(options,'fontweight','n');
     11fontsize   = getfieldvalue(options,'scaleruler_fontsize',16);
    1012
    1113%Go through structure and fill missing arguments
     
    1416end
    1517
    16 %retrieve north arrow parameters
    17 x0=structure(1);
    18 y0=structure(2);
    19 lengthscale=structure(3);
    20 widthscale=structure(4);
    21 numberofticks=structure(5);
    22 fontcolor=getfieldvalue(options,'fontcolor','k');
    23 fontweight=getfieldvalue(options,'fontweight','n');
     18%retrieve scale parameters
     19x0            = structure(1);
     20y0            = structure(2);
     21lengthscale   = structure(3);
     22widthscale    = structure(4);
     23numberofticks = structure(5);
    2424
    25 %initialize some coordinates
    26 unitlength=lengthscale/(numberofticks -1);
    27 flag=-1;
     25%If only one tick, just draw a rectangle
     26if numberofticks==1,
     27        text(x0+lengthscale/2,y0+2*widthscale,2,[num2str(lengthscale/1000) 'km'],...
     28                'FontSize',fontsize,'FontWeight',fontweight,'Color',fontcolor,'HorizontalAlignment','center','VerticalAlignment','baseline');
     29        patch([x0 x0+lengthscale x0+lengthscale x0],[y0 y0 y0+widthscale y0+widthscale],2*ones(1,4),fontcolor,'Edgecolor',fontcolor);
     30else
     31        %initialize some coordinates
     32        unitlength=lengthscale/(numberofticks -1);
     33        flag=-1;
    2834
    29 Bd=[x0 y0];
    30 Bu=[x0 y0+widthscale];
    31 Tick=0;
    32 
    33 %Text
    34 xt=Bu(1);
    35 yt=Bu(2)+widthscale;
    36 text(xt,yt,num2str(Tick),'FontSize',fontsize,'FontWeight',fontweight,'Color',fontcolor,'HorizontalAlignment','left','VerticalAlignment','baseline');
    37 
    38 %loope over the patches
    39 for i=1:numberofticks-1,
    40         Au=Bu;
    41         Ad=Bd;
    42         Bu=[Au(1)+unitlength Ad(2)+widthscale];
    43         Bd=[Ad(1)+unitlength Ad(2)];
    44         Tick=Tick+unitlength;
    45 
    46         %pathes
    47         if flag==-1
    48                 p=patch([Ad(1) Bd(1) Bu(1) Au(1)],[Ad(2) Bd(2) Bu(2) Au(2)],'Black','FaceAlpha',0.5);
    49         else
    50                 p=patch([Ad(1) Bd(1) Bu(1) Au(1)],[Ad(2) Bd(2) Bu(2) Au(2)],'White','FaceAlpha',0.3);
    51         end
    52 
    53         %flip flag
    54         flag=-flag;
     35        Bd=[x0 y0];
     36        Bu=[x0 y0+widthscale];
     37        Tick=0;
    5538
    5639        %Text
    5740        xt=Bu(1);
    5841        yt=Bu(2)+widthscale;
    59         if i~=numberofticks-1,
    60                 text(xt,yt,num2str(round_ice(Tick/1000,3)),'FontSize',fontsize,'FontWeight',fontweight,'Color',fontcolor,'HorizontalAlignment','left','VerticalAlignment','baseline');
     42        text(xt,yt,2,num2str(Tick),'FontSize',fontsize,'FontWeight',fontweight,'Color',fontcolor,'HorizontalAlignment','center','VerticalAlignment','baseline');
     43
     44        %loope over the patches
     45        for i=1:numberofticks-1,
     46                Au=Bu;
     47                Ad=Bd;
     48                Bu=[Au(1)+unitlength Ad(2)+widthscale];
     49                Bd=[Ad(1)+unitlength Ad(2)];
     50                Tick=Tick+unitlength;
     51
     52                %pathes
     53                if flag==-1
     54                        p=patch([Ad(1) Bd(1) Bu(1) Au(1)],[Ad(2) Bd(2) Bu(2) Au(2)],2*ones(1,4),'Black');
     55                else
     56                        p=patch([Ad(1) Bd(1) Bu(1) Au(1)],[Ad(2) Bd(2) Bu(2) Au(2)],2*ones(1,4),'White');
     57                end
     58
     59                %flip flag
     60                flag=-flag;
     61
     62                %Text
     63                xt=Bu(1);
     64                yt=Bu(2)+widthscale;
     65                if i~=numberofticks-1,
     66                        text(xt,yt,2,num2str(round_ice(Tick/1000,3)),'FontSize',fontsize,'FontWeight',fontweight,'Color',fontcolor,'HorizontalAlignment','center','VerticalAlignment','baseline');
     67                end
    6168        end
     69        text(xt,yt,2,[num2str(round_ice(Tick/1000,3)) ' km'],'FontSize',fontsize,'FontWeight',fontweight,'Color',fontcolor,'HorizontalAlignment','center','VerticalAlignment','baseline');
    6270end
    63 text(xt,yt,[num2str(round_ice(Tick/1000,3)) ' km'],'FontSize',fontsize,'FontWeight',fontweight,'Color',fontcolor,'HorizontalAlignment','left','VerticalAlignment','baseline');
Note: See TracChangeset for help on using the changeset viewer.