Changeset 19782


Ignore:
Timestamp:
11/22/15 00:03:21 (9 years ago)
Author:
dlcheng
Message:

CHG:Adding colorbar support for test101.html

Location:
issm/trunk-jpl
Files:
3 edited

Legend:

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

    r19724 r19782  
    11function applyoptions(md,data,options){
    2 //APPLYOPTIONS - apply the options to current plot
    3 //
    4 //   Usage:
    5 //      applyoptions(md,data,options)
    6 //
    7 //   See also: PLOTMODEL, PARSE_OPTIONS
    8 
    9 //fontsize
    10 fontsize=options.getfieldvalue('fontsize',14);
    11 
    12 //fontweight
    13 fontweight=options.getfieldvalue('fontweight','normal');
    14 
    15 //title
    16 if exist(options,'title')
    17         titlevalue=options.getfieldvalue('title');
    18         if iscell(titlevalue),
    19                 title(titlevalue,'FontSize',fontsize,'FontWeight',fontweight);
     2        //APPLYOPTIONS - apply the options to current plot
     3        //
     4        //   Usage:
     5        //      applyoptions(md,data,options)
     6        //
     7        //   See also: PLOTMODEL, PARSE_OPTIONS
     8        /* //{{{
     9        //fontsize
     10        fontsize=options.getfieldvalue('fontsize',14);
     11
     12        //fontweight
     13        fontweight=options.getfieldvalue('fontweight','normal');
     14
     15        //title
     16        if exist(options,'title')
     17                titlevalue=options.getfieldvalue('title');
     18                if iscell(titlevalue),
     19                        title(titlevalue,'FontSize',fontsize,'FontWeight',fontweight);
     20                else
     21                        if ~isnan(titlevalue),
     22                                title(titlevalue,'FontSize',fontsize,'FontWeight',fontweight);
     23                        end
     24                end
     25        end
     26
     27        //xlabel, ylabel and zlabel
     28        if exist(options,'xlabel');
     29                xlabel(options.getfieldvalue('xlabel'),'FontSize',fontsize,'FontWeight',fontweight);
     30        end
     31        if exist(options,'ylabel');
     32                ylabel(options.getfieldvalue('ylabel'),'FontSize',fontsize,'FontWeight',fontweight);
     33        end
     34        if exist(options,'zlabel');
     35                zlabel(options.getfieldvalue('zlabel'),'FontSize',fontsize,'FontWeight',fontweight);
     36        end
     37
     38        //xticks, yticks and zticks
     39        if exist(options,'xtick'), set(gca,'XTick',options.getfieldvalue('xtick')); end
     40        if exist(options,'ytick'), set(gca,'YTick',options.getfieldvalue('ytick')); end
     41        if exist(options,'ztick'), set(gca,'ZTick',options.getfieldvalue('ztick')); end
     42
     43        //view
     44        if dimension(md.mesh)==3 & ~exist(options,'layer'),
     45                view(options.getfieldvalue('view',3));
    2046        else
    21                 if ~isnan(titlevalue),
    22                         title(titlevalue,'FontSize',fontsize,'FontWeight',fontweight);
    23                 end
    24         end
    25 end
    26 
    27 //xlabel, ylabel and zlabel
    28 if exist(options,'xlabel');
    29         xlabel(options.getfieldvalue('xlabel'),'FontSize',fontsize,'FontWeight',fontweight);
    30 end
    31 if exist(options,'ylabel');
    32         ylabel(options.getfieldvalue('ylabel'),'FontSize',fontsize,'FontWeight',fontweight);
    33 end
    34 if exist(options,'zlabel');
    35         zlabel(options.getfieldvalue('zlabel'),'FontSize',fontsize,'FontWeight',fontweight);
    36 end
    37 
    38 //xticks, yticks and zticks
    39 if exist(options,'xtick'), set(gca,'XTick',options.getfieldvalue('xtick')); end
    40 if exist(options,'ytick'), set(gca,'YTick',options.getfieldvalue('ytick')); end
    41 if exist(options,'ztick'), set(gca,'ZTick',options.getfieldvalue('ztick')); end
    42 
    43 //view
    44 if dimension(md.mesh)==3 & ~exist(options,'layer'),
    45         view(options.getfieldvalue('view',3));
    46 else
    47         view(options.getfieldvalue('view',2));
    48 end
    49 
    50 //axis
    51 set(gca,'FontSize',options.getfieldvalue('axisfontsize',fontsize));;
    52 if exist(options,'axis')
    53         eval(['axis ' options.getfieldvalue('axis')]);
    54 else
    55         if strcmp(domaintype(md.mesh),'3D'),
    56                 if ~exist(options,'layer'),
     47                view(options.getfieldvalue('view',2));
     48        end
     49
     50        //axis
     51        set(gca,'FontSize',options.getfieldvalue('axisfontsize',fontsize));;
     52        if exist(options,'axis')
     53                eval(['axis ' options.getfieldvalue('axis')]);
     54        else
     55                if strcmp(domaintype(md.mesh),'3D'),
     56                        if ~exist(options,'layer'),
     57                                axis auto tight
     58                        else
     59                                axis tight equal
     60                        end
     61                elseif strcmp(domaintype(md.mesh),'2Dvertical'),
    5762                        axis auto tight
     63                elseif strcmp(domaintype(md.mesh),'3Dsurface'),
     64                        axis auto tight
     65
     66                elseif strcmp(domaintype(md.mesh),'2Dhorizontal'),
     67                        axis tight equal;
    5868                else
    59                         axis tight equal
    60                 end
    61         elseif strcmp(domaintype(md.mesh),'2Dvertical'),
    62                 axis auto tight
    63         elseif strcmp(domaintype(md.mesh),'3Dsurface'),
    64                 axis auto tight
    65 
    66         elseif strcmp(domaintype(md.mesh),'2Dhorizontal'),
    67                 axis tight equal;
    68         else
    69                 error('type of domain not supported');
    70         end
    71 end
    72 
    73 //box
    74 if exist(options,'box')
    75         eval(['box ' options.getfieldvalue('box')]);
    76 end
    77 
    78 //xlim, ylim and zlim
    79 if exist(options,'xlim');
    80         xlim(options.getfieldvalue('xlim'));
    81 end
    82 if exist(options,'ylim');
    83         ylim(options.getfieldvalue('ylim'));
    84 end
    85 if exist(options,'zlim');
    86         zlim(options.getfieldvalue('zlim'));
    87 end
    88 
    89 //latlon
    90 //Must be done here (before xlim and ylim??) so that it uses the same xlim and ylim as plot_overlay
    91 //these are changed by axis that follows
    92 if ~strcmpi(options.getfieldvalue('latlon','off'),'off')
    93         latlonoverlay(md,options);
    94 end
    95 
    96 //Basinzoom
    97 if exist(options,'basin');
    98         basinzoom(options);
    99 end
    100 
    101 //ShowBasins
    102 if strcmpi(options.getfieldvalue('showbasins','off'),'on')
    103         showbasins(options);
    104 end
    105 
    106 //Caxis
    107 if exist(options,'caxis'),
    108         caxis(options.getfieldvalue('caxis'));
    109 end
    110 
    111 //shading
    112 if exist(options,'shading'),
    113         shading(options.getfieldvalue('shading'));
    114 end
    115 
    116 //grid
    117 if exist(options,'grid'),
    118         if strcmpi(options.getfieldvalue('grid'),'on'),
    119                 grid on;
    120         end
    121 end
    122 
    123 //colormap
    124 c = getcolormap(options);
    125 h = colormap(c);
    126 
    127 //wrapping
    128 if exist(options,'wrapping'),
    129         if ~exist(options,'colormap'),
    130                 h=jet;
    131         end
    132         colormap(repmat(h,options.getfieldvalue('wrapping',1),1));
    133 end
    134 
    135 //colorbar
    136 if options.getfieldvalue('colorbar',1)==1,
    137         if exist(options,'colorbarcornerposition'),
    138                 c=colorbar(options.getfieldvalue('colorbarcornerposition'),'peer',gca);
    139         else
    140                 c=colorbar('peer',gca);
    141         end
    142         set(c,'FontSize',options.getfieldvalue('colorbarfontsize',fontsize),'YColor',options.getfieldvalue('FontColor','k'));
    143         if exist(options,'wrapping')
    144                 lim=get(c,'Ylim');
    145                 lim=[lim(1) lim(1)+(lim(2)-lim(1))/options.getfieldvalue('wrapping')];
    146                 set(c,'Ylim',lim);
    147         end
    148         if exist(options,'colorbarpos'),
    149                 set(c,'Position',options.getfieldvalue('colorbarpos'));
    150         end
    151         if exist(options,'log'),
    152                 nlab=length(get(c,'YTick'));
    153                 logvalue=options.getfieldvalue('log');
    154 
    155                 scaleminmax=caxis;
    156                 Min=min(scaleminmax);
    157                 Max=max(scaleminmax);
    158                 set(c,'YLim',[Min Max]); // set colorbar limits
    159                 set(c,'YTick',linspace(Min,Max,nlab));     // set tick mark locations
    160 
    161                 labels = cell(1,nlab);
    162                 tick_vals = linspace(Min,Max,nlab);
    163                 tick_vals = exp(log(logvalue)*tick_vals);
    164                 warning off MATLAB:log:logOfZero;
    165                 for i = 1:nlab
    166                         labels{i} = sprintf('//-3.4g',round_ice(tick_vals(i),2));
    167                         //labels{i} = sprintf('//-.4g',round_ice(tick_vals(i),2));
    168                 end
    169                 warning on MATLAB:log:logOfZero;
    170                 set(c,'YTickLabel',labels);
    171         end
    172         if exist(options,'cbYLim');
    173                 set(c,'YLim',options.getfieldvalue('cbYLim'));
    174         end
    175         if exist(options,'colorbartitle'),
    176                 set(get(c,'title'),'FontSize',options.getfieldvalue('colorbarfontsize',fontsize),'String',options.getfieldvalue('colorbartitle'),...
    177                         'Color',options.getfieldvalue('FontColor','k'));
    178         end
    179         if exist(options,'colorbarYLabel'),
    180                 set(get(c,'Ylabel'),'FontSize',options.getfieldvalue('colorbarfontsize',fontsize),'String',options.getfieldvalue('colorbarYLabel'),...
    181                         'Color',options.getfieldvalue('FontColor','k'));
    182         end
    183         if exist(options,'colorbarwidth'),
    184                 posaxes=get(gca,'Position');
    185                 alpha=options.getfieldvalue('colorbarwidth',1);
    186                 position=get(c,'Position');
    187                 dx=position(3);
    188                 newdx=dx*alpha;
    189                 position(1)=position(1)+(dx-newdx)/2;
    190                 position(3)=newdx;
    191                 set(c,'Position',position);
    192                 set(gca,'Position',posaxes);
    193         end
    194         if exist(options,'colorbarheight'),
    195                 posaxes=get(gca,'Position');
    196                 alpha=options.getfieldvalue('colorbarheight',1);
    197                 position=get(c,'Position');
    198                 dy=position(4);
    199                 newdy=dy*alpha;
    200                 position(2)=position(2)+(dy-newdy)/2;
    201                 position(4)=newdy;
    202                 set(c,'Position',position);
    203                 set(gca,'Position',posaxes);
    204         end
    205         if exist(options,'cbYTickLabel');
    206                 tick_vals=options.getfieldvalue('cbYTickLabel');
    207                 if ~isnumeric(tick_vals) & strcmp(tick_vals,'on')
    208                         tick_vals=get(c,'YTick')';
    209                         if exist(options,'log')
    210                                 logval= options.getfieldvalue('log');
    211                                 for i= 1:numel(tick_vals)
    212                                         tick_vals(i)= logval^(tick_vals(i));
    213                                 end
    214                         elseif numel(tick_vals) == 3
    215                                 tick_vals=[tick_vals(1); mean(tick_vals(1:2)); tick_vals(2); ...
    216                                         mean(tick_vals(2:3)); tick_vals(3)];
    217                                 set(c,'YTick',tick_vals);
    218                         end
     69                        error('type of domain not supported');
     70                end
     71        end
     72
     73        //box
     74        if exist(options,'box')
     75                eval(['box ' options.getfieldvalue('box')]);
     76        end
     77
     78        //xlim, ylim and zlim
     79        if exist(options,'xlim');
     80                xlim(options.getfieldvalue('xlim'));
     81        end
     82        if exist(options,'ylim');
     83                ylim(options.getfieldvalue('ylim'));
     84        end
     85        if exist(options,'zlim');
     86                zlim(options.getfieldvalue('zlim'));
     87        end
     88
     89        //latlon
     90        //Must be done here (before xlim and ylim??) so that it uses the same xlim and ylim as plot_overlay
     91        //these are changed by axis that follows
     92        if ~strcmpi(options.getfieldvalue('latlon','off'),'off')
     93                latlonoverlay(md,options);
     94        end
     95
     96        //Basinzoom
     97        if exist(options,'basin');
     98                basinzoom(options);
     99        end
     100
     101        //ShowBasins
     102        if strcmpi(options.getfieldvalue('showbasins','off'),'on')
     103                showbasins(options);
     104        end
     105        */ //}}}
     106        //Caxis
     107        if (options.exist('caxis')) {
     108                caxis(options.getfieldvalue('caxis'));
     109        }
     110        /* ///{{{
     111        //shading
     112        if exist(options,'shading'),
     113                shading(options.getfieldvalue('shading'));
     114        end
     115
     116        //grid
     117        if exist(options,'grid'),
     118                if strcmpi(options.getfieldvalue('grid'),'on'),
     119                        grid on;
     120                end
     121        end
     122
     123        //colormap
     124        c = getcolormap(options);
     125        h = colormap(c);
     126
     127        //wrapping
     128        if exist(options,'wrapping'),
     129                if ~exist(options,'colormap'),
     130                        h=jet;
     131                end
     132                colormap(repmat(h,options.getfieldvalue('wrapping',1),1));
     133        end
     134        */ //}}}
     135        //colorbar
     136        if (options.exist('colorbar')) {
     137                if (options.getfieldvalue('colorbar')==1) {
     138                        if (options.exist('colorbarcornerposition')) {
     139                                //c=colorbar(options.getfieldvalue('colorbarcornerposition'),'peer',gca);
     140                        } else {
     141                                var cheight = options.getfieldvalue('colorbarheight',options.getfieldvalue('canvassize',480));
     142                                var cwidth = options.getfieldvalue('colorbarwidth',options.getfieldvalue('canvassize',480)/20);
     143                                var cdivisions = cheight/4;
     144                                var color;
     145                                var ccanvas = $('<canvas id="'+options.getfieldvalue('canvasid')+'-colorbar" width="'+cwidth+'" height="'+cheight+'"></canvas>').insertAfter("#"+options.getfieldvalue('canvasid'));
     146                                ccanvas.css({"vertical-align":"top","margin":"0px "+String(cwidth/4)+"px 0px "+String(cwidth/4)+"px"});
     147                                var ccontext = ccanvas[0].getContext('2d');
     148                                for (var i = 0; i < cdivisions; i++) {
     149                                        var cindex= Math.floor(i / cdivisions * (colorbar.length - 1));
     150                                        color = colorbar[(colorbar.length - 1) - cindex];
     151                                        color = [Math.round(color[0] * 255), Math.round(color[1] * 255), Math.round(color[2] * 255)];   
     152                                        ccontext.fillStyle = "rgba(" + color.toString() + ",1.0)";
     153                                        ccontext.fillRect(0, Math.floor(i * cheight / cdivisions), cwidth, Math.ceil(cheight / cdivisions));
     154                                }
     155                        }
     156                        /* //{{{
     157                        set(c,'FontSize',options.getfieldvalue('colorbarfontsize',fontsize),'YColor',options.getfieldvalue('FontColor','k'));
     158                        if exist(options,'wrapping')
     159                                lim=get(c,'Ylim');
     160                                lim=[lim(1) lim(1)+(lim(2)-lim(1))/options.getfieldvalue('wrapping')];
     161                                set(c,'Ylim',lim);
     162                        }
     163                        if exist(options,'colorbarpos'),
     164                                set(c,'Position',options.getfieldvalue('colorbarpos'));
     165                        }
     166                        if exist(options,'log'),
     167                                nlab=length(get(c,'YTick'));
     168                                logvalue=options.getfieldvalue('log');
     169
     170                                scaleminmax=caxis;
     171                                Min=min(scaleminmax);
     172                                Max=max(scaleminmax);
     173                                set(c,'YLim',[Min Max]); // set colorbar limits
     174                                set(c,'YTick',linspace(Min,Max,nlab));     // set tick mark locations
     175
     176                                labels = cell(1,nlab);
     177                                tick_vals = linspace(Min,Max,nlab);
     178                                tick_vals = exp(log(logvalue)*tick_vals);
     179                                warning off MATLAB:log:logOfZero;
     180                                for i = 1:nlab
     181                                        labels{i} = sprintf('//-3.4g',round_ice(tick_vals(i),2));
     182                                        //labels{i} = sprintf('//-.4g',round_ice(tick_vals(i),2));
     183                                }
     184                                warning on MATLAB:log:logOfZero;
     185                                set(c,'YTickLabel',labels);
     186                        }
     187                        if exist(options,'cbYLim');
     188                                set(c,'YLim',options.getfieldvalue('cbYLim'));
     189                        }
     190                        if exist(options,'colorbartitle'),
     191                                set(get(c,'title'),'FontSize',options.getfieldvalue('colorbarfontsize',fontsize),'String',options.getfieldvalue('colorbartitle'),...
     192                                        'Color',options.getfieldvalue('FontColor','k'));
     193                        }
     194                        if exist(options,'colorbarYLabel'),
     195                                set(get(c,'Ylabel'),'FontSize',options.getfieldvalue('colorbarfontsize',fontsize),'String',options.getfieldvalue('colorbarYLabel'),...
     196                                        'Color',options.getfieldvalue('FontColor','k'));
     197                        }
     198                        if exist(options,'colorbarwidth'),
     199                                posaxes=get(gca,'Position');
     200                                alpha=options.getfieldvalue('colorbarwidth',1);
     201                                position=get(c,'Position');
     202                                dx=position(3);
     203                                newdx=dx*alpha;
     204                                position(1)=position(1)+(dx-newdx)/2;
     205                                position(3)=newdx;
     206                                set(c,'Position',position);
     207                                set(gca,'Position',posaxes);
     208                        }
     209                        if exist(options,'colorbarheight'),
     210                                posaxes=get(gca,'Position');
     211                                alpha=options.getfieldvalue('colorbarheight',1);
     212                                position=get(c,'Position');
     213                                dy=position(4);
     214                                newdy=dy*alpha;
     215                                position(2)=position(2)+(dy-newdy)/2;
     216                                position(4)=newdy;
     217                                set(c,'Position',position);
     218                                set(gca,'Position',posaxes);
     219                        }
     220                        if exist(options,'cbYTickLabel');
     221                                tick_vals=options.getfieldvalue('cbYTickLabel');
     222                                if ~isnumeric(tick_vals) & strcmp(tick_vals,'on')
     223                                        tick_vals=get(c,'YTick')';
     224                                        if exist(options,'log')
     225                                                logval= options.getfieldvalue('log');
     226                                                for i= 1:numel(tick_vals)
     227                                                        tick_vals(i)= logval^(tick_vals(i));
     228                                                }
     229                                        elseif numel(tick_vals) == 3
     230                                                tick_vals=[tick_vals(1); mean(tick_vals(1:2)); tick_vals(2); ...
     231                                                        mean(tick_vals(2:3)); tick_vals(3)];
     232                                                set(c,'YTick',tick_vals);
     233                                        }
     234                                else
     235                                        if exist(options,'log')
     236                                                logvalue=options.getfieldvalue('log');
     237                                                set(c,'YTick',log(tick_vals)./log(logvalue));
     238                                        else
     239                                                set(c,'YTick',tick_vals);
     240                                        }
     241                                }
     242                                labels = cell(1,numel(tick_vals));
     243                                for i = 1:numel(tick_vals)
     244                                        labels{i} = num2str(tick_vals(i));
     245                                }
     246                                set(c,'YTickLabel',labels);
     247                        }
     248                        */ //}}}
     249                }
     250        } else {
     251                //do nothing
     252
     253        }
     254        /* //{{{
     255        //area
     256        if exist(options,'area'),
     257                antzoom(options.getfieldvalue('area'));
     258        end
     259
     260        //expdisp
     261        if exist(options,'expdisp'),
     262                filename=(options.getfieldvalue('expdisp'));
     263                style=(options.getfieldvalue('expstyle'));
     264                linewidth=(options.getfieldvalue('linewidth',1));
     265                for i=1:length(options.getfieldvalue('expdisp')),
     266                        filenamei=filename{i};
     267                        stylei=style{i};
     268                        if length(linewidth)==1,
     269                                linewidthi=linewidth;
     270                        else
     271                                linewidthi=linewidth{i};
     272                        end
     273                        expdisp(filenamei,'linestyle',stylei,'linewidthi',linewidthi,'multiplier',options.getfieldvalue('unit',1));
     274                end
     275        end
     276
     277        //text (default value is empty, not NaN...)
     278        if exist(options,'text');
     279                textstring=options.getfieldvalue('text');
     280                textweight=options.getfieldvalue('textweight','b');
     281                textsize=options.getfieldvalue('textsize');
     282                textcolor=options.getfieldvalue('textcolor');
     283                textposition=options.getfieldvalue('textposition');
     284                textrotation=options.getfieldvalue('textrotation');
     285                for i=1:length(options.getfieldvalue('text'));
     286                        textstringi=textstring{i};
     287                        textweighti=textweight{i};
     288                        textsizei=textsize{i};
     289                        textcolori=textcolor{i};
     290                        textpositioni=textposition{i};
     291                        textrotationi=textrotation{i};
     292                        h=text(textpositioni(1),textpositioni(2),10,textstringi,'FontSize',textsizei,'FontWeight',textweighti,'Color',textcolori,'Rotation',textrotationi);
     293                        set(h,'Clipping','on'); //prevent text from appearing outside of the box
     294                end
     295        end
     296
     297        //north arrow
     298        if exist(options,'northarrow'),
     299                northarrow(options.getfieldvalue('northarrow'));
     300        end
     301
     302        //curved arrow
     303        if exist(options,'curvedarrow'),
     304                curvedoptions=options.getfieldvalue('curvedarrow');
     305                curvedarrow(curvedoptions{:});
     306        end
     307
     308        //Scale ruler
     309        if exist(options,'scaleruler'),
     310                scaleruler(options);
     311        end
     312
     313        //streamliness
     314        if exist(options,'streamlines'),
     315                plot_streamlines(md,options);
     316        end
     317
     318        //contours
     319        if exist(options,'contourlevels'),
     320                plot_contour(md,data,options);
     321        end
     322
     323        //YTickLabel
     324        if exist(options,'yticklabel'),
     325                set(gca,'YTickLabel',options.getfieldvalue('YTickLabel'));
     326        end
     327
     328        //XTickLabel
     329        if exist(options,'xticklabel'),
     330                set(gca,'XTickLabel',options.getfieldvalue('XTickLabel'));
     331        end
     332
     333        //xtick
     334        if exist(options,'xtick'),
     335                set(gca,'xtick',options.getfieldvalue('xtick'));
     336        end
     337
     338        //ytick
     339        if exist(options,'ytick'),
     340                set(gca,'ytick',options.getfieldvalue('ytick'));
     341        end
     342
     343        //Axis positions
     344        if exist(options,'offsetaxispos'),
     345                offset=options.getfieldvalue('offsetaxispos');
     346                P=get(gca,'pos');
     347                P(1)=P(1)+offset(1);
     348                P(2)=P(2)+offset(2);
     349                P(3)=P(3)+offset(3);
     350                P(3)=P(4)+offset(4);
     351                set(gca,'pos',P);
     352        end
     353        if exist(options,'axispos'),
     354                Axis=options.getfieldvalue('axispos');
     355                hold on
     356                set(gca,'pos',Axis);
     357        end
     358
     359        //axes position
     360        if exist(options,'axesPosition')
     361                set(gca,'Position',options.getfieldvalue('axesPosition'));
     362        end
     363
     364        //showregion
     365        if strcmpi(options.getfieldvalue('showregion','off'),'on'),
     366                //Keep pointer of main axis
     367                maingca=gca;
     368                //get inset relative position (x,y,width,height)
     369                insetpos=options.getfieldvalue('insetpos',[0.02 0.70 0.18 0.18]);
     370                //get current plos position
     371                cplotpos=get(maingca,'pos');
     372                //compute inset position
     373                PosInset=[cplotpos(1)+insetpos(1)*cplotpos(3),cplotpos(2)+insetpos(2)*cplotpos(4), insetpos(3)*cplotpos(3), insetpos(4)*cplotpos(4)];
     374                axes('pos',PosInset);
     375                axis equal off
     376                //box off
     377                if md.mesh.epsg==3413,
     378                        A=expread('/u/astrid-r1b/ModelData/Exp/GreenlandBoxFront.exp');
     379                        [A.x A.y]=ll2xy(A.x,A.y,+1,45,70);
     380                        A.x = A.x(1:30:end);
     381                        A.y = A.y(1:30:end);
     382                elseif md.mesh.epsg==3031,
     383                        A=expread('/u/astrid-r1b/ModelData/Exp/Antarctica.exp');
    219384                else
    220                         if exist(options,'log')
    221                                 logvalue=options.getfieldvalue('log');
    222                                 set(c,'YTick',log(tick_vals)./log(logvalue));
    223                         else
    224                                 set(c,'YTick',tick_vals);
    225                         end
    226                 end
    227                 labels = cell(1,numel(tick_vals));
    228                 for i = 1:numel(tick_vals)
    229                         labels{i} = num2str(tick_vals(i));
    230                 end
    231                 set(c,'YTickLabel',labels);
    232         end
    233 
    234 elseif options.getfieldvalue('colorbar',1)==0,
    235         colorbar('off');
    236 else
    237         //do nothing
    238 
    239 end
    240 
    241 //area
    242 if exist(options,'area'),
    243         antzoom(options.getfieldvalue('area'));
    244 end
    245 
    246 //expdisp
    247 if exist(options,'expdisp'),
    248         filename=(options.getfieldvalue('expdisp'));
    249         style=(options.getfieldvalue('expstyle'));
    250         linewidth=(options.getfieldvalue('linewidth',1));
    251         for i=1:length(options.getfieldvalue('expdisp')),
    252                 filenamei=filename{i};
    253                 stylei=style{i};
    254                 if length(linewidth)==1,
    255                         linewidthi=linewidth;
     385                        error('applyoptions error message: md.mesh.epsg not defined');
     386                end
     387                offset=3*10^4;
     388                Ax=[min(A.x)-offset max(A.x)+offset];
     389                Ay=[min(A.y)-offset max(A.y)+offset];
     390                //if we are zooming on a basin, don't take the mesh for the boundaries!
     391                if exist(options,'basin'),
     392                        [mdx mdy]=basinzoom(options);
    256393                else
    257                         linewidthi=linewidth{i};
    258                 end
    259                 expdisp(filenamei,'linestyle',stylei,'linewidthi',linewidthi,'multiplier',options.getfieldvalue('unit',1));
    260         end
    261 end
    262 
    263 //text (default value is empty, not NaN...)
    264 if exist(options,'text');
    265         textstring=options.getfieldvalue('text');
    266         textweight=options.getfieldvalue('textweight','b');
    267         textsize=options.getfieldvalue('textsize');
    268         textcolor=options.getfieldvalue('textcolor');
    269         textposition=options.getfieldvalue('textposition');
    270         textrotation=options.getfieldvalue('textrotation');
    271         for i=1:length(options.getfieldvalue('text'));
    272                 textstringi=textstring{i};
    273                 textweighti=textweight{i};
    274                 textsizei=textsize{i};
    275                 textcolori=textcolor{i};
    276                 textpositioni=textposition{i};
    277                 textrotationi=textrotation{i};
    278                 h=text(textpositioni(1),textpositioni(2),10,textstringi,'FontSize',textsizei,'FontWeight',textweighti,'Color',textcolori,'Rotation',textrotationi);
    279                 set(h,'Clipping','on'); //prevent text from appearing outside of the box
    280         end
    281 end
    282 
    283 //north arrow
    284 if exist(options,'northarrow'),
    285         northarrow(options.getfieldvalue('northarrow'));
    286 end
    287 
    288 //curved arrow
    289 if exist(options,'curvedarrow'),
    290         curvedoptions=options.getfieldvalue('curvedarrow');
    291         curvedarrow(curvedoptions{:});
    292 end
    293 
    294 //Scale ruler
    295 if exist(options,'scaleruler'),
    296         scaleruler(options);
    297 end
    298 
    299 //streamliness
    300 if exist(options,'streamlines'),
    301         plot_streamlines(md,options);
    302 end
    303 
    304 //contours
    305 if exist(options,'contourlevels'),
    306         plot_contour(md,data,options);
    307 end
    308 
    309 //YTickLabel
    310 if exist(options,'yticklabel'),
    311         set(gca,'YTickLabel',options.getfieldvalue('YTickLabel'));
    312 end
    313 
    314 //XTickLabel
    315 if exist(options,'xticklabel'),
    316         set(gca,'XTickLabel',options.getfieldvalue('XTickLabel'));
    317 end
    318 
    319 //xtick
    320 if exist(options,'xtick'),
    321         set(gca,'xtick',options.getfieldvalue('xtick'));
    322 end
    323 
    324 //ytick
    325 if exist(options,'ytick'),
    326         set(gca,'ytick',options.getfieldvalue('ytick'));
    327 end
    328 
    329 //Axis positions
    330 if exist(options,'offsetaxispos'),
    331         offset=options.getfieldvalue('offsetaxispos');
    332         P=get(gca,'pos');
    333         P(1)=P(1)+offset(1);
    334         P(2)=P(2)+offset(2);
    335         P(3)=P(3)+offset(3);
    336         P(3)=P(4)+offset(4);
    337         set(gca,'pos',P);
    338 end
    339 if exist(options,'axispos'),
    340         Axis=options.getfieldvalue('axispos');
    341         hold on
    342         set(gca,'pos',Axis);
    343 end
    344 
    345 //axes position
    346 if exist(options,'axesPosition')
    347         set(gca,'Position',options.getfieldvalue('axesPosition'));
    348 end
    349 
    350 //showregion
    351 if strcmpi(options.getfieldvalue('showregion','off'),'on'),
    352         //Keep pointer of main axis
    353         maingca=gca;
    354         //get inset relative position (x,y,width,height)
    355         insetpos=options.getfieldvalue('insetpos',[0.02 0.70 0.18 0.18]);
    356         //get current plos position
    357         cplotpos=get(maingca,'pos');
    358         //compute inset position
    359         PosInset=[cplotpos(1)+insetpos(1)*cplotpos(3),cplotpos(2)+insetpos(2)*cplotpos(4), insetpos(3)*cplotpos(3), insetpos(4)*cplotpos(4)];
    360         axes('pos',PosInset);
    361         axis equal off
    362         //box off
    363         if md.mesh.epsg==3413,
    364                 A=expread('/u/astrid-r1b/ModelData/Exp/GreenlandBoxFront.exp');
    365                 [A.x A.y]=ll2xy(A.x,A.y,+1,45,70);
    366                 A.x = A.x(1:30:end);
    367                 A.y = A.y(1:30:end);
    368         elseif md.mesh.epsg==3031,
    369                 A=expread('/u/astrid-r1b/ModelData/Exp/Antarctica.exp');
    370         else
    371                 error('applyoptions error message: md.mesh.epsg not defined');
    372         end
    373         offset=3*10^4;
    374         Ax=[min(A.x)-offset max(A.x)+offset];
    375         Ay=[min(A.y)-offset max(A.y)+offset];
    376         //if we are zooming on a basin, don't take the mesh for the boundaries!
    377         if exist(options,'basin'),
    378                 [mdx mdy]=basinzoom(options);
    379         else
    380                 mdx=[min(md.mesh.x)-offset max(md.mesh.x)+offset];
    381                 mdy=[min(md.mesh.y)-offset max(md.mesh.y)+offset];
    382         end
    383         line(A.x,A.y,ones(size(A.x)),'color','b');
    384         patch([Ax(1)  Ax(2)  Ax(2)  Ax(1) Ax(1)],[Ay(1)  Ay(1)  Ay(2)  Ay(2) Ay(1)],[1 1 1],'EdgeColor',[0 0 0],'LineWidth',1,'FaceLighting','none')
    385         patch([mdx(1) mdx(2) mdx(2) mdx(1)],[mdy(1) mdy(1) mdy(2) mdy(2)],ones(4,1),'EdgeColor',[0 0 0],'FaceColor','r','FaceAlpha',0.5)
    386         colorbar('off');
    387         //back to main gca
    388         set(gcf,'CurrentAxes',maingca)
    389 end
    390 
    391 //flag edges of a partition
    392 if exist(options,'partitionedges')
    393         [xsegments ysegments]=flagedges(md.mesh.elements,md.mesh.x,md.mesh.y,md.qmu.partition);
    394         xsegments=xsegments*options.getfieldvalue('unit',1);
    395         ysegments=ysegments*options.getfieldvalue('unit',1);
    396         color=options.getfieldvalue('partitionedgescolor','r-');
    397         linewidth=options.getfieldvalue('linewidth',1);
    398         hold on;
    399         for i=1:length(xsegments),
    400                 plot(xsegments(i,:),ysegments(i,:),color,'LineWidth',linewidth);
    401         end
    402 end
    403 
    404 //Scatter
    405 if exist(options,'scatter')
    406         data=options.getfieldvalue('scatter');
    407         hold on
    408         plot_scatter(data(:,1),data(:,2),data(:,3),options);
    409 end
    410 
    411 //backgroundcolor
    412 set(gca,'color',options.getfieldvalue('backgroundcolor','none'));
    413 
    414 //lighting
    415 if strcmpi(options.getfieldvalue('light','off'),'on'),
    416         set(gca,'FaceLighting','gouraud','FaceColor','interp','AmbientStrength',0.5);
    417         light('Position',[0 0.1 0.1],'Style','infinite');
    418 end
    419 
    420 //cloud of points:
    421 if exist(options,'cloud'),
    422         field=options.getfieldvalue('cloud');
    423         x=field(:,1);
    424         y=field(:,2);
    425         //unit multiplier:
    426         if exist(options,'unit'),
    427                 unit=options.getfieldvalue('unit');
    428                 x=x*unit;
    429                 y=y*unit;
    430         end
    431         hold on,p=plot(x,y,'k.');
    432         markersize=options.getfieldvalue('markersize',12);
    433         color=options.getfieldvalue('cloudcolor','k');
    434         set(p,'Color',color);
    435         set(p,'MarkerSize',markersize);
    436 end
    437 
    438 //========================//
    439 //OK VERY LAST STEP: INSET|
    440 //========================//
    441 if exist(options,'inset'),
    442 
    443         //Keep pointer of main axis
    444         maingca=gca;
    445         //get inset relative position (x,y,width,height)
    446         insetpos=options.getfieldvalue('insetpos',[0.56 0.55 0.35 0.35]);
    447         //get current plot position
    448         cplotpos=get(gca,'pos');
    449 
    450         X1=options.getfieldvalue('insetx',xlim);
    451         Y1=options.getfieldvalue('insety',ylim);
    452 
    453         for i=1:length(options.getfieldvalue('insetx')),
    454                 if length(insetpos)==4,
    455                         insetposi=insetpos;
    456                 else
    457                         insetposi=insetpos{i};
    458                 end
    459                 PosInseti=[cplotpos(1)+insetposi(1)*cplotpos(3),cplotpos(2)+insetposi(2)*cplotpos(4), insetposi(3)*cplotpos(3), insetposi(4)*cplotpos(4)];
    460                 //show pos
    461                 if iscell(X1),
    462                         X1i=X1{i};
    463                 else
    464                         X1i=X1;
    465                 end
    466                 if iscell(Y1),
    467                         Y1i=Y1{i};
    468                 else
    469                         Y1i=Y1;
    470                 end
    471                 if strcmpi(options.getfieldvalue('showinset','off'),'on')
    472                         line(X1i([1 2 2 1 1]),Y1i([1 1 2 2 1]),zeros(1,5),'Color','k','LineWidth',2);
    473                 end
    474 
    475                 //Get current figure
    476                 ax1=gca;
    477 
    478                 //plot inset
    479                 axes('pos',PosInseti);
    480                 copyobj(get(ax1,'children'),gca);
    481                 patch('Faces',[1 2 3 4 1],'Vertices',[X1i([1 2 2 1])' Y1i([1 1 2 2])'],'FaceColor','None','EdgeColor','k','LineWidth',2);
    482 
    483                 //apply options
    484                 options=removefield(options,'text',0);
    485                 options=removefield(options,'title',0);
    486                 options=removefield(options,'xlabel',0);
    487                 options=removefield(options,'ylabel',0);
    488                 options=removefield(options,'inset',0);
    489                 options=removefield(options,'offsetaxispos',0);
    490                 options=removefield(options,'showregion',0);
    491                 options=changefieldvalue(options,'colorbar',0);
    492                 options=changefieldvalue(options,'latlon','off');
    493                 options=changefieldvalue(options,'axis','equal off');
    494                 options=changefieldvalue(options,'xlim',X1i);
    495                 options=changefieldvalue(options,'ylim',Y1i);
    496                 applyoptions(md,data,options);
    497 
     394                        mdx=[min(md.mesh.x)-offset max(md.mesh.x)+offset];
     395                        mdy=[min(md.mesh.y)-offset max(md.mesh.y)+offset];
     396                end
     397                line(A.x,A.y,ones(size(A.x)),'color','b');
     398                patch([Ax(1)  Ax(2)  Ax(2)  Ax(1) Ax(1)],[Ay(1)  Ay(1)  Ay(2)  Ay(2) Ay(1)],[1 1 1],'EdgeColor',[0 0 0],'LineWidth',1,'FaceLighting','none')
     399                patch([mdx(1) mdx(2) mdx(2) mdx(1)],[mdy(1) mdy(1) mdy(2) mdy(2)],ones(4,1),'EdgeColor',[0 0 0],'FaceColor','r','FaceAlpha',0.5)
     400                colorbar('off');
    498401                //back to main gca
    499402                set(gcf,'CurrentAxes',maingca)
    500403        end
    501 end
     404
     405        //flag edges of a partition
     406        if exist(options,'partitionedges')
     407                [xsegments ysegments]=flagedges(md.mesh.elements,md.mesh.x,md.mesh.y,md.qmu.partition);
     408                xsegments=xsegments*options.getfieldvalue('unit',1);
     409                ysegments=ysegments*options.getfieldvalue('unit',1);
     410                color=options.getfieldvalue('partitionedgescolor','r-');
     411                linewidth=options.getfieldvalue('linewidth',1);
     412                hold on;
     413                for i=1:length(xsegments),
     414                        plot(xsegments(i,:),ysegments(i,:),color,'LineWidth',linewidth);
     415                end
     416        end
     417
     418        //Scatter
     419        if exist(options,'scatter')
     420                data=options.getfieldvalue('scatter');
     421                hold on
     422                plot_scatter(data(:,1),data(:,2),data(:,3),options);
     423        end
     424
     425        //backgroundcolor
     426        set(gca,'color',options.getfieldvalue('backgroundcolor','none'));
     427
     428        //lighting
     429        if strcmpi(options.getfieldvalue('light','off'),'on'),
     430                set(gca,'FaceLighting','gouraud','FaceColor','interp','AmbientStrength',0.5);
     431                light('Position',[0 0.1 0.1],'Style','infinite');
     432        end
     433
     434        //cloud of points:
     435        if exist(options,'cloud'),
     436                field=options.getfieldvalue('cloud');
     437                x=field(:,1);
     438                y=field(:,2);
     439                //unit multiplier:
     440                if exist(options,'unit'),
     441                        unit=options.getfieldvalue('unit');
     442                        x=x*unit;
     443                        y=y*unit;
     444                end
     445                hold on,p=plot(x,y,'k.');
     446                markersize=options.getfieldvalue('markersize',12);
     447                color=options.getfieldvalue('cloudcolor','k');
     448                set(p,'Color',color);
     449                set(p,'MarkerSize',markersize);
     450        end
     451
     452        //========================//
     453        //OK VERY LAST STEP: INSET|
     454        //========================//
     455        if exist(options,'inset'),
     456
     457                //Keep pointer of main axis
     458                maingca=gca;
     459                //get inset relative position (x,y,width,height)
     460                insetpos=options.getfieldvalue('insetpos',[0.56 0.55 0.35 0.35]);
     461                //get current plot position
     462                cplotpos=get(gca,'pos');
     463
     464                X1=options.getfieldvalue('insetx',xlim);
     465                Y1=options.getfieldvalue('insety',ylim);
     466
     467                for i=1:length(options.getfieldvalue('insetx')),
     468                        if length(insetpos)==4,
     469                                insetposi=insetpos;
     470                        else
     471                                insetposi=insetpos{i};
     472                        end
     473                        PosInseti=[cplotpos(1)+insetposi(1)*cplotpos(3),cplotpos(2)+insetposi(2)*cplotpos(4), insetposi(3)*cplotpos(3), insetposi(4)*cplotpos(4)];
     474                        //show pos
     475                        if iscell(X1),
     476                                X1i=X1{i};
     477                        else
     478                                X1i=X1;
     479                        end
     480                        if iscell(Y1),
     481                                Y1i=Y1{i};
     482                        else
     483                                Y1i=Y1;
     484                        end
     485                        if strcmpi(options.getfieldvalue('showinset','off'),'on')
     486                                line(X1i([1 2 2 1 1]),Y1i([1 1 2 2 1]),zeros(1,5),'Color','k','LineWidth',2);
     487                        end
     488
     489                        //Get current figure
     490                        ax1=gca;
     491
     492                        //plot inset
     493                        axes('pos',PosInseti);
     494                        copyobj(get(ax1,'children'),gca);
     495                        patch('Faces',[1 2 3 4 1],'Vertices',[X1i([1 2 2 1])' Y1i([1 1 2 2])'],'FaceColor','None','EdgeColor','k','LineWidth',2);
     496
     497                        //apply options
     498                        options=removefield(options,'text',0);
     499                        options=removefield(options,'title',0);
     500                        options=removefield(options,'xlabel',0);
     501                        options=removefield(options,'ylabel',0);
     502                        options=removefield(options,'inset',0);
     503                        options=removefield(options,'offsetaxispos',0);
     504                        options=removefield(options,'showregion',0);
     505                        options=changefieldvalue(options,'colorbar',0);
     506                        options=changefieldvalue(options,'latlon','off');
     507                        options=changefieldvalue(options,'axis','equal off');
     508                        options=changefieldvalue(options,'xlim',X1i);
     509                        options=changefieldvalue(options,'ylim',Y1i);
     510                        applyoptions(md,data,options);
     511
     512                        //back to main gca
     513                        set(gcf,'CurrentAxes',maingca)
     514                end
     515        end
     516        */ //}}}
    502517}
  • issm/trunk-jpl/src/m/plot/plot_manager.js

    r19775 r19782  
    222222        }
    223223        //applyoptions(md,data2,options);
     224        applyoptions(md,data,options);
    224225}
  • issm/trunk-jpl/test/NightlyRun/test101.html

    r19781 r19782  
    6464<script type="text/javascript" src="../../src/m/plot/plot_mesh.js"></script>
    6565<script type="text/javascript" src="../../src/m/plot/checkplotoptions.js"></script>
     66<script type="text/javascript" src="../../src/m/plot/applyoptions.js"></script>
    6667<script type="text/javascript" src="../../src/m/plot/plot_manager.js"></script>
    6768<script type="text/javascript" src="../../src/m/geometry/FlagElements.js"></script>
     
    9192        parameterize(md);
    9293       
    93         setflowequation(md,'SSA','all');
    94         md=solve(md,StressbalanceSolutionEnum());
     94        //setflowequation(md,'SSA','all');
     95        //md=solve(md,StressbalanceSolutionEnum());
    9596
    96         /*plotmodel(md,'data',md.initialization.vel, 'data',md.initialization.vx,
    97         'data',md.initialization.temperature, 'data',md.basalforcings.floatingice_melting_rate,'data','mesh');*/
     97        plotmodel(md,'data',md.initialization.vel,'colorbar',1, 'data',md.initialization.vx,
     98        'data',md.initialization.temperature, 'data',md.basalforcings.floatingice_melting_rate,'data','mesh');
    9899
    99100
Note: See TracChangeset for help on using the changeset viewer.