Browse Source

added multiline text to edges, updated multiline code for both nodes and edges #291

v3_develop
Alex de Mulder 10 years ago
parent
commit
1cecbb96eb
4 changed files with 25010 additions and 25171 deletions
  1. +24980
    -25160
      dist/vis.js
  2. +1
    -1
      dist/vis.min.css
  3. +23
    -8
      lib/network/Edge.js
  4. +6
    -2
      lib/network/Node.js

+ 24980
- 25160
dist/vis.js
File diff suppressed because it is too large
View File


+ 1
- 1
dist/vis.min.css
File diff suppressed because it is too large
View File


+ 23
- 8
lib/network/Edge.js View File

@ -548,18 +548,33 @@ Edge.prototype._label = function (ctx, text, x, y) {
ctx.font = ((this.from.selected || this.to.selected) ? "bold " : "") + ctx.font = ((this.from.selected || this.to.selected) ? "bold " : "") +
this.options.fontSize + "px " + this.options.fontFace; this.options.fontSize + "px " + this.options.fontFace;
ctx.fillStyle = this.options.fontFill; ctx.fillStyle = this.options.fontFill;
var width = ctx.measureText(text).width;
var height = this.options.fontSize;
var left = x - width / 2;
var top = y - height / 2;
ctx.fillRect(left, top, width, height);
var lines = String(text).split('\n');
var lineCount = lines.length;
var fontSize = (Number(this.options.fontSize) + 4);
var yLine = y + (1 - lineCount) / 2 * fontSize;
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;
ctx.fillRect(left, top, width, height);
}
// draw text // draw text
ctx.fillStyle = this.options.fontColor || "black"; ctx.fillStyle = this.options.fontColor || "black";
ctx.textAlign = "left";
ctx.textBaseline = "top";
ctx.fillText(text, left, top);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
for (var i = 0; i < lineCount; i++) {
ctx.fillText(lines[i], x, yLine);
yLine += fontSize;
}
} }
}; };

+ 6
- 2
lib/network/Node.js View File

@ -857,8 +857,12 @@ Node.prototype._label = function (ctx, text, x, y, align, baseline, labelUnderNo
// font fill from edges now for nodes! // font fill from edges now for nodes!
if (this.options.fontFill !== undefined && this.options.fontFill !== null && this.options.fontFill !== "none") { if (this.options.fontFill !== undefined && this.options.fontFill !== null && this.options.fontFill !== "none") {
var width = ctx.measureText(text).width;
var height = this.options.fontSize;
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 left = x - width / 2;
var top = y - height / 2; var top = y - height / 2;
ctx.fillStyle = this.options.fontFill; ctx.fillStyle = this.options.fontFill;

Loading…
Cancel
Save