Browse Source

fixed label position for smooth curves as per #49

css_transitions
Alex de Mulder 10 years ago
parent
commit
0b4a06d98a
3 changed files with 59 additions and 15 deletions
  1. +27
    -5
      dist/vis.js
  2. +5
    -5
      dist/vis.min.js
  3. +27
    -5
      src/graph/Edge.js

+ 27
- 5
dist/vis.js View File

@ -10645,14 +10645,21 @@ Edge.prototype._drawLine = function(ctx) {
ctx.strokeStyle = this.color; ctx.strokeStyle = this.color;
ctx.lineWidth = this._getLineWidth(); ctx.lineWidth = this._getLineWidth();
var point;
if (this.from != this.to) { if (this.from != this.to) {
// draw line // draw line
this._line(ctx); this._line(ctx);
// draw label // draw label
var point;
if (this.label) { if (this.label) {
point = this._pointOnLine(0.5);
if (this.smooth == true) {
var midpointX = 0.5*(0.5*(this.from.x + this.via.x) + 0.5*(this.to.x + this.via.x));
var midpointY = 0.5*(0.5*(this.from.y + this.via.y) + 0.5*(this.to.y + this.via.y));
point = {x:midpointX, y:midpointY};
}
else {
point = this._pointOnLine(0.5);
}
this._label(ctx, this.label, point.x, point.y); this._label(ctx, this.label, point.x, point.y);
} }
} }
@ -10835,7 +10842,15 @@ Edge.prototype._drawDashLine = function(ctx) {
// draw label // draw label
if (this.label) { if (this.label) {
var point = this._pointOnLine(0.5);
var point;
if (this.smooth == true) {
var midpointX = 0.5*(0.5*(this.from.x + this.via.x) + 0.5*(this.to.x + this.via.x));
var midpointY = 0.5*(0.5*(this.from.y + this.via.y) + 0.5*(this.to.y + this.via.y));
point = {x:midpointX, y:midpointY};
}
else {
point = this._pointOnLine(0.5);
}
this._label(ctx, this.label, point.x, point.y); this._label(ctx, this.label, point.x, point.y);
} }
}; };
@ -10906,7 +10921,6 @@ Edge.prototype._drawArrowCenter = function(ctx) {
// draw label // draw label
if (this.label) { if (this.label) {
point = this._pointOnLine(0.5);
this._label(ctx, this.label, point.x, point.y); this._label(ctx, this.label, point.x, point.y);
} }
} }
@ -11010,7 +11024,15 @@ Edge.prototype._drawArrow = function(ctx) {
// draw label // draw label
if (this.label) { if (this.label) {
var point = this._pointOnLine(0.5);
var point;
if (this.smooth == true) {
var midpointX = 0.5*(0.5*(this.from.x + this.via.x) + 0.5*(this.to.x + this.via.x));
var midpointY = 0.5*(0.5*(this.from.y + this.via.y) + 0.5*(this.to.y + this.via.y));
point = {x:midpointX, y:midpointY};
}
else {
point = this._pointOnLine(0.5);
}
this._label(ctx, this.label, point.x, point.y); this._label(ctx, this.label, point.x, point.y);
} }
} }

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


+ 27
- 5
src/graph/Edge.js View File

@ -232,14 +232,21 @@ Edge.prototype._drawLine = function(ctx) {
ctx.strokeStyle = this.color; ctx.strokeStyle = this.color;
ctx.lineWidth = this._getLineWidth(); ctx.lineWidth = this._getLineWidth();
var point;
if (this.from != this.to) { if (this.from != this.to) {
// draw line // draw line
this._line(ctx); this._line(ctx);
// draw label // draw label
var point;
if (this.label) { if (this.label) {
point = this._pointOnLine(0.5);
if (this.smooth == true) {
var midpointX = 0.5*(0.5*(this.from.x + this.via.x) + 0.5*(this.to.x + this.via.x));
var midpointY = 0.5*(0.5*(this.from.y + this.via.y) + 0.5*(this.to.y + this.via.y));
point = {x:midpointX, y:midpointY};
}
else {
point = this._pointOnLine(0.5);
}
this._label(ctx, this.label, point.x, point.y); this._label(ctx, this.label, point.x, point.y);
} }
} }
@ -422,7 +429,15 @@ Edge.prototype._drawDashLine = function(ctx) {
// draw label // draw label
if (this.label) { if (this.label) {
var point = this._pointOnLine(0.5);
var point;
if (this.smooth == true) {
var midpointX = 0.5*(0.5*(this.from.x + this.via.x) + 0.5*(this.to.x + this.via.x));
var midpointY = 0.5*(0.5*(this.from.y + this.via.y) + 0.5*(this.to.y + this.via.y));
point = {x:midpointX, y:midpointY};
}
else {
point = this._pointOnLine(0.5);
}
this._label(ctx, this.label, point.x, point.y); this._label(ctx, this.label, point.x, point.y);
} }
}; };
@ -493,7 +508,6 @@ Edge.prototype._drawArrowCenter = function(ctx) {
// draw label // draw label
if (this.label) { if (this.label) {
point = this._pointOnLine(0.5);
this._label(ctx, this.label, point.x, point.y); this._label(ctx, this.label, point.x, point.y);
} }
} }
@ -597,7 +611,15 @@ Edge.prototype._drawArrow = function(ctx) {
// draw label // draw label
if (this.label) { if (this.label) {
var point = this._pointOnLine(0.5);
var point;
if (this.smooth == true) {
var midpointX = 0.5*(0.5*(this.from.x + this.via.x) + 0.5*(this.to.x + this.via.x));
var midpointY = 0.5*(0.5*(this.from.y + this.via.y) + 0.5*(this.to.y + this.via.y));
point = {x:midpointX, y:midpointY};
}
else {
point = this._pointOnLine(0.5);
}
this._label(ctx, this.label, point.x, point.y); this._label(ctx, this.label, point.x, point.y);
} }
} }

Loading…
Cancel
Save