浏览代码

forcegraph: do not use global ctx when preparing labels

Nils Schneider 9 年之前
父节点
当前提交
8ff0f789f8
共有 1 个文件被更改,包括 2 次插入3 次删除
  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)"