From 22e2c6d3c5aabf00b268eeda2121d592c5ca2aaf Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Sun, 2 Aug 2015 00:45:28 +0200 Subject: [PATCH] forcegraph: node shadow hi-dpi fix --- lib/forcegraph.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 7b00b0e..df70766 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -252,6 +252,7 @@ define(["d3"], function (d3) { } function redraw() { + var r = window.devicePixelRatio var translate = zoomBehavior.translate() var scale = zoomBehavior.scale() var links = intLinks.filter(visibleLinks) @@ -307,11 +308,11 @@ define(["d3"], function (d3) { // -- draw nodes -- var node = document.createElement("canvas") - node.width = scale * nodeRadius * 8 + node.width = scale * nodeRadius * 8 * r node.height = node.width var nctx = node.getContext("2d") - nctx.scale(scale, scale) + nctx.scale(scale * r, scale * r) nctx.save() nctx.translate(-node.width / scale, -node.height / scale) @@ -324,17 +325,17 @@ define(["d3"], function (d3) { nctx.strokeStyle = "rgba(255, 0, 0, 1)" nctx.shadowOffsetX = node.width * 1.5 + 0 nctx.shadowOffsetY = node.height * 1.5 + 3 - nctx.shadowBlur = 6 - nctx.shadowColor = "rgba(0, 0, 0, 0.32)" + nctx.shadowBlur = 12 + nctx.shadowColor = "rgba(0, 0, 0, 0.16)" nctx.stroke() nctx.shadowOffsetX = node.width * 1.5 + 0 nctx.shadowOffsetY = node.height * 1.5 + 3 - nctx.shadowBlur = 6 - nctx.shadowColor = "rgba(0, 0, 0, 0.46)" + nctx.shadowBlur = 12 + nctx.shadowColor = "rgba(0, 0, 0, 0.23)" nctx.stroke() nctx.restore() - nctx.translate(node.width / 2 / scale, node.height / 2 / scale) + nctx.translate(node.width / 2 / scale / r, node.height / 2 / scale / r) nctx.beginPath() nctx.moveTo(nodeRadius, 0) @@ -345,9 +346,9 @@ define(["d3"], function (d3) { nctx.stroke() ctx.save() - ctx.scale(1 / scale, 1 / scale) + ctx.scale(1 / scale / r, 1 / scale / r) nodes.filter(visibleNodes).forEach(function (d) { - ctx.drawImage(node, scale * d.x - node.width / 2, scale * d.y - node.height / 2) + ctx.drawImage(node, scale * r * d.x - node.width / 2, scale * r * d.y - node.height / 2) }) ctx.restore()