From d2090225c56d6ad710ada08fd720c250eba9fca7 Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Wed, 8 Feb 2017 00:14:48 +0100 Subject: [PATCH] [TASK] Add zoom limit for drawing clients in forcegraph --- lib/forcegraph.js | 51 ++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 271132f..7212981 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -395,33 +395,34 @@ define(['d3', 'helper'], function (d3, helper) { // -- draw clients -- ctx.save(); ctx.beginPath(); - nodes.filter(visibleNodes).forEach(function (d) { - var clients = d.o.node.statistics.clients; - if (clients === 0) { - return; - } - - var startDistance = 16; - var radius = 3; - var a = 1.2; - var startAngle = Math.PI; - - for (var orbit = 0, i = 0; i < clients; orbit++) { - var di = startDistance + orbit * 2 * radius * a; - var n = Math.floor((Math.PI * di) / (a * radius)); - var delta = clients - i; - - for (var j = 0; j < Math.min(delta, n); i++, j++) { - var angle = 2 * Math.PI / n * j; - var x = d.x + di * Math.cos(angle + startAngle); - var y = d.y + di * Math.sin(angle + startAngle); - - ctx.moveTo(x, y); - ctx.arc(x, y, radius, 0, 2 * Math.PI); + if (scale > 0.9) { + nodes.filter(visibleNodes).forEach(function (d) { + var clients = d.o.node.statistics.clients; + if (clients === 0) { + return; } - } - }); + var startDistance = 16; + var radius = 3; + var a = 1.2; + var startAngle = Math.PI; + + for (var orbit = 0, i = 0; i < clients; orbit++) { + var di = startDistance + orbit * 2 * radius * a; + var n = Math.floor((Math.PI * di) / (a * radius)); + var delta = clients - i; + + for (var j = 0; j < Math.min(delta, n); i++, j++) { + var angle = 2 * Math.PI / n * j; + var x = d.x + di * Math.cos(angle + startAngle); + var y = d.y + di * Math.sin(angle + startAngle); + + ctx.moveTo(x, y); + ctx.arc(x, y, radius, 0, 2 * Math.PI); + } + } + }); + } ctx.fillStyle = clientColor; ctx.fill(); ctx.restore();