From 86070fb329634abb388504bf5596ffad4dbdded9 Mon Sep 17 00:00:00 2001 From: Alex de Mulder Date: Wed, 17 Sep 2014 14:23:44 +0200 Subject: [PATCH] tweaked node label size cache --- dist/vis.js | 30 +++++++++++++++++------------- lib/network/Edge.js | 4 ++-- lib/network/Node.js | 26 +++++++++++++++----------- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/dist/vis.js b/dist/vis.js index f73bb8d2..a38ee1ed 100644 --- a/dist/vis.js +++ b/dist/vis.js @@ -24544,6 +24544,7 @@ return /******/ (function(modules) { // webpackBootstrap this.level = -1; this.preassignedLevel = false; this.hierarchyEnumerated = false; + this.labelDimensions = {top:0,left:0,width:0,height:0,yLine:0}; // could be cached this.imagelist = imagelist; @@ -25378,18 +25379,21 @@ return /******/ (function(modules) { // webpackBootstrap } // font fill from edges now for nodes! + var width = ctx.measureText(lines[0]).width; + for (var i = 1; i < lineCount; i++) { + var lineWidth = ctx.measureText(lines[i]).width; + width = lineWidth > width ? lineWidth : width; + } + var height = this.options.fontSize * lineCount; + var left = x - width / 2; + var top = y - height / 2; + if (ctx.textBaseline == "top") { + top += 0.5 * fontSize; + } + this.labelDimensions = {top:top,left:left,width:width,height:height,yLine:yLine}; + + // create the fontfill background if (this.options.fontFill !== undefined && this.options.fontFill !== null && this.options.fontFill !== "none") { - var width = ctx.measureText(lines[0]).width; - for (var i = 1; i < lineCount; i++) { - var lineWidth = ctx.measureText(lines[i]).width; - width = lineWidth > width ? lineWidth : width; - } - var height = this.options.fontSize * lineCount; - var left = x - width / 2; - var top = y - height / 2; - if (ctx.textBaseline == "top") { - top += 0.5 * fontSize; - } ctx.fillStyle = this.options.fontFill; ctx.fillRect(left, top, width, height); } @@ -25550,7 +25554,7 @@ return /******/ (function(modules) { // webpackBootstrap this.value = undefined; this.selected = false; this.hover = false; - this.labelDimensions = {top:0,left:0,width:0,height:0}; + this.labelDimensions = {top:0,left:0,width:0,height:0,yLine:0}; // could be cached this.from = null; // a node this.to = null; // a node @@ -26076,7 +26080,7 @@ return /******/ (function(modules) { // webpackBootstrap var left = x - width / 2; var top = y - height / 2; - this.labelDimensions = {top:top,left:left,width:width,height:height}; + this.labelDimensions = {top:top,left:left,width:width,height:height,yLine:yLine}; if (this.options.fontFill !== undefined && this.options.fontFill !== null && this.options.fontFill !== "none") { ctx.fillStyle = this.options.fontFill; diff --git a/lib/network/Edge.js b/lib/network/Edge.js index 07e91e50..a4883751 100644 --- a/lib/network/Edge.js +++ b/lib/network/Edge.js @@ -38,7 +38,7 @@ function Edge (properties, network, networkConstants) { this.value = undefined; this.selected = false; this.hover = false; - this.labelDimensions = {top:0,left:0,width:0,height:0}; + this.labelDimensions = {top:0,left:0,width:0,height:0,yLine:0}; // could be cached this.from = null; // a node this.to = null; // a node @@ -564,7 +564,7 @@ Edge.prototype._label = function (ctx, text, x, y) { var left = x - width / 2; var top = y - height / 2; - this.labelDimensions = {top:top,left:left,width:width,height:height}; + this.labelDimensions = {top:top,left:left,width:width,height:height,yLine:yLine}; if (this.options.fontFill !== undefined && this.options.fontFill !== null && this.options.fontFill !== "none") { ctx.fillStyle = this.options.fontFill; diff --git a/lib/network/Node.js b/lib/network/Node.js index 0677ed3d..349d943d 100644 --- a/lib/network/Node.js +++ b/lib/network/Node.js @@ -53,6 +53,7 @@ function Node(properties, imagelist, grouplist, networkConstants) { this.level = -1; this.preassignedLevel = false; this.hierarchyEnumerated = false; + this.labelDimensions = {top:0,left:0,width:0,height:0,yLine:0}; // could be cached this.imagelist = imagelist; @@ -887,18 +888,21 @@ Node.prototype._label = function (ctx, text, x, y, align, baseline, labelUnderNo } // font fill from edges now for nodes! + var width = ctx.measureText(lines[0]).width; + for (var i = 1; i < lineCount; i++) { + var lineWidth = ctx.measureText(lines[i]).width; + width = lineWidth > width ? lineWidth : width; + } + var height = this.options.fontSize * lineCount; + var left = x - width / 2; + var top = y - height / 2; + if (ctx.textBaseline == "top") { + top += 0.5 * fontSize; + } + this.labelDimensions = {top:top,left:left,width:width,height:height,yLine:yLine}; + + // create the fontfill background if (this.options.fontFill !== undefined && this.options.fontFill !== null && this.options.fontFill !== "none") { - var width = ctx.measureText(lines[0]).width; - for (var i = 1; i < lineCount; i++) { - var lineWidth = ctx.measureText(lines[i]).width; - width = lineWidth > width ? lineWidth : width; - } - var height = this.options.fontSize * lineCount; - var left = x - width / 2; - var top = y - height / 2; - if (ctx.textBaseline == "top") { - top += 0.5 * fontSize; - } ctx.fillStyle = this.options.fontFill; ctx.fillRect(left, top, width, height); }