borken worker
This commit is contained in:
12
share/public/javascripts/worker.js
Normal file
12
share/public/javascripts/worker.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
importScripts( 'http://localhost:5000/javascripts/d3-3.5.6.js' );
|
||||||
|
|
||||||
|
onmessage = function(event) {
|
||||||
|
var force = event.data.force;
|
||||||
|
|
||||||
|
for (var i = 0, n = Math.ceil(Math.log(0.001) / Math.log(1 - (1 - Math.pow(0.001, 1 / 300)))); i < n; ++i) {
|
||||||
|
postMessage({type: "tick", progress: i / n});
|
||||||
|
force.tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
postMessage({type: "end", force: force});
|
||||||
|
};
|
||||||
@@ -3,43 +3,71 @@
|
|||||||
// custom resize function as there is no event to fire and we need
|
// custom resize function as there is no event to fire and we need
|
||||||
// to react to the sidebar.
|
// to react to the sidebar.
|
||||||
$.getJSON('[% uri_for('/ajax/data/device/netmap') %]', {q: '[% params.q %]'}, function(data) {
|
$.getJSON('[% uri_for('/ajax/data/device/netmap') %]', {q: '[% params.q %]'}, function(data) {
|
||||||
|
|
||||||
function resizeGraphContainer() {
|
function resizeGraphContainer() {
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
var graph = jQuery('#netmap_pane');
|
var graph = jQuery('#netmap_pane');
|
||||||
netmap_pane.width( parseInt(graph.parent().css('width')) ).resume();
|
netmap_pane.width( parseInt(graph.parent().css('width')) ).resume();
|
||||||
netmap_pane.height( window.innerHeight - 100 ).resume();
|
netmap_pane.height( window.innerHeight - 100 ).resume();
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
jQuery(document).ready(function() {
|
jQuery(document).ready(function() {
|
||||||
window.netmap_pane = netGobrechtsD3Force('netmap_pane')
|
window.netmap_pane = netGobrechtsD3Force()
|
||||||
.debug(true)
|
.debug(true)
|
||||||
.lassoMode(true)
|
.lassoMode(true)
|
||||||
.nodeEventToOpenLink('click')
|
.nodeEventToOpenLink('click')
|
||||||
.nodeLinkTarget('none')
|
.nodeLinkTarget('none')
|
||||||
.labelDistance(2)
|
.labelDistance(2)
|
||||||
.charge(-850)
|
.charge(-850)
|
||||||
.zoomMode(true)
|
.zoomMode(true)
|
||||||
.preventLabelOverlappingOnForceEnd(true)
|
.preventLabelOverlappingOnForceEnd(true)
|
||||||
.showLinkDirection(false)
|
.showLinkDirection(false)
|
||||||
.showSelfLinks(true)
|
.showSelfLinks(true)
|
||||||
.showLoadingIndicatorOnAjaxCall(true)
|
.minZoomFactor(0.1)
|
||||||
.minZoomFactor(0.1)
|
.maxZoomFactor(10);
|
||||||
.maxZoomFactor(10);
|
|
||||||
|
|
||||||
// center on our selected device
|
// stop force
|
||||||
netmap_pane.inspect().main.force.on('end.centernode', function() {
|
netmap_pane.inspect().main.force.stop();
|
||||||
var node = netmap_pane.nodeDataById( data['data']['centernode'] );
|
|
||||||
netmap_pane.zoomSmooth(node.x, node.y, node.radius * 200);
|
|
||||||
netmap_pane.inspect().main.force.on('end.centernode', null);
|
|
||||||
});
|
|
||||||
|
|
||||||
jQuery('#nd_sidebar-toggle-img-in').on("click", resizeGraphContainer);
|
// center on our selected device
|
||||||
jQuery('#nd_sidebar-toggle-img-out').on("click", resizeGraphContainer);
|
netmap_pane.inspect().main.force.on('end.centernode', function() {
|
||||||
jQuery(window).on("resize", resizeGraphContainer);
|
var node = netmap_pane.nodeDataById( data['data']['centernode'] );
|
||||||
|
netmap_pane.zoomSmooth(node.x, node.y, node.radius * 200);
|
||||||
|
netmap_pane.inspect().main.force.on('end.centernode', null);
|
||||||
|
});
|
||||||
|
|
||||||
|
// disable the default ticker
|
||||||
|
netmap_pane.inspect().main.force.on('tick', function() {} );
|
||||||
|
|
||||||
|
// now start, but without a ticker
|
||||||
|
netmap_pane.start(data);
|
||||||
|
|
||||||
|
var worker = new Worker( 'http://localhost:5000/javascripts/worker.js' );
|
||||||
|
console.log(netmap_pane.inspect().main.force);
|
||||||
|
worker.postMessage({force: netmap_pane.inspect().main.force});
|
||||||
|
worker.onmessage = function(event) {
|
||||||
|
switch (event.data.type) {
|
||||||
|
case "tick": return ticked(event.data);
|
||||||
|
case "end": return ended(event.data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function ticked(data) {
|
||||||
|
var progress = data.progress;
|
||||||
|
console.log(100 * progress + "%");
|
||||||
|
//meter.style.width = 100 * progress + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
function ended(data) {
|
||||||
|
console.log( data );
|
||||||
|
}
|
||||||
|
|
||||||
|
// jQuery('#nd_sidebar-toggle-img-in').on("click", resizeGraphContainer);
|
||||||
|
// jQuery('#nd_sidebar-toggle-img-out').on("click", resizeGraphContainer);
|
||||||
|
// jQuery(window).on("resize", resizeGraphContainer);
|
||||||
|
// resizeGraphContainer();
|
||||||
|
|
||||||
resizeGraphContainer();
|
|
||||||
netmap_pane.start(data);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<script type="text/javascript" src="[% uri_base %]/javascripts/bootstrap.min.js"></script>
|
<script type="text/javascript" src="[% uri_base %]/javascripts/bootstrap.min.js"></script>
|
||||||
<script type="text/javascript" src="[% uri_base %]/javascripts/underscore.min.js"></script>
|
<script type="text/javascript" src="[% uri_base %]/javascripts/underscore.min.js"></script>
|
||||||
<script type="text/javascript" src="[% uri_base %]/javascripts/jquery.qtip.min.js"></script>
|
<script type="text/javascript" src="[% uri_base %]/javascripts/jquery.qtip.min.js"></script>
|
||||||
<script type="text/javascript" src="[% uri_base %]/javascripts/d3.min.js"></script>
|
<script type="text/javascript" src="[% uri_base %]/javascripts/d3-3.5.6.js"></script>
|
||||||
<script type="text/javascript" src="[% uri_base %]/javascripts/d3-force.js"></script>
|
<script type="text/javascript" src="[% uri_base %]/javascripts/d3-force.js"></script>
|
||||||
<script type="text/javascript" src="[% uri_base %]/javascripts/toastr.js"></script>
|
<script type="text/javascript" src="[% uri_base %]/javascripts/toastr.js"></script>
|
||||||
<script type="text/javascript" src="[% uri_base %]/javascripts/jquery.floatThead.js"></script>
|
<script type="text/javascript" src="[% uri_base %]/javascripts/jquery.floatThead.js"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user