diff options
| author | Kristian Lyngstol <kristian@bohemians.org> | 2015-05-08 12:25:50 +0200 | 
|---|---|---|
| committer | Kristian Lyngstol <kristian@bohemians.org> | 2015-05-08 12:25:50 +0200 | 
| commit | 80c10810cfcb9225eb68b876bc843ea5204dff3d (patch) | |
| tree | 68e2c4b42519dc79c6074b0be2e0e11be02e0e39 /web/nms.gathering.org/nms2/js | |
| parent | b504bf15f738c7ae3633af3dec14148e79b778f7 (diff) | |
| parent | 99bde7c69fb4adf34bfa5450293aec995bc7cb74 (diff) | |
Merge branch 'master' of github.com:tech-server/tgmanage
Diffstat (limited to 'web/nms.gathering.org/nms2/js')
| -rw-r--r-- | web/nms.gathering.org/nms2/js/nms-map-handlers.js | 3 | ||||
| -rw-r--r-- | web/nms.gathering.org/nms2/js/nms.js | 128 | 
2 files changed, 100 insertions, 31 deletions
| diff --git a/web/nms.gathering.org/nms2/js/nms-map-handlers.js b/web/nms.gathering.org/nms2/js/nms-map-handlers.js index 9b2d44c..ddb50a1 100644 --- a/web/nms.gathering.org/nms2/js/nms-map-handlers.js +++ b/web/nms.gathering.org/nms2/js/nms-map-handlers.js @@ -232,11 +232,14 @@ function tempUpdater()  {  	for (sw in nms.switches_now["switches"]) {  		var t = "white"; +		var temp = "";  		if (nms.switches_now["switches"][sw]["temp"]) {  			t = temp_color(nms.switches_now["switches"][sw]["temp"]); +			temp = nms.switches_now["switches"][sw]["temp"] + "°C";  		}  		setSwitchColor(sw, t); +		switchInfoText(sw, temp);  	}  } diff --git a/web/nms.gathering.org/nms2/js/nms.js b/web/nms.gathering.org/nms2/js/nms.js index d4cf4e8..30d6ba8 100644 --- a/web/nms.gathering.org/nms2/js/nms.js +++ b/web/nms.gathering.org/nms2/js/nms.js @@ -7,6 +7,8 @@ var nms = {  	ping_data:undefined, // JSON data for ping history.  	drawn:false, // Set to 'true' when switches are drawn  	switch_showing:"", // Which switch we are displaying (if any). +	switchInfo:{}, +	switchInfoDrawn:{},  	repop_switch:false, // True if we need to repopulate the switch info when port state updates (e.g.: added comments);  	repop_time:false, // Timestamp in case we get a cached result  	nightMode:false,  @@ -23,7 +25,8 @@ var nms = {  	textDrawn:{}, // Have we drawn text for this switch?  	now:false, // Date we are looking at (false for current date).  	fontSize:16, // This is scaled too, but 16 seems to make sense. -	fontFace:"Arial Black", +	fontFace:"Verdana", +	fontLineFactor:3,  	/*  	 * This is used to track outbound AJAX requests and skip updates if  	 * we have too many outstanding requests. The ajaxOverflow is a @@ -203,6 +206,9 @@ function initDrawing() {  	dr['text'] = {};  	dr['text']['c'] = document.getElementById("textCanvas");  	dr['text']['ctx'] = dr['text']['c'].getContext('2d'); +	dr['textInfo'] = {}; +	dr['textInfo']['c'] = document.getElementById("textInfoCanvas"); +	dr['textInfo']['ctx'] = dr['textInfo']['c'].getContext('2d');  	dr['top'] = {};  	dr['top']['c'] = document.getElementById("topCanvas");  	dr['top']['ctx'] = dr['top']['c'].getContext('2d'); @@ -649,6 +655,7 @@ function setUpdater(fo)  {  	nms.updater = undefined;  	resetColors(); +	resetTextInfo();  	fo.init();  	nms.updater = fo;  	var foo = document.getElementById("updater_name"); @@ -932,8 +939,8 @@ function updateSpeed()  	nms.speed = speed_in;  	nms.speed_full = speed_full;  	if (speedele) { -		speedele.innerHTML = byteCount(8 * parseInt(nms.speed)) + "bit/s"; -		speedele.innerHTML += " / " + byteCount(8 * parseInt(nms.speed_full)) + "bit/s"; +		speedele.innerHTML = byteCount(8 * parseInt(nms.speed)) + "b/s"; +		speedele.innerHTML += " / " + byteCount(8 * parseInt(nms.speed_full)) + "b/s";  	}  } @@ -1008,10 +1015,11 @@ function drawSwitch(sw)  		drawBox(box['x'],box['y'],box['width'],box['height']);  		dr.switch.ctx.shadowBlur = 0;  		if (!nms.textDrawn[sw]) { -			if ((box['width'] + 10 )< box['height']) -				drawSideways(sw,box['x'],box['y'],box['width'],box['height']); -			else -				drawRegular(sw,box['x'],box['y'],box['width'],box['height']); +			if ((box['width'] + 10 )< box['height']) { +				drawSideways(dr.text.ctx, sw,box['x'],box['y'],box['width'],box['height']); +			} else { +				drawRegular(dr.text.ctx,sw,box['x'],box['y'],box['width'],box['height']); +			}  			nms.textDrawn[sw] = true;  		} @@ -1046,6 +1054,15 @@ function drawSwitches()  	}  	nms.drawn = true;  } +function drawSwitchInfo() +{ +	if (!nms.switches_now || !nms.switches_now.switches) +		return; +	for (var sw in nms.switchInfo) { +		switchInfoText(sw, nms.switchInfo[sw]); +	} +	nms.drawn = true; +}  /*   * Draw current time-window @@ -1063,9 +1080,9 @@ function drawNow()  	dr.top.ctx.clearRect(0,0,Math.floor(800 * canvas.scale),Math.floor(100 * canvas.scale));  	dr.top.ctx.fillStyle = "white";  	dr.top.ctx.strokeStyle = "black"; -	dr.top.ctx.lineWidth = Math.floor(2 * canvas.scale); +	dr.top.ctx.lineWidth = Math.floor(nms.fontLineFactor * canvas.scale);  	if (dr.top.ctx.lineWidth == 0) { -		dr.top.ctx.lineWidth = Math.round(2 * canvas.scale); +		dr.top.ctx.lineWidth = Math.round(nms.fontLineFactor * canvas.scale);  	}  	dr.top.ctx.strokeText(now, 0 + margin.text, 25 * canvas.scale);  	dr.top.ctx.fillText(now, 0 + margin.text, 25 * canvas.scale); @@ -1083,8 +1100,10 @@ function drawNow()  function drawScene()  {  	dr.text.ctx.font = Math.floor(nms.fontSize * canvas.scale) + "px " + nms.fontFace; +	dr.textInfo.ctx.font = Math.floor(nms.fontSize * canvas.scale) + "px " + nms.fontFace;  	drawLinknets();  	drawSwitches(); +	drawSwitchInfo();  }  /* @@ -1096,11 +1115,17 @@ function setScale()  	canvas.height =  orig.height * canvas.scale ;  	canvas.width = orig.width * canvas.scale ;  	for (var a in dr) { +		/* +		 * Resizing this to a too small size breaks gradients on smaller screens. +		 */ +		if (a == 'hidden') +			continue;  		dr[a].c.height = canvas.height;  		dr[a].c.width = canvas.width;  	}  	nms.nightBlur = {};  	nms.textDrawn = {}; +	nms.switchInfoDrawn = {};  	if (nms.gradients)  		drawGradient(nms.gradients);  	drawBG(); @@ -1192,6 +1217,15 @@ function resetColors()  	}  } +function resetTextInfo() +{ +	if (!nms.switches_now) +		return; +	for (var sw in nms.switches_now.switches) { +		switchInfoText(sw, undefined); +	} + +}  /*   * onclick handler for the canvas.   * @@ -1259,6 +1293,26 @@ function setNightMode(toggle) {  	}  	setScale();  } + +function switchInfoText(sw, text) +{ +	var box = nms.switches_now['switches'][sw]['placement']; +	var c = canvas.scale; +	if (nms.switchInfo[sw] == text && nms.switchInfoDrawn[sw]) { +		return; +	} +	nms.switchInfo[sw] = text; +	nms.switchInfoDrawn[sw] = true; +	dr.textInfo.ctx.clearRect(c* box['x'], c*box['y'], c*box['width'], c*box['height']); +	if (text != undefined && text != "") { +		if ((box['width'] + 10 )< box['height']) { +			drawSideways(dr.textInfo.ctx, text,box['x'],box['y'],box['width'],box['height'],"end"); +		} else { +			drawRegular(dr.textInfo.ctx, text,box['x'],box['y'],box['width'],box['height'],"end"); +		} +	} +} +  /*   * Draw a box (e.g.: switch).   */ @@ -1269,9 +1323,9 @@ function drawBox(x,y,boxw,boxh)  	var myX2 = Math.floor((boxw) * canvas.scale);  	var myY2 = Math.floor((boxh) * canvas.scale);  	dr.switch.ctx.fillRect(myX,myY, myX2, myY2); -	dr.switch.ctx.lineWidth = Math.floor(0.5 * canvas.scale); +	dr.switch.ctx.lineWidth = Math.floor(1.0 * canvas.scale);  	if (canvas.scale < 1.0) { -		dr.switch.ctx.lineWidth = 0.5; +		dr.switch.ctx.lineWidth = 1.0;  	}  	dr.switch.ctx.strokeStyle = "#000000";  	dr.switch.ctx.strokeRect(myX,myY, myX2, myY2); @@ -1293,19 +1347,25 @@ function drawBoxBlur(x,y,boxw,boxh)   *   * XXX: This is pretty nasty and should also probably take a box as input.   */ -function drawSideways(text,x,y,w,h) +function drawSideways(ctx,text,x,y,w,h,align)  { -	dr.text.ctx.rotate(Math.PI * 3 / 2); -	dr.text.ctx.fillStyle = "white"; -	dr.text.ctx.strokeStyle = "black"; -	dr.text.ctx.lineWidth = Math.floor(3 * canvas.scale); -	if (dr.text.ctx.lineWidth == 0) { -		dr.text.ctx.lineWidth = Math.round(3 * canvas.scale); +	ctx.rotate(Math.PI * 3 / 2); +	ctx.fillStyle = "white"; +	ctx.strokeStyle = "black"; +	if (align == "end") { +		ctx.textAlign = align; +		y = y-h + margin.text*2; +	} else { +		ctx.textAlign = "start"; +	} +	ctx.lineWidth = Math.floor(nms.fontLineFactor * canvas.scale); +	if (ctx.lineWidth == 0) { +		ctx.lineWidth = Math.round(nms.fontLineFactor * canvas.scale);  	} -	dr.text.ctx.strokeText(text, - canvas.scale * (y + h - margin.text),canvas.scale * (x + w - margin.text) ); -	dr.text.ctx.fillText(text, - canvas.scale * (y + h - margin.text),canvas.scale * (x + w - margin.text) ); +	ctx.strokeText(text, - canvas.scale * (y + h - margin.text),canvas.scale * (x + w - margin.text) ); +	ctx.fillText(text, - canvas.scale * (y + h - margin.text),canvas.scale * (x + w - margin.text) ); -	dr.text.ctx.rotate(Math.PI / 2); +	ctx.rotate(Math.PI / 2);  }  /* @@ -1336,16 +1396,22 @@ function invertCanvas() {   *   * XXX: Both should be renamed to have 'text' or something in them   */ -function drawRegular(text,x,y,w,h) { - -	dr.text.ctx.fillStyle = "white"; -	dr.text.ctx.strokeStyle = "black"; -	dr.text.ctx.lineWidth = Math.floor(3 * canvas.scale); -	if (dr.text.ctx.lineWidth == 0) { -		dr.text.ctx.lineWidth = Math.round(3 * canvas.scale); +function drawRegular(ctx,text,x,y,w,h,align) { + +	ctx.fillStyle = "white"; +	ctx.strokeStyle = "black"; +	ctx.lineWidth = Math.floor(nms.fontLineFactor * canvas.scale); +	if (align == "end") { +		ctx.textAlign = align; +		x = x+w - margin.text*2; +	} else { +		ctx.textAlign = "start"; +	} +	if (ctx.lineWidth == 0) { +		ctx.lineWidth = Math.round(nms.fontLineFactor * canvas.scale);  	} -	dr.text.ctx.strokeText(text, (x + margin.text) * canvas.scale, (y + h - margin.text) * canvas.scale); -	dr.text.ctx.fillText(text, (x + margin.text) * canvas.scale, (y + h - margin.text) * canvas.scale); +	ctx.strokeText(text, (x + margin.text) * canvas.scale, (y + h - margin.text) * canvas.scale); +	ctx.fillText(text, (x + margin.text) * canvas.scale, (y + h - margin.text) * canvas.scale);  }  /* @@ -1397,7 +1463,7 @@ function initNMS() {  	nms.timers.ping = new nmsTimer(updatePing, 1000, "Ping updater", "AJAX request to update ping data");  	nms.timers.ping.start(); -	nms.timers.replay = new nmsTimer(timeReplay, 500, "Time machine", "Handler used to change time"); +	nms.timers.replay = new nmsTimer(timeReplay, 1000, "Time machine", "Handler used to change time");  	detectHandler();  	updatePorts();  	updatePing(); | 
