Browse Source

forcegraph: do not use global ctx when preparing labels

Nils Schneider 9 years ago
parent
commit
8ff0f789f8
1 changed files with 2 additions and 3 deletions
  1. 2 3
      lib/forcegraph.js

+ 2 - 3
lib/forcegraph.js

@@ -557,20 +557,19 @@ define(["d3"], function (d3) {
 
         var name = nodeName(d)
 
-        ctx.font = "11px Roboto"
         var offset = 8
         var lineWidth = 3
-        var width = ctx.measureText(name).width
         var buffer = document.createElement("canvas")
         var r = window.devicePixelRatio
         var bctx = buffer.getContext("2d")
+        bctx.font = "11px Roboto"
+        var width = bctx.measureText(name).width
         var scale = zoomBehavior.scaleExtent()[1] * r
         buffer.width = (width + 2 * lineWidth) * scale
         buffer.height = (16 + 2 * lineWidth) * scale
         bctx.scale(scale, scale)
         bctx.textBaseline = "middle"
         bctx.textAlign = "center"
-        bctx.font = ctx.font
         bctx.lineWidth = lineWidth
         bctx.lineCap = "round"
         bctx.strokeStyle = "rgba(255, 255, 255, 0.8)"