vis_files/button.js
/// Plots centered text in an area
Plots centered text in an area
Plots centered text in an area
function centertext(text,x,y,font,col,width)        
{
	if(text == undefined) text = "undefined";
	text = text.toString();
	if(text.search("_") == -1 && text.search("^") == -1 && text.search("&") == -1){   
		cv.font = font;
		if(width){
			if(cv.measureText(text).width > width-10){
				while(cv.measureText(text+"...").width > width-10) text = text.substr(0,text.length-1);
				text += "...";
			}	
		}
		cv.textAlign = 'center';
		cv.fillStyle = col;
		cv.fillText(text, x, y);
	}
	else{
		var lab = splitintosub(text,font);
		var w = lab[lab.length-1].w+lab[lab.length-1].dw;
		cv.textAlign = 'left';
		cv.fillStyle = col;
		var j;
		for(j = 0; j < lab.length; j++){
			cv.font = lab[j].font;
			cv.fillText(lab[j].frag,x+lab[j].w-w/2,y+lab[j].dy);
		}
	}
}
function centertext ( text , x , y , font , col , width ) { if ( text == undefined ) text = "undefined" ; text = text . toString ( ) ; if ( text . search ( "_" ) == - 1 && text . search ( "^" ) == - 1 && text . search ( "&" ) == - 1 ) { cv . font = font ; if ( width ) { if ( cv . measureText ( text ) . width > width - 10 ) { while ( cv . measureText ( text + "..." ) . width > width - 10 ) text = text . substr ( 0 , text . length - 1 ) ; text += "..." ; } } cv . textAlign = 'center' ; cv . fillStyle = col ; cv . fillText ( text , x , y ) ; } else { var lab = splitintosub ( text , font ) ; var w = lab [ lab . length - 1 ] . w + lab [ lab . length - 1 ] . dw ; cv . textAlign = 'left' ; cv . fillStyle = col ; var j ; for ( j = 0 ; j < lab . length ; j ++ ) { cv . font = lab [ j ] . font ; cv . fillText ( lab [ j ] . frag , x + lab [ j ] . w - w / 2 , y + lab [ j ] . dy ) ; } } }
Plots centered text in an area
Plots centered text in an area
// looks for subscripts