|
@ -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; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|