Index: ../trunk-jpl/src/m/plot/webgl.js =================================================================== --- ../trunk-jpl/src/m/plot/webgl.js (revision 20789) +++ ../trunk-jpl/src/m/plot/webgl.js (revision 20790) @@ -334,8 +334,14 @@ var deltaX = (canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth / canvas.zoom * -2 * canvas.controlsensitivity; var deltaY = (canvas.lastDeltaY - ev.deltaY) / canvas.clientHeight / canvas.zoom * -2 * canvas.controlsensitivity; - canvas.translation[0] += Math.cos(radians(canvas.rotation[0])) * deltaX - Math.sin(radians(canvas.rotation[0])) * deltaY; - canvas.translation[1] += Math.sin(radians(canvas.rotation[0])) * deltaX + Math.cos(radians(canvas.rotation[0])) * deltaY; + if (canvas.twod) { + canvas.translation[0] += Math.cos(radians(canvas.rotation[0])) * deltaX - Math.sin(radians(0)) * deltaY; + canvas.translation[1] += Math.sin(radians(canvas.rotation[0])) * deltaX + Math.cos(radians(0)) * deltaY; + } + else { + canvas.translation[0] += Math.cos(radians(canvas.rotation[0])) * deltaX - Math.sin(radians(canvas.rotation[0])) * deltaY; + canvas.translation[1] += Math.sin(radians(canvas.rotation[0])) * deltaX + Math.cos(radians(canvas.rotation[0])) * deltaY; + } } else { canvas.rotation[0] += degrees((canvas.lastDeltaX - ev.deltaX) / canvas.clientWidth / canvas.zoom * -2 * canvas.controlsensitivity); Index: ../trunk-jpl/src/m/plot/plotdoc.js =================================================================== --- ../trunk-jpl/src/m/plot/plotdoc.js (revision 20789) +++ ../trunk-jpl/src/m/plot/plotdoc.js (revision 20790) @@ -23,6 +23,7 @@ console.log(' "colorbarnticks": number of colorbar ticks (default 6, ex: 2, 10)'); console.log(' "colorbarprecision": colorbar label digit precision (default 3, ex: 1, 4)'); console.log(' "colorbarorientation": oreintation of colorbar (default "vertical", ex: "horizontal")'); + console.log(' "colorbarinnerlabels": choose whether labels are inside colorbar (default "off", ex: "on", "off")'); console.log(' "colorbarfontsize": specify colorbar font size (default 1, ex: 14, 22)'); console.log(' "colorbarfontcolor": specify colorbar font color (default "black", ex: "green","blue")'); console.log(' "colorbarwidth": multiplier (default 1) to the default width colorbar'); Index: ../trunk-jpl/src/m/plot/applyoptions.js =================================================================== --- ../trunk-jpl/src/m/plot/applyoptions.js (revision 20789) +++ ../trunk-jpl/src/m/plot/applyoptions.js (revision 20790) @@ -16,11 +16,12 @@ //Variable options initialization {{{ var caxis = options.getfieldvalue('caxis',[ArrayMin(data),ArrayMax(data)]); var colorbarorientiation = options.getfieldvalue('colorbarorientation','vertical'); + var colorbarinnerlabels = options.getfieldvalue('colorbarinnerlabels','off'); var cheightoffset = options.getfieldvalue('colorbarfontsize',18); var cwidthoffset = options.getfieldvalue('colorbarfontsize',18)*3; var cwidthscale = 0.5; //Default size of actual colorbar width, relative to canvas width (range [0,1]) var cheightscale = 0.875; //Default size of actual colorbar height, relative to canvas height (range [0,1]) - var ccontext,ccanvas,ccanvasid,ccanvashtml,cheight,cwidth,color,y,x; + var ccontext,ccanvas,ccanvasid,ccanvashtml,cheight,cwidth,color,y,x,cgradient,cmap,colorbar,textAlign,a,b,c,d,e,f,g,h; //}}} //Set colorbar lables {{{ var labels = []; @@ -38,106 +39,104 @@ labels[i] = (caxisdelta*(cdivisions-i)/cdivisions+caxis[0]).toPrecision(precision); } } //}}} + ccanvasid = options.getfieldvalue('colorbarid',options.getfieldvalue('canvasid')+'_colorbar'); + ccanvashtml = document.getElementById(ccanvasid); + ccanvas = $('#'+ccanvasid); + ccontext = ccanvas[0].getContext('2d'); + ccontext.clearRect(0,0, ccanvashtml.width, ccanvashtml.height); + ccontext.beginPath(); + cmap = options.getfieldvalue('colormap','jet'); + colorbar = colorbars[cmap]; //Handle orientation {{{ - if (colorbarorientiation=='vertical') { //{{{ - ccanvasid = options.getfieldvalue('colorbarid',options.getfieldvalue('canvasid')+'_colorbar'); - ccanvashtml = document.getElementById(ccanvasid); + if (colorbarorientiation=='vertical') { cwidth = ccanvashtml.width*cwidthscale*options.getfieldvalue('colorbarwidth',1); cheight = ccanvashtml.height*cheightscale*options.getfieldvalue('colorbarheight',1); - ccanvas = $('#'+ccanvasid); - ccontext = ccanvas[0].getContext('2d'); - ccontext.clearRect(0,0, ccanvashtml.width, ccanvashtml.height); - ccontext.beginPath(); + cgradient = ccontext.createLinearGradient(0,cheightoffset/2,0,cheight); + textAlign = 'left'; + a = 0; + b = cheightoffset*3/2; + c = 0; + } + else { + cwidth = ccanvashtml.width*0.7*options.getfieldvalue('colorbarwidth',1); + cheight = ccanvashtml.height*0.4*options.getfieldvalue('colorbarheight',1); + cgradient = ccontext.createLinearGradient(cwidth+cwidthoffset,0,cwidthoffset,0); + textAlign = 'center'; + a = cwidthoffset; + b = cheightoffset; + c = cwidth/2+cwidthoffset; + } //}}} + //Handle internal labels {{{ + if (colorbarinnerlabels=='on') { + textAlign = 'center'; + d = (cdivisions/(cdivisions+1.0)); + e = (1.0/(cdivisions+1.0)); + f = 2; + g = 1; + h = cwidth/2; + } + else { + d = 1; + e = 0; + f = 1; + g = 0; + h = cwidth+0.2*cwidth; + } //}}} - var cgradient = ccontext.createLinearGradient(0,cheightoffset/2,0,cheight); - var cmap = options.getfieldvalue('colormap','jet'); - var colorbar = colorbars[cmap]; - for (var i=0; i < colorbar.length; i++) { - color = colorbar[colorbar.length-i-1]; - color = [Math.round(color[0]*255),Math.round(color[1]*255),Math.round(color[2]*255)]; - cgradient.addColorStop(i/colorbar.length,'rgba('+color.toString()+',1.0)'); - } - ccontext.fillStyle=cgradient; - ccontext.fillRect(0,cheightoffset*3/2,cwidth,cheight); - - //Draw colorbar border - ccontext.beginPath(); - ccontext.lineWidth='1'; - ccontext.strokeStyle=options.getfieldvalue('colorbarfontcolor','black'); - ccontext.rect(0,cheightoffset*3/2,cwidth,cheight); - ccontext.stroke(); - + for (var i=0; i < colorbar.length; i++) { + color = colorbar[colorbar.length-i-1]; + color = [Math.round(color[0]*255),Math.round(color[1]*255),Math.round(color[2]*255)]; + cgradient.addColorStop(i/colorbar.length*d+e,'rgba('+color.toString()+',1.0)'); + } + ccontext.fillStyle=cgradient; + ccontext.fillRect(a,b,cwidth,cheight); + + //Draw colorbar border + ccontext.beginPath(); + ccontext.lineWidth='1'; + ccontext.strokeStyle=options.getfieldvalue('colorbarfontcolor','black'); + ccontext.rect(a,b,cwidth,cheight); + ccontext.stroke(); + + if (colorbarorientiation=='vertical') { //{{{ for (var i=0; i <= cdivisions; i++) { - y = i/cdivisions*cheight+cheightoffset/2; + y = i/(cdivisions+g)*cheight+cheightoffset/2; x = 0.2*cwidth; - ccontext.beginPath(); - ccontext.moveTo(0,y+cheightoffset); - ccontext.lineTo(x,y+cheightoffset); - ccontext.moveTo(cwidth-x,y+cheightoffset); - ccontext.lineTo(cwidth,y+cheightoffset); - ccontext.stroke(); ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif'; ccontext.fillStyle=options.getfieldvalue('colorbarfontcolor','black'); - ccontext.textAlign='left'; - ccontext.fillText(labels[i],cwidth+x,y+cheightoffset*3/2); + ccontext.textAlign=textAlign; + ccontext.textBaseline='top'; + ccontext.fillText(labels[i],h,y+cheightoffset*(g+0.5)); + ccontext.beginPath(); + ccontext.moveTo(0,y+cheightoffset*f); + ccontext.lineTo(x,y+cheightoffset*f); + ccontext.moveTo(cwidth-x,y+cheightoffset*f); + ccontext.lineTo(cwidth,y+cheightoffset*f); + ccontext.stroke(); } - if (options.exist('colorbartitle')) { - ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif'; - ccontext.fillStyle=options.getfieldvalue('colorbarfontcolor','black'); - ccontext.textAlign='left'; - ccontext.textBaseline='bottom'; - ccontext.fillText(options.getfieldvalue('colorbartitle'),0,cheightoffset); - } - } //}}} - else { //colorbarorientiation=='horizontal' {{{ - ccanvasid = options.getfieldvalue('colorbarid',options.getfieldvalue('canvasid')+'_colorbar'); - ccanvashtml = document.getElementById(ccanvasid); - cwidth = ccanvashtml.width*0.7*options.getfieldvalue('colorbarwidth',1); - cheight = ccanvashtml.height*0.4*options.getfieldvalue('colorbarheight',1); - ccanvas = $('#'+ccanvasid); - ccontext = ccanvas[0].getContext('2d'); - ccontext.clearRect(0,0, ccanvashtml.width, ccanvashtml.height); - ccontext.beginPath(); - - var cgradient = ccontext.createLinearGradient(cwidth+cwidthoffset,0,cwidthoffset,0); - var cmap = options.getfieldvalue('colormap','jet'); - var colorbar = colorbars[cmap]; - for (var i=0; i < colorbar.length; i++) { - color = colorbar[colorbar.length-i-1]; - color = [Math.round(color[0]*255),Math.round(color[1]*255),Math.round(color[2]*255)]; - cgradient.addColorStop(i/colorbar.length,'rgba('+color.toString()+',1.0)'); - } - ccontext.fillStyle=cgradient; - ccontext.fillRect(cwidthoffset,cheightoffset,cwidth,cheight); - - //Draw colorbar border - ccontext.beginPath(); - ccontext.lineWidth='1'; - ccontext.strokeStyle=options.getfieldvalue('colorbarfontcolor','black'); - ccontext.rect(cwidthoffset,cheightoffset,cwidth,cheight); - ccontext.stroke(); - + } + else { for (var i=0; i <= cdivisions; i++) { y = 0.2*cheight; x = i/cdivisions*cwidth; + ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif'; + ccontext.fillStyle=options.getfieldvalue('colorbarfontcolor','black'); + ccontext.textAlign=textAlign; + ccontext.fillText(labels[cdivisions-i],x+cwidthoffset,cheight+cheightoffset*2); ccontext.beginPath(); ccontext.moveTo(x+cwidthoffset,cheightoffset); ccontext.lineTo(x+cwidthoffset,y+cheightoffset); ccontext.moveTo(x+cwidthoffset,cheight-y+cheightoffset); ccontext.lineTo(x+cwidthoffset,cheight+cheightoffset); ccontext.stroke(); - ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif'; - ccontext.fillStyle=options.getfieldvalue('colorbarfontcolor','black'); - ccontext.textAlign='center'; - ccontext.fillText(labels[cdivisions-i],x+cwidthoffset,cheight+cheightoffset*2); } - if (options.exist('colorbartitle')) { - ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif'; - ccontext.fillStyle=options.getfieldvalue('colorbarfontcolor','black'); - ccontext.textAlign='center'; - ccontext.textBaseline='bottom'; - ccontext.fillText(options.getfieldvalue('colorbartitle'),cwidth/2+cwidthoffset,cheightoffset); - } + } + if (options.exist('colorbartitle')) { + ccontext.font=String(options.getfieldvalue('colorbarfontsize',18))+'px "Lato",Helvetica,Arial,sans-serif'; + ccontext.fillStyle=options.getfieldvalue('colorbarfontcolor','black'); + ccontext.textAlign='left'; + ccontext.textBaseline='bottom'; + ccontext.fillText(options.getfieldvalue('colorbartitle'),c,cheightoffset); } //}}} //}}} }