this.paintText = function(a, b) {
var c = b[0],
d = b[b.length - 1];
if (4 == b.length && (c = b[1], d = b[2]), this.text && this.text.length > 0) {
var e = (d.x + c.x) / 2 + this.textOffsetX,
f = (d.y + c.y) / 2 + this.textOffsetY;
a.save(), a.beginPath(), a.font = this.font;
var g = a.measureText(this.text).width,
h = a.measureText("ç”°").width;
//---------新增的代码
a.translate(e ,f );
a.rotate(Math.atan((d.y-c.y)/(d.x-c.x)));
if (a.fillStyle = "rgba(" + this.fontColor + ", " + this.alpha + ")", this.nodeA === this.nodeZ) {
var j = this.bundleGap * (this.nodeIndex + 1) / 2,
e = this.nodeA.x + j * Math.cos(i),
f = this.nodeA.y + j * Math.sin(i);
a.fillText(this.text, e, f)
} else
// a.fillText(this.text, e - g / 2, f - h / 2);//源码计算文字位置
//修改文本字体大小
a.font = "7pt Calibri";
//----------修改代码
a.fillText(this.text, -g/2+10,-h/2+20);
a.stroke(), a.closePath(), a.restore()
}
}
在源码找到paintText方法 在canvas对象a下面加上
a.translate(e ,f ); a.rotate(Math.atan((d.y-c.y)/(d.x-c.x)));
详情如上面代码。
然后修改 a.fillText(this.text, e - g / 2, f - h / 2);
为a.fillText(this.text, -g/2+10,-h/2+20);
其中+10和+20是调整文字在连线上的位置;
调整字体大小a.font = "7pt Calibri";