App-Netdisco
view release on metacpan or search on metacpan
share/views/js/netmap.js view on Meta::CPAN
// this handler rather than a second one that would replace it
fg.onEngineTick(function () {
ticksSinceStop++;
setSpinnerState('nd_netmap-running');
});
// labels draw above this zoom
var LABEL_ZOOM = +'[% settings.netmap.node_label_zoom_threshold || 0.9 %]';
var LABEL_SIZE = +'[% settings.netmap.node_label_font_size || 8 %]';
// read once, not once per node per frame
var showips = document.getElementById('nd_showips');
fg.nodeCanvasObjectMode(function () { return 'after' })
.nodeCanvasObject(function (n, ctx, scale) {
if (n.selected) {
ctx.beginPath();
ctx.arc(n.x, n.y, n.radius + 2, 0, 2 * Math.PI);
ctx.strokeStyle = '#0d6efd';
ctx.lineWidth = 1.5 / scale;
ctx.stroke();
}
if (scale < LABEL_ZOOM) { return }
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
ctx.fillStyle = '#333';
// Drawn from the two fields rather than splitting LABEL: a device name
// may contain spaces, and a two-word split drops the rest of it.
var gap = LABEL_SIZE * 0.5; // graph units, so it holds as the map zooms
ctx.font = 'bold ' + LABEL_SIZE + 'px sans-serif';
ctx.fillText(n.ORIG_LABEL, n.x, n.y + n.radius + gap);
if (showips && showips.checked && n.ORIG_LABEL !== n.ID) {
ctx.font = LABEL_SIZE + 'px sans-serif';
ctx.fillText(n.ID, n.x, n.y + n.radius + gap + LABEL_SIZE + 1);
}
});
// read once, not once per link per frame
var showspeed = document.getElementById('nd_showspeed');
fg.linkCanvasObjectMode(function () { return 'after' })
.linkCanvasObject(function (l, ctx) {
if (!showspeed || !showspeed.checked) { return }
if (typeof l.source !== 'object') { return }
ctx.font = '[% settings.netmap.link_label_font_size || 5 %]px sans-serif';
ctx.textAlign = 'center';
ctx.fillStyle = 'black';
ctx.fillText(l.SPEED, (l.source.x + l.target.x) / 2, (l.source.y + l.target.y) / 2);
});
// the old renderer's legend included ROOTNODE (its distinctNodeColorValues
// list has no special case for it); '__plain' stays excluded, but it is
// unreachable here anyway, since the legend only renders for colorby=hgroup
// or colorby=lgroup, and both always give every node a COLORVALUE (falling
// back to 'Other' rather than leaving it unset)
var legend = document.getElementById('nd2_netmap-legend');
if (legend) {
// Object.keys is arrival order in the payload, and a long unsorted list in
// a scroller cannot be read by eye
Object.keys(colorOf).sort(function (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
}).forEach(function (key) {
if (key === '__plain') { return }
var row = document.createElement('div');
// the row clips to one line, and long site codes share their leading
// 80 characters, so the title is the only way to tell those rows apart
row.title = key;
row.innerHTML = '<span style="color:' + colorOf[key] + '">■</span> ';
row.appendChild(document.createTextNode(key));
legend.appendChild(row);
});
}
});
// ***********************************************
// ************ full screen handling *************
// ***********************************************
function isFullScreen() {
return (document.webkitFullscreenElement || document.mozFullScreenElement || document.fullscreenElement);
}
function requestFullScreen(elt) {
if (isFullScreen()) {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
else {
if (elt.requestFullscreen) {
elt.requestFullscreen();
} else if (elt.msRequestFullscreen) {
elt.msRequestFullscreen();
} else if (elt.mozRequestFullScreen) {
elt.mozRequestFullScreen();
} else if (elt.webkitRequestFullscreen) {
elt.webkitRequestFullscreen();
}
}
}
( run in 0.366 second using v1.01-cache-2.11-cpan-ff9377addf4 )