aboutsummaryrefslogtreecommitdiffstats
path: root/web/nms.gathering.org/ping.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/nms.gathering.org/ping.js')
-rw-r--r--web/nms.gathering.org/ping.js97
1 files changed, 56 insertions, 41 deletions
diff --git a/web/nms.gathering.org/ping.js b/web/nms.gathering.org/ping.js
index ce3d99f..75d8190 100644
--- a/web/nms.gathering.org/ping.js
+++ b/web/nms.gathering.org/ping.js
@@ -22,11 +22,11 @@ function json_request(url, func, repeat_ms) {
}
function get_switches() {
- json_request('/switches-json.pl', draw_switches, 1000);
+ json_request(switches_url, draw_switches, 1000);
}
function get_ping() {
- json_request('/ping-json.pl', update_ping, 1000);
+ json_request(ping_url, update_ping, 1000);
}
function draw_switches(json) {
@@ -53,9 +53,11 @@ function draw_switches(json) {
parseInt(s['height']));
}
- for (var i = 0; i < json['linknets'].length; ++i) {
- var linknet = json['linknets'][i];
- create_linknet(linknet['linknet'], linknet['switch1'], linknet['switch2']);
+ if (draw_linknets) {
+ for (var i = 0; i < json['linknets'].length; ++i) {
+ var linknet = json['linknets'][i];
+ create_linknet(linknet['linknet'], linknet['switch1'], linknet['switch2']);
+ }
}
setTimeout(get_switches, 60000);
@@ -114,9 +116,9 @@ function gradient_from_latency(latency_ms, latency_secondary_ms) {
if (latency_secondary_ms === undefined) {
return rgb_from_latency(latency_ms);
}
- return '-webkit-gradient(linear, left top, left bottom, ' +
- 'from(' + rgb_from_latency(latency_ms) + '), ' +
- 'to(' + rgb_from_latency(latency_secondary_ms) + '))';
+ return 'linear-gradient(' +
+ rgb_from_latency(latency_ms) + ', ' +
+ rgb_from_latency(latency_secondary_ms) + ')';
}
function rgb_from_latency(latency_ms) {
@@ -126,20 +128,31 @@ function rgb_from_latency(latency_ms) {
// 10ms is max
var l = latency_ms / 10.0;
- if (l >= 1.0) { l = 1.0; }
- l = Math.pow(l, 1.0/2.2);
- l = Math.round(l * 255.0);
-
- return 'rgb(' + l + ', 255, 0)';
+ if (l >= 2.0) {
+ return 'rgb(255, 0, 0)';
+ } else if (l >= 1.0) {
+ l = 2.0 - l;
+ l = Math.pow(l, 1.0/2.2);
+ l = Math.round(l * 255.0);
+ return 'rgb(255, ' + l + ', 0)';
+ } else {
+ l = Math.pow(l, 1.0/2.2);
+ l = Math.round(l * 255.0);
+ return 'rgb(' + l + ', 255, 0)';
+ }
}
function really_update_ping(json) {
if (json['switches']) {
for (var switchnum in switches) {
if (json['switches'][switchnum]) {
- switches[switchnum].style.background =
- gradient_from_latency(json['switches'][switchnum]['latency'],
- json['switches'][switchnum]['latency_secondary']);
+ if (json['switches'][switchnum]['color']) {
+ switches[switchnum].style.background = json['switches'][switchnum]['color'];
+ } else {
+ switches[switchnum].style.background =
+ gradient_from_latency(json['switches'][switchnum]['latency'],
+ json['switches'][switchnum]['latency_secondary']);
+ }
} else {
switches[switchnum].style.background = '#0000ff';
}
@@ -190,35 +203,37 @@ function create_switch(switchnum, sysname, x, y, zorder, width, height) {
var dragging_switch = null;
var delta_x = null, delta_y = null;
-document.onmousedown = function(e) {
- var switchnum = e.target.getAttribute("data-switchnum");
- if (switchnum === null) {
- return;
+if (can_edit) {
+ document.onmousedown = function(e) {
+ var switchnum = e.target.getAttribute("data-switchnum");
+ if (switchnum === null) {
+ return;
+ }
+ dragging_switch = switchnum;
+ delta_x = parseInt(e.target.style.left.replace("px", "")) - e.clientX;
+ delta_y = parseInt(e.target.style.top.replace("px", "")) - e.clientY;
}
- dragging_switch = switchnum;
- delta_x = parseInt(e.target.style.left.replace("px", "")) - e.clientX;
- delta_y = parseInt(e.target.style.top.replace("px", "")) - e.clientY;
-}
-document.onmousemove = function(e) {
- if (dragging_switch === null) {
- return;
+ document.onmousemove = function(e) {
+ if (dragging_switch === null) {
+ return;
+ }
+ switches[dragging_switch].style.left = (e.clientX + delta_x) + 'px';
+ switches[dragging_switch].style.top = (e.clientY + delta_y) + 'px';
}
- switches[dragging_switch].style.left = (e.clientX + delta_x) + 'px';
- switches[dragging_switch].style.top = (e.clientY + delta_y) + 'px';
-}
-document.onmouseup = function(e) {
- if (dragging_switch === null) {
- return;
- }
- var x = e.clientX + delta_x - map.getBoundingClientRect().top;
- var y = e.clientY + delta_y - map.getBoundingClientRect().left;
+ document.onmouseup = function(e) {
+ if (dragging_switch === null) {
+ return;
+ }
+ var x = e.clientX + delta_x - map.getBoundingClientRect().top;
+ var y = e.clientY + delta_y - map.getBoundingClientRect().left;
- var request = new XMLHttpRequest();
- request.open('POST', '/change-switch-pos.pl', true);
- request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
- request.send("switch=" + dragging_switch + "&x=" + x + "&y=" + y);
+ var request = new XMLHttpRequest();
+ request.open('POST', '/change-switch-pos.pl', true);
+ request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
+ request.send("switch=" + dragging_switch + "&x=" + x + "&y=" + y);
- dragging_switch = null;
+ dragging_switch = null;
+ }
}