[21337] | 1 | Index: ../trunk-jpl/src/m/plot/webgl.js
|
---|
| 2 | ===================================================================
|
---|
| 3 | --- ../trunk-jpl/src/m/plot/webgl.js (revision 20789)
|
---|
| 4 | +++ ../trunk-jpl/src/m/plot/webgl.js (revision 20790)
|
---|
| 5 | @@ -334,8 +334,14 @@
|
---|
| 6 | var deltaX = (canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth / canvas.zoom * -2 * canvas.controlsensitivity;
|
---|
| 7 | var deltaY = (canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight / canvas.zoom * -2 * canvas.controlsensitivity;
|
---|
| 8 |
|
---|
| 9 | - canvas.translation[0] += Math.cos(radians(canvas.rotation[0])) * deltaX - Math.sin(radians(canvas.rotation[0])) * deltaY;
|
---|
| 10 | - canvas.translation[1] += Math.sin(radians(canvas.rotation[0])) * deltaX + Math.cos(radians(canvas.rotation[0])) * deltaY;
|
---|
| 11 | + if (canvas.twod) {
|
---|
| 12 | + canvas.translation[0] += Math.cos(radians(canvas.rotation[0])) * deltaX - Math.sin(radians(0)) * deltaY;
|
---|
| 13 | + canvas.translation[1] += Math.sin(radians(canvas.rotation[0])) * deltaX + Math.cos(radians(0)) * deltaY;
|
---|
| 14 | + }
|
---|
| 15 | + else {
|
---|
| 16 | + canvas.translation[0] += Math.cos(radians(canvas.rotation[0])) * deltaX - Math.sin(radians(canvas.rotation[0])) * deltaY;
|
---|
| 17 | + canvas.translation[1] += Math.sin(radians(canvas.rotation[0])) * deltaX + Math.cos(radians(canvas.rotation[0])) * deltaY;
|
---|
| 18 | + }
|
---|
| 19 | }
|
---|
| 20 | else {
|
---|
| 21 | canvas.rotation[0] += degrees((canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth / canvas.zoom * -2 * canvas.controlsensitivity);
|
---|
| 22 | Index: ../trunk-jpl/src/m/plot/plotdoc.js
|
---|
| 23 | ===================================================================
|
---|
| 24 | --- ../trunk-jpl/src/m/plot/plotdoc.js (revision 20789)
|
---|
| 25 | +++ ../trunk-jpl/src/m/plot/plotdoc.js (revision 20790)
|
---|
| 26 | @@ -23,6 +23,7 @@
|
---|
| 27 | console.log(' "colorbarnticks": number of colorbar ticks (default 6, ex: 2, 10)');
|
---|
| 28 | console.log(' "colorbarprecision": colorbar label digit precision (default 3, ex: 1, 4)');
|
---|
| 29 | console.log(' "colorbarorientation": oreintation of colorbar (default "vertical", ex: "horizontal")');
|
---|
| 30 | + console.log(' "colorbarinnerlabels": choose whether labels are inside colorbar (default "off", ex: "on", "off")');
|
---|
| 31 | console.log(' "colorbarfontsize": specify colorbar font size (default 1, ex: 14, 22)');
|
---|
| 32 | console.log(' "colorbarfontcolor": specify colorbar font color (default "black", ex: "green","blue")');
|
---|
| 33 | console.log(' "colorbarwidth": multiplier (default 1) to the default width colorbar');
|
---|
| 34 | Index: ../trunk-jpl/src/m/plot/applyoptions.js
|
---|
| 35 | ===================================================================
|
---|
| 36 | --- ../trunk-jpl/src/m/plot/applyoptions.js (revision 20789)
|
---|
| 37 | +++ ../trunk-jpl/src/m/plot/applyoptions.js (revision 20790)
|
---|
| 38 | @@ -16,11 +16,12 @@
|
---|
| 39 | //Variable options initialization {{{
|
---|
| 40 | var caxis = options.getfieldvalue('caxis',[ArrayMin(data),ArrayMax(data)]);
|
---|
| 41 | var colorbarorientiation = options.getfieldvalue('colorbarorientation','vertical');
|
---|
| 42 | + var colorbarinnerlabels = options.getfieldvalue('colorbarinnerlabels','off');
|
---|
| 43 | var cheightoffset = options.getfieldvalue('colorbarfontsize',18);
|
---|
| 44 | var cwidthoffset = options.getfieldvalue('colorbarfontsize',18)*3;
|
---|
| 45 | var cwidthscale = 0.5; //Default size of actual colorbar width, relative to canvas width (range [0,1])
|
---|
| 46 | var cheightscale = 0.875; //Default size of actual colorbar height, relative to canvas height (range [0,1])
|
---|
| 47 | - var ccontext,ccanvas,ccanvasid,ccanvashtml,cheight,cwidth,color,y,x;
|
---|
| 48 | + var ccontext,ccanvas,ccanvasid,ccanvashtml,cheight,cwidth,color,y,x,cgradient,cmap,colorbar,textAlign,a,b,c,d,e,f,g,h;
|
---|
| 49 | //}}}
|
---|
| 50 | //Set colorbar lables {{{
|
---|
| 51 | var labels = [];
|
---|
| 52 | @@ -38,106 +39,104 @@
|
---|
| 53 | labels[i] = (caxisdelta*(cdivisions-i)/cdivisions+caxis[0]).toPrecision(precision);
|
---|
| 54 | }
|
---|
| 55 | } //}}}
|
---|
| 56 | + ccanvasid = options.getfieldvalue('colorbarid',options.getfieldvalue('canvasid')+'_colorbar');
|
---|
| 57 | + ccanvashtml = document.getElementById(ccanvasid);
|
---|
| 58 | + ccanvas = $('#'+ccanvasid);
|
---|
| 59 | + ccontext = ccanvas[0].getContext('2d');
|
---|
| 60 | + ccontext.clearRect(0,0, ccanvashtml.width, ccanvashtml.height);
|
---|
| 61 | + ccontext.beginPath();
|
---|
| 62 | + cmap = options.getfieldvalue('colormap','jet');
|
---|
| 63 | + colorbar = colorbars[cmap];
|
---|
| 64 | //Handle orientation {{{
|
---|
| 65 | - if (colorbarorientiation=='vertical') { //{{{
|
---|
| 66 | - ccanvasid = options.getfieldvalue('colorbarid',options.getfieldvalue('canvasid')+'_colorbar');
|
---|
| 67 | - ccanvashtml = document.getElementById(ccanvasid);
|
---|
| 68 | + if (colorbarorientiation=='vertical') {
|
---|
| 69 | cwidth = ccanvashtml.width*cwidthscale*options.getfieldvalue('colorbarwidth',1);
|
---|
| 70 | cheight = ccanvashtml.height*cheightscale*options.getfieldvalue('colorbarheight',1);
|
---|
| 71 | - ccanvas = $('#'+ccanvasid);
|
---|
| 72 | - ccontext = ccanvas[0].getContext('2d');
|
---|
| 73 | - ccontext.clearRect(0,0, ccanvashtml.width, ccanvashtml.height);
|
---|
| 74 | - ccontext.beginPath();
|
---|
| 75 | + cgradient = ccontext.createLinearGradient(0,cheightoffset/2,0,cheight);
|
---|
| 76 | + textAlign = 'left';
|
---|
| 77 | + a = 0;
|
---|
| 78 | + b = cheightoffset*3/2;
|
---|
| 79 | + c = 0;
|
---|
| 80 | + }
|
---|
| 81 | + else {
|
---|
| 82 | + cwidth = ccanvashtml.width*0.7*options.getfieldvalue('colorbarwidth',1);
|
---|
| 83 | + cheight = ccanvashtml.height*0.4*options.getfieldvalue('colorbarheight',1);
|
---|
| 84 | + cgradient = ccontext.createLinearGradient(cwidth+cwidthoffset,0,cwidthoffset,0);
|
---|
| 85 | + textAlign = 'center';
|
---|
| 86 | + a = cwidthoffset;
|
---|
| 87 | + b = cheightoffset;
|
---|
| 88 | + c = cwidth/2+cwidthoffset;
|
---|
| 89 | + } //}}}
|
---|
| 90 | + //Handle internal labels {{{
|
---|
| 91 | + if (colorbarinnerlabels=='on') {
|
---|
| 92 | + textAlign = 'center';
|
---|
| 93 | + d = (cdivisions/(cdivisions+1.0));
|
---|
| 94 | + e = (1.0/(cdivisions+1.0));
|
---|
| 95 | + f = 2;
|
---|
| 96 | + g = 1;
|
---|
| 97 | + h = cwidth/2;
|
---|
| 98 | + }
|
---|
| 99 | + else {
|
---|
| 100 | + d = 1;
|
---|
| 101 | + e = 0;
|
---|
| 102 | + f = 1;
|
---|
| 103 | + g = 0;
|
---|
| 104 | + h = cwidth+0.2*cwidth;
|
---|
| 105 | + } //}}}
|
---|
| 106 |
|
---|
| 107 | - var cgradient = ccontext.createLinearGradient(0,cheightoffset/2,0,cheight);
|
---|
| 108 | - var cmap = options.getfieldvalue('colormap','jet');
|
---|
| 109 | - var colorbar = colorbars[cmap];
|
---|
| 110 | - for (var i=0; i < colorbar.length; i++) {
|
---|
| 111 | - color = colorbar[colorbar.length-i-1];
|
---|
| 112 | - color = [Math.round(color[0]*255),Math.round(color[1]*255),Math.round(color[2]*255)];
|
---|
| 113 | - cgradient.addColorStop(i/colorbar.length,'rgba('+color.toString()+',1.0)');
|
---|
| 114 | - }
|
---|
| 115 | - ccontext.fillStyle=cgradient;
|
---|
| 116 | - ccontext.fillRect(0,cheightoffset*3/2,cwidth,cheight);
|
---|
| 117 | -
|
---|
| 118 | - //Draw colorbar border
|
---|
| 119 | - ccontext.beginPath();
|
---|
| 120 | - ccontext.lineWidth='1';
|
---|
| 121 | - ccontext.strokeStyle=options.getfieldvalue('colorbarfontcolor','black');
|
---|
| 122 | - ccontext.rect(0,cheightoffset*3/2,cwidth,cheight);
|
---|
| 123 | - ccontext.stroke();
|
---|
| 124 | -
|
---|
| 125 | + for (var i=0; i < colorbar.length; i++) {
|
---|
| 126 | + color = colorbar[colorbar.length-i-1];
|
---|
| 127 | + color = [Math.round(color[0]*255),Math.round(color[1]*255),Math.round(color[2]*255)];
|
---|
| 128 | + cgradient.addColorStop(i/colorbar.length*d+e,'rgba('+color.toString()+',1.0)');
|
---|
| 129 | + }
|
---|
| 130 | + ccontext.fillStyle=cgradient;
|
---|
| 131 | + ccontext.fillRect(a,b,cwidth,cheight);
|
---|
| 132 | +
|
---|
| 133 | + //Draw colorbar border
|
---|
| 134 | + ccontext.beginPath();
|
---|
| 135 | + ccontext.lineWidth='1';
|
---|
| 136 | + ccontext.strokeStyle=options.getfieldvalue('colorbarfontcolor','black');
|
---|
| 137 | + ccontext.rect(a,b,cwidth,cheight);
|
---|
| 138 | + ccontext.stroke();
|
---|
| 139 | +
|
---|
| 140 | + if (colorbarorientiation=='vertical') { //{{{
|
---|
| 141 | for (var i=0; i <= cdivisions; i++) {
|
---|
| 142 | - y = i/cdivisions*cheight+cheightoffset/2;
|
---|
| 143 | + y = i/(cdivisions+g)*cheight+cheightoffset/2;
|
---|
| 144 | x = 0.2*cwidth;
|
---|
| 145 | - ccontext.beginPath();
|
---|
| 146 | - ccontext.moveTo(0,y+cheightoffset);
|
---|
| 147 | - ccontext.lineTo(x,y+cheightoffset);
|
---|
| 148 | - ccontext.moveTo(cwidth-x,y+cheightoffset);
|
---|
| 149 | - ccontext.lineTo(cwidth,y+cheightoffset);
|
---|
| 150 | - ccontext.stroke();
|
---|
| 151 | ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif';
|
---|
| 152 | ccontext.fillStyle=options.getfieldvalue('colorbarfontcolor','black');
|
---|
| 153 | - ccontext.textAlign='left';
|
---|
| 154 | - ccontext.fillText(labels[i],cwidth+x,y+cheightoffset*3/2);
|
---|
| 155 | + ccontext.textAlign=textAlign;
|
---|
| 156 | + ccontext.textBaseline='top';
|
---|
| 157 | + ccontext.fillText(labels[i],h,y+cheightoffset*(g+0.5));
|
---|
| 158 | + ccontext.beginPath();
|
---|
| 159 | + ccontext.moveTo(0,y+cheightoffset*f);
|
---|
| 160 | + ccontext.lineTo(x,y+cheightoffset*f);
|
---|
| 161 | + ccontext.moveTo(cwidth-x,y+cheightoffset*f);
|
---|
| 162 | + ccontext.lineTo(cwidth,y+cheightoffset*f);
|
---|
| 163 | + ccontext.stroke();
|
---|
| 164 | }
|
---|
| 165 | - if (options.exist('colorbartitle')) {
|
---|
| 166 | - ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif';
|
---|
| 167 | - ccontext.fillStyle=options.getfieldvalue('colorbarfontcolor','black');
|
---|
| 168 | - ccontext.textAlign='left';
|
---|
| 169 | - ccontext.textBaseline='bottom';
|
---|
| 170 | - ccontext.fillText(options.getfieldvalue('colorbartitle'),0,cheightoffset);
|
---|
| 171 | - }
|
---|
| 172 | - } //}}}
|
---|
| 173 | - else { //colorbarorientiation=='horizontal' {{{
|
---|
| 174 | - ccanvasid = options.getfieldvalue('colorbarid',options.getfieldvalue('canvasid')+'_colorbar');
|
---|
| 175 | - ccanvashtml = document.getElementById(ccanvasid);
|
---|
| 176 | - cwidth = ccanvashtml.width*0.7*options.getfieldvalue('colorbarwidth',1);
|
---|
| 177 | - cheight = ccanvashtml.height*0.4*options.getfieldvalue('colorbarheight',1);
|
---|
| 178 | - ccanvas = $('#'+ccanvasid);
|
---|
| 179 | - ccontext = ccanvas[0].getContext('2d');
|
---|
| 180 | - ccontext.clearRect(0,0, ccanvashtml.width, ccanvashtml.height);
|
---|
| 181 | - ccontext.beginPath();
|
---|
| 182 | -
|
---|
| 183 | - var cgradient = ccontext.createLinearGradient(cwidth+cwidthoffset,0,cwidthoffset,0);
|
---|
| 184 | - var cmap = options.getfieldvalue('colormap','jet');
|
---|
| 185 | - var colorbar = colorbars[cmap];
|
---|
| 186 | - for (var i=0; i < colorbar.length; i++) {
|
---|
| 187 | - color = colorbar[colorbar.length-i-1];
|
---|
| 188 | - color = [Math.round(color[0]*255),Math.round(color[1]*255),Math.round(color[2]*255)];
|
---|
| 189 | - cgradient.addColorStop(i/colorbar.length,'rgba('+color.toString()+',1.0)');
|
---|
| 190 | - }
|
---|
| 191 | - ccontext.fillStyle=cgradient;
|
---|
| 192 | - ccontext.fillRect(cwidthoffset,cheightoffset,cwidth,cheight);
|
---|
| 193 | -
|
---|
| 194 | - //Draw colorbar border
|
---|
| 195 | - ccontext.beginPath();
|
---|
| 196 | - ccontext.lineWidth='1';
|
---|
| 197 | - ccontext.strokeStyle=options.getfieldvalue('colorbarfontcolor','black');
|
---|
| 198 | - ccontext.rect(cwidthoffset,cheightoffset,cwidth,cheight);
|
---|
| 199 | - ccontext.stroke();
|
---|
| 200 | -
|
---|
| 201 | + }
|
---|
| 202 | + else {
|
---|
| 203 | for (var i=0; i <= cdivisions; i++) {
|
---|
| 204 | y = 0.2*cheight;
|
---|
| 205 | x = i/cdivisions*cwidth;
|
---|
| 206 | + ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif';
|
---|
| 207 | + ccontext.fillStyle=options.getfieldvalue('colorbarfontcolor','black');
|
---|
| 208 | + ccontext.textAlign=textAlign;
|
---|
| 209 | + ccontext.fillText(labels[cdivisions-i],x+cwidthoffset,cheight+cheightoffset*2);
|
---|
| 210 | ccontext.beginPath();
|
---|
| 211 | ccontext.moveTo(x+cwidthoffset,cheightoffset);
|
---|
| 212 | ccontext.lineTo(x+cwidthoffset,y+cheightoffset);
|
---|
| 213 | ccontext.moveTo(x+cwidthoffset,cheight-y+cheightoffset);
|
---|
| 214 | ccontext.lineTo(x+cwidthoffset,cheight+cheightoffset);
|
---|
| 215 | ccontext.stroke();
|
---|
| 216 | - ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif';
|
---|
| 217 | - ccontext.fillStyle=options.getfieldvalue('colorbarfontcolor','black');
|
---|
| 218 | - ccontext.textAlign='center';
|
---|
| 219 | - ccontext.fillText(labels[cdivisions-i],x+cwidthoffset,cheight+cheightoffset*2);
|
---|
| 220 | }
|
---|
| 221 | - if (options.exist('colorbartitle')) {
|
---|
| 222 | - ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif';
|
---|
| 223 | - ccontext.fillStyle=options.getfieldvalue('colorbarfontcolor','black');
|
---|
| 224 | - ccontext.textAlign='center';
|
---|
| 225 | - ccontext.textBaseline='bottom';
|
---|
| 226 | - ccontext.fillText(options.getfieldvalue('colorbartitle'),cwidth/2+cwidthoffset,cheightoffset);
|
---|
| 227 | - }
|
---|
| 228 | + }
|
---|
| 229 | + if (options.exist('colorbartitle')) {
|
---|
| 230 | + ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif';
|
---|
| 231 | + ccontext.fillStyle=options.getfieldvalue('colorbarfontcolor','black');
|
---|
| 232 | + ccontext.textAlign='left';
|
---|
| 233 | + ccontext.textBaseline='bottom';
|
---|
| 234 | + ccontext.fillText(options.getfieldvalue('colorbartitle'),c,cheightoffset);
|
---|
| 235 | } //}}}
|
---|
| 236 | //}}}
|
---|
| 237 | }
|
---|