Index: /issm/trunk-jpl/src/m/plot/applyoptions.js
===================================================================
--- /issm/trunk-jpl/src/m/plot/applyoptions.js	(revision 19857)
+++ /issm/trunk-jpl/src/m/plot/applyoptions.js	(revision 19858)
@@ -138,51 +138,176 @@
 			var caxis = options.getfieldvalue('caxis',[Math.min.apply(null,data),Math.max.apply(null,data)]);
 			var canvassize = options.getfieldvalue('canvassize',480);
-			var cheight = options.getfieldvalue('colorbarheight',0.95)*canvassize;
-			var cwidth = options.getfieldvalue('colorbarwidth',canvassize/20);
+			var cheight;
+			var cwidth;
 			var cdivisions = cheight/4;
 			var color;
+			var ccontext,ccanvas,ccanvasid,ccanvashtml;
+			var colorbarorientiation = options.getfieldvalue('colorbarorientation','vertical');
+			//define offsets for correct font drawing on canvas
 			var cheightoffset = options.getfieldvalue('colorbarfontsize',16);
-			var ccontext,ccanvas,ccanvasid,ccanvashtml;
-			ccanvasid = options.getfieldvalue('colorbarcanvasid',options.getfieldvalue('canvasid')+'_colorbar');
-			ccanvashtml = document.getElementById(ccanvasid);
-			if (ccanvashtml==null) {
-				ccanvas = $('<canvas id="'+ccanvasid+'" width="'+String(cwidth+cheightoffset*4)+'" height="'+String(cheight+cheightoffset)+'"></canvas>').insertAfter('#'+options.getfieldvalue('canvasid'));
-				ccanvas.css({'position':'relative','top':((canvassize-cheight-cheightoffset)/-2).toFixed(2)+'px'});
-				ccontext = ccanvas[0].getContext('2d');
-			}
-			else{
-				ccanvas = $('#'+ccanvasid);
-				if (options.exist('colorbarcanvasid')&&!ccanvashtml.hasOwnProperty('init')){
-					//store actual colobar size
-					cwidth = ccanvas.width();
-					cheight = ccanvas.height();
-					//get html object instead of jqurey object to modify height/width to accomodate labels
-					ccanvashtml.width = ccanvas.width()+cheightoffset*6;
-					ccanvashtml.height = cheight+cheightoffset;
-					ccanvashtml.cwidth = cwidth;
-					ccanvashtml.cheight = cheight;
-					ccanvashtml.init = true;
-				}
-				else {
-					cwidth = ccanvashtml.cwidth;
-					cheight = ccanvashtml.cheight;
-				}
-				ccontext = ccanvas[0].getContext('2d');
-				/*erase existing colorbar:*/
-				ccontext.clearRect(0,0, cwidth*4, cheight+cheightoffset);
+			var cwidthoffset = options.getfieldvalue('colorbarfontsize',16)*3;
+			
+			//Set colorbar lables
+			var labels = [];
+			var cdivisions = options.getfieldvalue('colorbarnticks',6);
+			var caxisdelta = caxis[1] - caxis[0];
+			var clabelitem;
+			var precision=options.getfieldvalue('colorbarprecision',3);
+			if (options.exist('log')) {
+				for (var i = cdivisions; i >= 0; i--) {
+					if (caxisdelta*i/cdivisions==min) {
+						labels[i] = (caxis[0]).toPrecision(precision);
+					}
+					else {
+						labels[i] = (Math.exp(Math.log(caxisdelta)*i/cdivisions)+caxis[0]).toPrecision(precision);
+					}	
+				}
+			} else {
+				for (var i = cdivisions; i >= 0; i--) {
+					labels[i] = (caxisdelta*(cdivisions-i)/cdivisions+caxis[0]).toPrecision(precision);
+				}
+			}
+			var y;
+			var x;
+			
+			if (colorbarorientiation=='vertical') {
+				cheight = options.getfieldvalue('colorbarheight',0.95)*canvassize;
+				cwidth = options.getfieldvalue('colorbarwidth',canvassize/20);
+				ccanvasid = options.getfieldvalue('colorbarcanvasid',options.getfieldvalue('canvasid')+'_colorbar');
+				ccanvashtml = document.getElementById(ccanvasid);
+				if (ccanvashtml==null) {
+					ccanvas = $('<canvas id="'+ccanvasid+'" width="'+String(cwidth+cheightoffset*4)+'" height="'+String(cheight+cheightoffset)+'"></canvas>').insertAfter('#'+options.getfieldvalue('canvasid'));
+					ccanvas.css({'position':'relative','top':((canvassize-cheight-cheightoffset)/-2).toFixed(2)+'px'});
+					ccontext = ccanvas[0].getContext('2d');
+				}
+				else{
+					ccanvas = $('#'+ccanvasid);
+					if (options.exist('colorbarcanvasid')&&!ccanvashtml.hasOwnProperty('init')){
+						//store actual colobar size
+						cwidth = ccanvas.width();
+						cheight = ccanvas.height();
+						//get html object instead of jqurey object to modify height/width to accomodate labels
+						ccanvashtml.width = ccanvas.width()+cheightoffset*6;
+						ccanvashtml.height = cheight+cheightoffset;
+						ccanvashtml.cwidth = cwidth;
+						ccanvashtml.cheight = cheight;
+						ccanvashtml.init = true;
+					}
+					else {
+						cwidth = ccanvashtml.cwidth;
+						cheight = ccanvashtml.cheight;
+					}
+					ccontext = ccanvas[0].getContext('2d');
+					/*erase existing colorbar:*/
+					ccontext.clearRect(0,0, cwidth*4, cheight+cheightoffset);
+					ccontext.beginPath();
+				}
+				var cgradient = ccontext.createLinearGradient(0,cheightoffset/2,0,cheight);
+				var tgradient = ccontext.createLinearGradient(0,0,0,256);
+				
+				var cmap = options.getfieldvalue('cmap','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)');
+					tgradient.addColorStop(i/colorbar.length,'rgba('+color.toString()+',1.0)');
+				}
+				ccontext.fillStyle=cgradient;
+				ccontext.fillRect(0,cheightoffset/2,cwidth,cheight);
+				
+				
+				//Draw colorbar border
 				ccontext.beginPath();
-			}
-			var cgradient = ccontext.createLinearGradient(0,cheightoffset/2,0,cheight);
-			var tgradient = ccontext.createLinearGradient(0,0,0,256);
-			var cmap = options.getfieldvalue('cmap','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)');
-				tgradient.addColorStop(i/colorbar.length,'rgba('+color.toString()+',1.0)');
-			}
-			ccontext.fillStyle=cgradient;
-			ccontext.fillRect(0,cheightoffset/2,cwidth,cheight);
+				ccontext.lineWidth='1';
+				ccontext.strokeStyle='black';
+				ccontext.rect(0,cheightoffset/2,cwidth,cheight);
+				ccontext.stroke();
+				
+				for (var i = 0; i <= cdivisions; i++) {
+					y = i/cdivisions*cheight+cheightoffset/2;
+					x = 0.2*cwidth;
+					ccontext.beginPath();
+					ccontext.moveTo(0,y);
+					ccontext.lineTo(x,y);
+					ccontext.moveTo(cwidth-x,y);
+					ccontext.lineTo(cwidth,y);
+					ccontext.stroke();
+					ccontext.font=String(options.getfieldvalue('colorbarfontsize',16))+'px Arial';
+					ccontext.fillStyle='black';
+					ccontext.textAlign='left';
+					ccontext.fillText(labels[i],cwidth+x,y+cheightoffset/2);
+				}
+			}
+			else { //colorbarorientiation=='horizontal'
+				cheight = options.getfieldvalue('colorbarheight',canvassize/20);
+				cwidth = options.getfieldvalue('colorbarwidth',0.95)*canvassize;
+				ccanvasid = options.getfieldvalue('colorbarcanvasid',options.getfieldvalue('canvasid')+'_colorbar');
+				ccanvashtml = document.getElementById(ccanvasid);
+				if (ccanvashtml==null) {
+					ccanvas = $('<canvas id="'+ccanvasid+'" width="'+String(cwidth+cheightoffset*4)+'" height="'+String(cheight+cheightoffset)+'"></canvas>').insertAfter('#'+options.getfieldvalue('canvasid'));
+					ccanvas.css({'position':'relative','top':((canvassize-cheight-cheightoffset)/-2).toFixed(2)+'px'});
+					ccontext = ccanvas[0].getContext('2d');
+				}
+				else{
+					ccanvas = $('#'+ccanvasid);
+					if (options.exist('colorbarcanvasid')&&!ccanvashtml.hasOwnProperty('init')){
+						//store actual colobar size
+						cwidth = ccanvas.width();
+						cheight = ccanvas.height();
+						//get html object instead of jqurey object to modify height/width to accomodate labels
+						ccanvashtml.width = cwidth+cheightoffset*6;
+						ccanvashtml.height = cheight+cheightoffset;
+						ccanvashtml.cwidth = cwidth;
+						ccanvashtml.cheight = cheight;
+						ccanvashtml.init = true;
+					}
+					else {
+						cwidth = ccanvashtml.cwidth;
+						cheight = ccanvashtml.cheight;
+					}
+					ccontext = ccanvas[0].getContext('2d');
+					/*erase existing colorbar:*/
+					ccontext.clearRect(0,0, cwidth*4, cheight+cheightoffset);
+					ccontext.beginPath();
+				}
+				var cgradient = ccontext.createLinearGradient(cwidth+cwidthoffset,0,cwidthoffset,0);
+				var tgradient = ccontext.createLinearGradient(cwidthoffset,0,0,256);
+				
+				var cmap = options.getfieldvalue('cmap','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)');
+					tgradient.addColorStop(i/colorbar.length,'rgba('+color.toString()+',1.0)');
+				}
+				ccontext.fillStyle=cgradient;
+				ccontext.fillRect(cwidthoffset,0,cwidth,cheight);
+				
+				
+				//Draw colorbar border
+				ccontext.beginPath();
+				ccontext.lineWidth='1';
+				ccontext.strokeStyle='black';
+				ccontext.rect(cwidthoffset,0,cwidth,cheight);
+				ccontext.stroke();
+				
+				for (var i = 0; i <= cdivisions; i++) {
+					y = 0.2*cheight;
+					x = i/cdivisions*cwidth;
+					ccontext.beginPath();
+					ccontext.moveTo(x+cwidthoffset,0);
+					ccontext.lineTo(x+cwidthoffset,y);
+					ccontext.moveTo(x+cwidthoffset,cheight-y);
+					ccontext.lineTo(x+cwidthoffset,cheight);
+					ccontext.stroke();
+					ccontext.font=String(options.getfieldvalue('colorbarfontsize',16))+'px Arial';
+					ccontext.fillStyle='black';
+					ccontext.textAlign='center';
+					ccontext.fillText(labels[cdivisions-i],x+cwidthoffset,cheight+cheightoffset);
+				}
+			}
+			
 			//Make texture canvas
 			var tcontext,tcanvas,tcanvasid,tcanvashtml,tURL;
@@ -202,45 +327,4 @@
 			tURL = tcanvashtml.toDataURL();
 			node["texture"] = initTexture(gl,tURL);
-			//Draw colorbar border
-			ccontext.beginPath();
-			ccontext.lineWidth='1';
-			ccontext.strokeStyle='black';
-			ccontext.rect(0,cheightoffset/2,cwidth,cheight);
-			ccontext.stroke();
-			//Set colorbar lables
-			var labels = [];
-			var cdivisions = options.getfieldvalue('colorbarnticks',6);
-			var caxisdelta = caxis[1] - caxis[0];
-			var clabelitem;
-			precision=options.getfieldvalue('colorbarprecision',3);
-			if (options.exist('log')) {
-				for (var i = cdivisions; i >= 0; i--) {
-					if (caxisdelta*i/cdivisions==min) {
-						labels[i] = (caxis[0]).toPrecision(precision);
-					}
-					else {
-						labels[i] = (Math.exp(Math.log(caxisdelta)*i/cdivisions)+caxis[0]).toPrecision(precision);
-					}	
-				}
-			} else {
-				for (var i = cdivisions; i >= 0; i--) {
-					labels[i] = (caxisdelta*(cdivisions-i)/cdivisions+caxis[0]).toPrecision(precision);
-				}
-			}
-			for (var i = cdivisions; i >= 0; i--) {
-				var y = i/cdivisions*cheight+cheightoffset/2;
-				var x = 0.2*cwidth;
-				ccontext.beginPath();
-				ccontext.moveTo(0,y);
-				ccontext.lineTo(x,y);
-				ccontext.moveTo(cwidth-x,y);
-				ccontext.lineTo(cwidth,y);
-				ccontext.stroke();
-				ccontext.font=String(options.getfieldvalue('colorbarfontsize',16))+'px Arial';
-				ccontext.fillStyle='black';
-				ccontext.textAlign='left';
-				ccontext.fillText(labels[i],cwidth+x,y+cheightoffset/2);
-
-			}
 			/* //{{{
 			if exist(options,'wrapping')
