58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
<script>
|
|
|
|
// custom resize function as there is no event to fire and we need
|
|
// to react to the sidebar.
|
|
$.getJSON('[% uri_for('/ajax/data/device/netmap') %]', {q: '[% params.q %]'}, function(mapdata) {
|
|
|
|
function resizeGraphContainer() {
|
|
setTimeout(function(){
|
|
var netmap_pane = jQuery('#netmap_pane');
|
|
graph.width( parseInt(netmap_pane.parent().css('width')) ).resume();
|
|
graph.height( window.innerHeight - 100 ).resume();
|
|
}, 500)
|
|
}
|
|
|
|
jQuery(document).ready(function() {
|
|
window.graph = netGobrechtsD3Force('netmap_pane')
|
|
.debug(true)
|
|
.lassoMode(true)
|
|
.nodeEventToOpenLink('click')
|
|
.nodeLinkTarget('none')
|
|
.labelDistance(2)
|
|
.zoomMode(true)
|
|
.pinMode(true)
|
|
.showLinkDirection(false)
|
|
.preventLabelOverlappingOnForceEnd(true)
|
|
// .zoomToFitOnForceEnd(true)
|
|
.width( parseInt(jQuery('#netmap_pane').parent().css('width')) )
|
|
.height( window.innerHeight - 100 )
|
|
.showSelfLinks(true)
|
|
.minZoomFactor(0.1)
|
|
.maxZoomFactor(10);
|
|
|
|
jQuery('#nd_sidebar-toggle-img-in').on("click", resizeGraphContainer);
|
|
jQuery('#nd_sidebar-toggle-img-out').on("click", resizeGraphContainer);
|
|
jQuery(window).on("resize", resizeGraphContainer);
|
|
|
|
var netmapdata = {'data': {
|
|
'nodes': mapdata['v4']['nodes'].map(function(node) {
|
|
var index = node['index'];
|
|
return mapdata['v3']['nodes'][index];
|
|
}),
|
|
'links': mapdata['v3']['links']
|
|
}};
|
|
graph.start(netmapdata);
|
|
|
|
// center on our selected device
|
|
// graph.inspect().main.force.on('end.centernode', function() {
|
|
// var node = graph.nodeDataById( mapdata['v3']['centernode'] );
|
|
// graph.zoomSmooth(node.x, node.y, node.radius * 200);
|
|
// graph.inspect().main.force.on('end.centernode', null);
|
|
// });
|
|
});
|
|
|
|
});
|
|
|
|
// vim: ft=javascript
|
|
</script>
|