Changeset 20652
- Timestamp:
- 05/25/16 23:35:31 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/applyoptions.js
r20586 r20652 14 14 data = data[0]; 15 15 } //}}} 16 //Variable options initialization {{{ 16 //Variable options initialization {{{ 17 17 var caxis = options.getfieldvalue('caxis',[ArrayMin(data),ArrayMax(data)]); 18 18 var canvassize = options.getfieldvalue('canvassize',480); 19 var cheight; 20 var cwidth; 21 var cdivisions = cheight/4; 22 var color; 23 var ccontext,ccanvas,ccanvasid,ccanvashtml; 19 20 var ccontext,ccanvas,ccanvasid,ccanvashtml,cheight,cwidth,color,y,x; 24 21 var colorbarorientiation = options.getfieldvalue('colorbarorientation','vertical'); 25 22 var cheightoffset = options.getfieldvalue('colorbarfontsize',18); 26 23 var cwidthoffset = options.getfieldvalue('colorbarfontsize',18)*3; 27 var y;28 var x;24 var cwidthscale = 0.5; //Default size of actual colorbar width, relative to canvas width (range [0,1]) 25 var cheightscale = 0.875; //Default size of actual colorbar height, relative to canvas height (range [0,1]) 29 26 //}}} 30 27 //Set colorbar lables {{{ … … 33 30 var caxisdelta = caxis[1] - caxis[0]; 34 31 var clabelitem; 35 var precision =options.getfieldvalue('colorbarprecision',3);32 var precision = options.getfieldvalue('colorbarprecision',3); 36 33 37 34 if (options.getfieldvalue('log','off')!='off') { … … 47 44 //Handle orientation {{{ 48 45 if (colorbarorientiation=='vertical') { //{{{ 49 cheight = options.getfieldvalue('colorbarheight',0.95)*canvassize;50 cwidth = options.getfieldvalue('colorbarwidth',canvassize/20);51 46 ccanvasid = options.getfieldvalue('colorbarcanvasid',options.getfieldvalue('canvasid')+'_colorbar'); 52 47 ccanvashtml = document.getElementById(ccanvasid); 53 if (ccanvashtml==null) { 54 ccanvas = $('<canvas id="'+ccanvasid+'" width="'+String(cwidth+cheightoffset*4)+'" height="'+String(cheight+cheightoffset*2)+'"></canvas>').insertAfter('#'+options.getfieldvalue('canvasid')); 55 ccanvas.css({'position':'relative','top':((canvassize-cheight-cheightoffset)/-2).toFixed(2)+'px'}); 56 ccontext = ccanvas[0].getContext('2d'); 57 } 58 else{ 59 ccanvas = $('#'+ccanvasid); 60 if (options.exist('colorbarcanvasid')&&!ccanvashtml.hasOwnProperty('init')){ 61 //store actual colobar size 62 cwidth = ccanvashtml.clientWidth; 63 cheight = ccanvashtml.clientHeight; 64 ccanvas.attr({width:cwidth+cheightoffset*4,height:cheight+cheightoffset*2}).css({width:cwidth+cheightoffset*4,height:cheight+cheightoffset*2}); 65 //get html object instead of jqurey object to modify height/width to accomodate labels 66 ccanvashtml.cwidth = cwidth; 67 ccanvashtml.cheight = cheight; 68 ccanvashtml.init = true; 69 } 70 else { 71 cwidth = ccanvashtml.cwidth; 72 cheight = ccanvashtml.cheight; 73 } 74 ccontext = ccanvas[0].getContext('2d'); 75 /*erase existing colorbar:*/ 76 ccontext.clearRect(0,0, ccanvashtml.width, ccanvashtml.height); 77 ccontext.beginPath(); 78 } 48 cwidth = ccanvashtml.width*cwidthscale*options.getfieldvalue('colorbarwidth',1); 49 cheight = ccanvashtml.height*cheightscale*options.getfieldvalue('colorbarheight',1); 50 ccanvas = $('#'+ccanvasid); 51 ccontext = ccanvas[0].getContext('2d'); 52 ccontext.clearRect(0,0, ccanvashtml.width, ccanvashtml.height); 53 ccontext.beginPath(); 54 79 55 var cgradient = ccontext.createLinearGradient(0,cheightoffset/2,0,cheight); 80 81 56 var cmap = options.getfieldvalue('cmap','jet'); 82 57 var colorbar = colorbars[cmap]; … … 123 98 ccanvasid = options.getfieldvalue('colorbarcanvasid',options.getfieldvalue('canvasid')+'_colorbar'); 124 99 ccanvashtml = document.getElementById(ccanvasid); 125 if (ccanvashtml==null) { 126 ccanvas = $('<canvas id="'+ccanvasid+'" width="'+String(cwidth+cheightoffset*4)+'" height="'+String(cheight+cheightoffset*5/2)+'"></canvas>').insertAfter('#'+options.getfieldvalue('canvasid')); 127 ccanvas.css({'position':'relative','top':((canvassize-cheight-cheightoffset*2)/-2).toFixed(2)+'px'}); 128 ccontext = ccanvas[0].getContext('2d'); 129 } 130 else{ 131 ccanvas = $('#'+ccanvasid); 132 if (options.exist('colorbarcanvasid')&&!ccanvashtml.hasOwnProperty('init')){ 133 //store actual colobar size 134 cwidth = ccanvashtml.clientWidth; 135 cheight = ccanvashtml.clientHeight; 136 //get html object instead of jqurey object to modify height/width to accomodate labels 137 ccanvashtml.width = cwidth+cheightoffset*6; 138 ccanvashtml.height = cheight+cheightoffset*5/2; 139 ccanvashtml.cwidth = cwidth; 140 ccanvashtml.cheight = cheight; 141 ccanvashtml.init = true; 142 } 143 else { 144 cwidth = ccanvashtml.cwidth; 145 cheight = ccanvashtml.cheight; 146 } 147 ccontext = ccanvas[0].getContext('2d'); 148 /*erase existing colorbar:*/ 149 ccontext.clearRect(0,0, ccanvashtml.width, ccanvashtml.height); 150 ccontext.beginPath(); 151 } 152 var cgradient = ccontext.createLinearGradient(cwidth+cwidthoffset,0,cwidthoffset,0); 153 100 101 ccanvas = $('#'+ccanvasid); 102 cwidth = ccanvashtml.clientWidth; 103 cheight = ccanvashtml.clientHeight; 104 ccontext = ccanvas[0].getContext('2d'); 105 ccontext.clearRect(0,0, ccanvashtml.width, ccanvashtml.height); 106 ccontext.beginPath(); 107 108 var cgradient = ccontext.createLinearGradient(cwidth+cwidthoffset,0,cwidthoffset,0); 154 109 var cmap = options.getfieldvalue('cmap','jet'); 155 110 var colorbar = colorbars[cmap];
Note:
See TracChangeset
for help on using the changeset viewer.