Changeset 19965
- Timestamp:
- 01/19/16 18:15:11 (9 years ago)
- Location:
- issm/trunk-jpl/src/m/plot
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/applyoptions.js
r19891 r19965 6 6 // 7 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)); 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'), 57 axis auto tight 58 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 /* ///{{{ 107 //shading 108 if exist(options,'shading'), 109 shading(options.getfieldvalue('shading')); 110 end 111 112 //grid 113 if exist(options,'grid'), 114 if strcmpi(options.getfieldvalue('grid'),'on'), 115 grid on; 116 end 117 end 118 119 //colormap 120 c = getcolormap(options); 121 h = colormap(c); 122 123 //wrapping 124 if exist(options,'wrapping'), 125 if ~exist(options,'colormap'), 126 h=jet; 127 end 128 colormap(repmat(h,options.getfieldvalue('wrapping',1),1)); 129 end 130 */ //}}} 131 //colorbar 8 9 //colorbar {{{ 132 10 if (options.exist('colorbar')) { 133 11 if (options.getfieldvalue('colorbar')==1) { 134 if (options.exist('colorbarcornerposition')) { 135 //c=colorbar(options.getfieldvalue('colorbarcornerposition'),'peer',gca); 136 } else { 137 } 138 139 //Handle movie data 12 //Handle movie data {{{ 140 13 var dataresults = processdata(md,data,options); 141 14 var data2 = dataresults[0]; … … 150 23 data = data[node["movieFrame"]].slice(0,-1); 151 24 console.log(data); 152 } 153 25 } //}}} 26 //Variable options initialization {{{ 154 27 var caxis = options.getfieldvalue('caxis',[ArrayMin(data),ArrayMax(data)]); 155 28 var canvassize = options.getfieldvalue('canvassize',480); … … 160 33 var ccontext,ccanvas,ccanvasid,ccanvashtml; 161 34 var colorbarorientiation = options.getfieldvalue('colorbarorientation','vertical'); 162 //define offsets for correct font drawing on canvas163 35 var cheightoffset = options.getfieldvalue('colorbarfontsize',16); 164 36 var cwidthoffset = options.getfieldvalue('colorbarfontsize',16)*3; 165 166 //Set colorbar lables 37 var y; 38 var x; 39 //}}} 40 //Set colorbar lables {{{ 167 41 var labels = []; 168 42 var cdivisions = options.getfieldvalue('colorbarnticks',6); … … 183 57 labels[i] = (caxisdelta*(cdivisions-i)/cdivisions+caxis[0]).toPrecision(precision); 184 58 } 185 } 186 var y; 187 var x; 188 189 if (colorbarorientiation=='vertical') { 59 } //}}} 60 //Handle orientation {{{ 61 if (colorbarorientiation=='vertical') { //{{{ 190 62 cheight = options.getfieldvalue('colorbarheight',0.95)*canvassize; 191 63 cwidth = options.getfieldvalue('colorbarwidth',canvassize/20); … … 259 131 ccontext.fillText(options.getfieldvalue('colorbartitle'),0,cheightoffset); 260 132 } 261 } 262 else { //colorbarorientiation=='horizontal' 133 } //}}} 134 else { //colorbarorientiation=='horizontal' {{{ 263 135 cheight = options.getfieldvalue('colorbarheight',canvassize/20); 264 136 cwidth = options.getfieldvalue('colorbarwidth',0.95)*canvassize; … … 332 204 ccontext.fillText(options.getfieldvalue('colorbartitle'),cwidth/2+cwidthoffset,cheightoffset); 333 205 } 334 } 335 /* //{{{ 336 if exist(options,'wrapping') 337 lim=get(c,'Ylim'); 338 lim=[lim(1) lim(1)+(lim(2)-lim(1))/options.getfieldvalue('wrapping')]; 339 set(c,'Ylim',lim); 340 } 341 if exist(options,'colorbarpos'), 342 set(c,'Position',options.getfieldvalue('colorbarpos')); 343 } 344 if exist(options,'log'), 345 nlab=length(get(c,'YTick')); 346 logvalue=options.getfieldvalue('log'); 347 348 scaleminmax=caxis; 349 Min=min(scaleminmax); 350 Max=max(scaleminmax); 351 set(c,'YLim',[Min Max]); // set colorbar limits 352 set(c,'YTick',linspace(Min,Max,nlab)); // set tick mark locations 353 354 labels = cell(1,nlab); 355 tick_vals = linspace(Min,Max,nlab); 356 tick_vals = exp(log(logvalue)*tick_vals); 357 warning off MATLAB:log:logOfZero; 358 for i = 1:nlab 359 labels{i} = sprintf('//-3.4g',round_ice(tick_vals(i),2)); 360 //labels{i} = sprintf('//-.4g',round_ice(tick_vals(i),2)); 361 } 362 warning on MATLAB:log:logOfZero; 363 set(c,'YTickLabel',labels); 364 } 365 if exist(options,'cbYLim'); 366 set(c,'YLim',options.getfieldvalue('cbYLim')); 367 } 368 if exist(options,'colorbartitle'), 369 set(get(c,'title'),'FontSize',options.getfieldvalue('colorbarfontsize',fontsize),'String',options.getfieldvalue('colorbartitle'),... 370 'Color',options.getfieldvalue('FontColor','k')); 371 } 372 if exist(options,'colorbarYLabel'), 373 set(get(c,'Ylabel'),'FontSize',options.getfieldvalue('colorbarfontsize',fontsize),'String',options.getfieldvalue('colorbarYLabel'),... 374 'Color',options.getfieldvalue('FontColor','k')); 375 } 376 if exist(options,'colorbarwidth'), 377 posaxes=get(gca,'Position'); 378 alpha=options.getfieldvalue('colorbarwidth',1); 379 position=get(c,'Position'); 380 dx=position(3); 381 newdx=dx*alpha; 382 position(1)=position(1)+(dx-newdx)/2; 383 position(3)=newdx; 384 set(c,'Position',position); 385 set(gca,'Position',posaxes); 386 } 387 if exist(options,'colorbarheight'), 388 posaxes=get(gca,'Position'); 389 alpha=options.getfieldvalue('colorbarheight',1); 390 position=get(c,'Position'); 391 dy=position(4); 392 newdy=dy*alpha; 393 position(2)=position(2)+(dy-newdy)/2; 394 position(4)=newdy; 395 set(c,'Position',position); 396 set(gca,'Position',posaxes); 397 } 398 if (options.exist('cbYTickLabel')) { 399 } 400 */ //}}} 401 } 402 } else { 403 //do nothing 404 405 } 406 //Make texture canvas 407 206 } //}}} 207 //}}} 208 } 209 } 210 //}}} 211 //Make texture canvas //{{{ 408 212 var tcontext,tcanvas,tcanvasid,tcanvashtml,tURL,tgradient; 409 213 tcanvasid = 'texturecanvas'; … … 432 236 tURL = tcanvashtml.toDataURL(); 433 237 node["texture"] = initTexture(gl,tURL); 434 /* //{{{ 435 //area 436 if exist(options,'area'), 437 antzoom(options.getfieldvalue('area')); 438 end 439 440 //expdisp 441 if exist(options,'expdisp'), 442 filename=(options.getfieldvalue('expdisp')); 443 style=(options.getfieldvalue('expstyle')); 444 linewidth=(options.getfieldvalue('linewidth',1)); 445 for i=1:length(options.getfieldvalue('expdisp')), 446 filenamei=filename{i}; 447 stylei=style{i}; 448 if length(linewidth)==1, 449 linewidthi=linewidth; 450 else 451 linewidthi=linewidth{i}; 452 end 453 expdisp(filenamei,'linestyle',stylei,'linewidthi',linewidthi,'multiplier',options.getfieldvalue('unit',1)); 454 end 455 end 456 457 //text (default value is empty, not NaN...) 458 if exist(options,'text'); 459 textstring=options.getfieldvalue('text'); 460 textweight=options.getfieldvalue('textweight','b'); 461 textsize=options.getfieldvalue('textsize'); 462 textcolor=options.getfieldvalue('textcolor'); 463 textposition=options.getfieldvalue('textposition'); 464 textrotation=options.getfieldvalue('textrotation'); 465 for i=1:length(options.getfieldvalue('text')); 466 textstringi=textstring{i}; 467 textweighti=textweight{i}; 468 textsizei=textsize{i}; 469 textcolori=textcolor{i}; 470 textpositioni=textposition{i}; 471 textrotationi=textrotation{i}; 472 h=text(textpositioni(1),textpositioni(2),10,textstringi,'FontSize',textsizei,'FontWeight',textweighti,'Color',textcolori,'Rotation',textrotationi); 473 set(h,'Clipping','on'); //prevent text from appearing outside of the box 474 end 475 end 476 477 //north arrow 478 if exist(options,'northarrow'), 479 northarrow(options.getfieldvalue('northarrow')); 480 end 481 482 //curved arrow 483 if exist(options,'curvedarrow'), 484 curvedoptions=options.getfieldvalue('curvedarrow'); 485 curvedarrow(curvedoptions{:}); 486 end 487 488 //Scale ruler 489 if exist(options,'scaleruler'), 490 scaleruler(options); 491 end 492 493 //streamliness 494 if exist(options,'streamlines'), 495 plot_streamlines(md,options); 496 end 497 498 //contours 499 if exist(options,'contourlevels'), 500 plot_contour(md,data,options); 501 end 502 503 //YTickLabel 504 if exist(options,'yticklabel'), 505 set(gca,'YTickLabel',options.getfieldvalue('YTickLabel')); 506 end 507 508 //XTickLabel 509 if exist(options,'xticklabel'), 510 set(gca,'XTickLabel',options.getfieldvalue('XTickLabel')); 511 end 512 513 //xtick 514 if exist(options,'xtick'), 515 set(gca,'xtick',options.getfieldvalue('xtick')); 516 end 517 518 //ytick 519 if exist(options,'ytick'), 520 set(gca,'ytick',options.getfieldvalue('ytick')); 521 end 522 523 //Axis positions 524 if exist(options,'offsetaxispos'), 525 offset=options.getfieldvalue('offsetaxispos'); 526 P=get(gca,'pos'); 527 P(1)=P(1)+offset(1); 528 P(2)=P(2)+offset(2); 529 P(3)=P(3)+offset(3); 530 P(3)=P(4)+offset(4); 531 set(gca,'pos',P); 532 end 533 if exist(options,'axispos'), 534 Axis=options.getfieldvalue('axispos'); 535 hold on 536 set(gca,'pos',Axis); 537 end 538 539 //axes position 540 if exist(options,'axesPosition') 541 set(gca,'Position',options.getfieldvalue('axesPosition')); 542 end 543 544 //showregion 545 if strcmpi(options.getfieldvalue('showregion','off'),'on'), 546 //Keep pointer of main axis 547 maingca=gca; 548 //get inset relative position (x,y,width,height) 549 insetpos=options.getfieldvalue('insetpos',[0.02 0.70 0.18 0.18]); 550 //get current plos position 551 cplotpos=get(maingca,'pos'); 552 //compute inset position 553 PosInset=[cplotpos(1)+insetpos(1)*cplotpos(3),cplotpos(2)+insetpos(2)*cplotpos(4), insetpos(3)*cplotpos(3), insetpos(4)*cplotpos(4)]; 554 axes('pos',PosInset); 555 axis equal off 556 //box off 557 if md.mesh.epsg==3413, 558 A=expread('/u/astrid-r1b/ModelData/Exp/GreenlandBoxFront.exp'); 559 [A.x A.y]=ll2xy(A.x,A.y,+1,45,70); 560 A.x = A.x(1:30:end); 561 A.y = A.y(1:30:end); 562 elseif md.mesh.epsg==3031, 563 A=expread('/u/astrid-r1b/ModelData/Exp/Antarctica.exp'); 564 else 565 error('applyoptions error message: md.mesh.epsg not defined'); 566 end 567 offset=3*10^4; 568 Ax=[min(A.x)-offset max(A.x)+offset]; 569 Ay=[min(A.y)-offset max(A.y)+offset]; 570 //if we are zooming on a basin, don't take the mesh for the boundaries! 571 if exist(options,'basin'), 572 [mdx mdy]=basinzoom(options); 573 else 574 mdx=[min(md.mesh.x)-offset max(md.mesh.x)+offset]; 575 mdy=[min(md.mesh.y)-offset max(md.mesh.y)+offset]; 576 end 577 line(A.x,A.y,ones(size(A.x)),'color','b'); 578 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') 579 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) 580 colorbar('off'); 581 //back to main gca 582 set(gcf,'CurrentAxes',maingca) 583 end 584 585 //flag edges of a partition 586 if exist(options,'partitionedges') 587 [xsegments ysegments]=flagedges(md.mesh.elements,md.mesh.x,md.mesh.y,md.qmu.partition); 588 xsegments=xsegments*options.getfieldvalue('unit',1); 589 ysegments=ysegments*options.getfieldvalue('unit',1); 590 color=options.getfieldvalue('partitionedgescolor','r-'); 591 linewidth=options.getfieldvalue('linewidth',1); 592 hold on; 593 for i=1:length(xsegments), 594 plot(xsegments(i,:),ysegments(i,:),color,'LineWidth',linewidth); 595 end 596 end 597 598 //Scatter 599 if exist(options,'scatter') 600 data=options.getfieldvalue('scatter'); 601 hold on 602 plot_scatter(data(:,1),data(:,2),data(:,3),options); 603 end 604 605 //backgroundcolor 606 set(gca,'color',options.getfieldvalue('backgroundcolor','none')); 607 608 //lighting 609 if strcmpi(options.getfieldvalue('light','off'),'on'), 610 set(gca,'FaceLighting','gouraud','FaceColor','interp','AmbientStrength',0.5); 611 light('Position',[0 0.1 0.1],'Style','infinite'); 612 end 613 614 //cloud of points: 615 if exist(options,'cloud'), 616 field=options.getfieldvalue('cloud'); 617 x=field(:,1); 618 y=field(:,2); 619 //unit multiplier: 620 if exist(options,'unit'), 621 unit=options.getfieldvalue('unit'); 622 x=x*unit; 623 y=y*unit; 624 end 625 hold on,p=plot(x,y,'k.'); 626 markersize=options.getfieldvalue('markersize',12); 627 color=options.getfieldvalue('cloudcolor','k'); 628 set(p,'Color',color); 629 set(p,'MarkerSize',markersize); 630 end 631 632 //========================// 633 //OK VERY LAST STEP: INSET| 634 //========================// 635 if exist(options,'inset'), 636 637 //Keep pointer of main axis 638 maingca=gca; 639 //get inset relative position (x,y,width,height) 640 insetpos=options.getfieldvalue('insetpos',[0.56 0.55 0.35 0.35]); 641 //get current plot position 642 cplotpos=get(gca,'pos'); 643 644 X1=options.getfieldvalue('insetx',xlim); 645 Y1=options.getfieldvalue('insety',ylim); 646 647 for i=1:length(options.getfieldvalue('insetx')), 648 if length(insetpos)==4, 649 insetposi=insetpos; 650 else 651 insetposi=insetpos{i}; 652 end 653 PosInseti=[cplotpos(1)+insetposi(1)*cplotpos(3),cplotpos(2)+insetposi(2)*cplotpos(4), insetposi(3)*cplotpos(3), insetposi(4)*cplotpos(4)]; 654 //show pos 655 if iscell(X1), 656 X1i=X1{i}; 657 else 658 X1i=X1; 659 end 660 if iscell(Y1), 661 Y1i=Y1{i}; 662 else 663 Y1i=Y1; 664 end 665 if strcmpi(options.getfieldvalue('showinset','off'),'on') 666 line(X1i([1 2 2 1 1]),Y1i([1 1 2 2 1]),zeros(1,5),'Color','k','LineWidth',2); 667 end 668 669 //Get current figure 670 ax1=gca; 671 672 //plot inset 673 axes('pos',PosInseti); 674 copyobj(get(ax1,'children'),gca); 675 patch('Faces',[1 2 3 4 1],'Vertices',[X1i([1 2 2 1])' Y1i([1 1 2 2])'],'FaceColor','None','EdgeColor','k','LineWidth',2); 676 677 //apply options 678 options=removefield(options,'text',0); 679 options=removefield(options,'title',0); 680 options=removefield(options,'xlabel',0); 681 options=removefield(options,'ylabel',0); 682 options=removefield(options,'inset',0); 683 options=removefield(options,'offsetaxispos',0); 684 options=removefield(options,'showregion',0); 685 options=changefieldvalue(options,'colorbar',0); 686 options=changefieldvalue(options,'latlon','off'); 687 options=changefieldvalue(options,'axis','equal off'); 688 options=changefieldvalue(options,'xlim',X1i); 689 options=changefieldvalue(options,'ylim',Y1i); 690 applyoptions(md,data,options); 691 692 //back to main gca 693 set(gcf,'CurrentAxes',maingca) 694 end 695 end 696 */ //}}} 238 //}}} 239 //expdisp contours 240 if (options.exist('expdisp')) { 241 canvas.nodes["expdisp"] = Node(gl,options); 242 var node = canvas.nodes["expdisp"]; 243 244 //declare variables: {{{ 245 var vertices = []; 246 var indices = []; 247 var colors = []; 248 var rgbcolor = []; 249 var xmin,xmax; 250 var ymin,ymax; 251 var zmin,zmax; 252 var scale; 253 254 //Process data and model 255 var x = options.getfieldvalue('expdisp')['x']; 256 var y = options.getfieldvalue('expdisp')['y']; 257 var z = Array.apply(null, Array(x.length)).map(Number.prototype.valueOf,0); 258 259 if (options.getfieldvalue('expdisp')['z']) { 260 z = options.getfieldvalue('expdisp')['z']; 261 } 262 //}}} 263 264 //Compute coordinates and data range: 265 var modelxlim = [ArrayMin(x),ArrayMax(x)]; 266 var modelylim = [ArrayMin(y),ArrayMax(y)]; 267 var modelzlim = [ArrayMin(z),ArrayMax(z)]; 268 var xlim = options.getfieldvalue('xlim',modelxlim); 269 var ylim = options.getfieldvalue('ylim',modelylim); 270 var zlim = options.getfieldvalue('zlim',modelzlim); 271 xmin = xlim[0]; 272 xmax = xlim[1]; 273 ymin = ylim[0]; 274 ymax = ylim[1]; 275 zmin = zlim[0]; 276 zmax = zlim[1]; 277 278 //Compute scaling: 279 var scale = 1 / (xmax - xmin); 280 node["shaderName"] = "colored"; 281 node["shader"] = gl["shaders"][node["shaderName"]]["program"]; 282 node["scale"] = [scale, scale, scale*options.getfieldvalue('heightscale',1)]; 283 node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmin + zmax) / (-2 / scale)]; 284 node["modelMatrix"] = recalculateModelMatrix(node); 285 node["drawMode"] = gl.LINE_LOOP; 286 node["drawOrder"] = 0; 287 node["useIndexBuffer"] = false; 288 node["disableDepthTest"] = true; 289 290 //some defaults: 291 colors.itemSize = 4; 292 293 //retrieve some options 294 var linewidth=options.getfieldvalue('linewidth',1); 295 var edgecolor=options.getfieldvalue('edgecolor','black'); //RGBCOLOR? 296 297 vertices.itemSize = 3; 298 for(var i = 0; i < x.length; i++){ 299 vertices[vertices.length] = x[i]; 300 vertices[vertices.length] = y[i]; 301 vertices[vertices.length] = z[i]; 302 303 //edgecolor 304 rgbcolor = [0.0, 0.0, 0.0]; 305 colors[colors.length] = rgbcolor[0]; 306 colors[colors.length] = rgbcolor[1]; 307 colors[colors.length] = rgbcolor[2]; 308 colors[colors.length] = 1.0; 309 } 310 311 /*Initalize buffers: */ 312 node["arrays"] = [vertices, colors]; 313 node["buffers"] = initBuffers(gl, node["arrays"]); 314 } 697 315 } -
issm/trunk-jpl/src/m/plot/webgl.js
r19946 r19965 427 427 gl.uniform1i(node["shader"]["uColorSampler"], 0); 428 428 } 429 if (node["disableDepthTest"]) { 430 gl.disable(gl.DEPTH_TEST); 431 } 429 432 gl.blendFunc (gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); 430 433 if (node["useIndexBuffer"] == true) { … … 435 438 gl.drawArrays(node["drawMode"], 0, node["buffers"][0].numItems); 436 439 } 440 gl.enable(gl.DEPTH_TEST); 437 441 } //}}} 438 442 function bindAttributes(gl,shaderProgram,bufferArray) { //{{{
Note:
See TracChangeset
for help on using the changeset viewer.