Browse Source

added arrowScaleFactor per #99

css_transitions
Alex de Mulder 10 years ago
parent
commit
69fceb3931
5 changed files with 35 additions and 13 deletions
  1. +10
    -4
      dist/vis.js
  2. +3
    -3
      dist/vis.min.js
  3. +12
    -2
      docs/graph.html
  4. +8
    -4
      src/graph/Edge.js
  5. +2
    -0
      src/graph/Graph.js

+ 10
- 4
dist/vis.js View File

@ -9821,6 +9821,7 @@ function Edge (properties, graph, constants) {
this.customLength = false;
this.selected = false;
this.smooth = constants.smoothCurves;
this.arrowScaleFactor = constants.edges.arrowScaleFactor;
this.from = null; // a node
this.to = null; // a node
@ -9881,6 +9882,9 @@ Edge.prototype.setProperties = function(properties, constants) {
if (properties.length !== undefined) {this.length = properties.length;
this.customLength = true;}
// scale the arrow
if (properties.arrowScaleFactor !== undefined) {this.arrowScaleFactor = properties.arrowScaleFactor};
// Added to support dashed lines
// David Jordan
// 2012-08-08
@ -10297,7 +10301,7 @@ Edge.prototype._drawArrowCenter = function(ctx) {
this._line(ctx);
var angle = Math.atan2((this.to.y - this.from.y), (this.to.x - this.from.x));
var length = 10 + 5 * this.width; // TODO: make customizable?
var length = (10 + 5 * this.width) * this.arrowScaleFactor;
// draw an arrow halfway the line
if (this.smooth == true) {
var midpointX = 0.5*(0.5*(this.from.x + this.via.x) + 0.5*(this.to.x + this.via.x));
@ -10337,7 +10341,7 @@ Edge.prototype._drawArrowCenter = function(ctx) {
// draw all arrows
var angle = 0.2 * Math.PI;
var length = 10 + 5 * this.width; // TODO: make customizable?
var length = (10 + 5 * this.width) * this.arrowScaleFactor;
point = this._pointOnCircle(x, y, radius, 0.5);
ctx.arrow(point.x, point.y, angle, length);
ctx.fill();
@ -10411,7 +10415,7 @@ Edge.prototype._drawArrow = function(ctx) {
ctx.stroke();
// draw arrow at the end of the line
length = 10 + 5 * this.width;
length = (10 + 5 * this.width) * this.arrowScaleFactor;
ctx.arrow(xTo, yTo, angle, length);
ctx.fill();
ctx.stroke();
@ -10462,7 +10466,7 @@ Edge.prototype._drawArrow = function(ctx) {
ctx.stroke();
// draw all arrows
length = 10 + 5 * this.width; // TODO: make customizable?
var length = (10 + 5 * this.width) * this.arrowScaleFactor;
ctx.arrow(arrow.x, arrow.y, arrow.angle, length);
ctx.fill();
ctx.stroke();
@ -15476,6 +15480,7 @@ function Graph (container, data, options) {
fontSize: 14, // px
fontFace: 'arial',
fontFill: 'white',
arrowScaleFactor: 1,
dash: {
length: 10,
gap: 5,
@ -16030,6 +16035,7 @@ Graph.prototype.setOptions = function (options) {
}
}
if (options.edges.color !== undefined) {
if (util.isString(options.edges.color)) {
this.constants.edges.color = {};

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


+ 12
- 2
docs/graph.html View File

@ -490,7 +490,12 @@ var edges = [
<th>Required</th>
<th>Description</th>
</tr>
<tr>
<td>arrowScaleFactor</td>
<td>Number</td>
<td>no</td>
<td>If you are using arrows, this will scale the arrow. Values < 1 give smaller arrows, > 1 larger arrows. Default: 1.</td>
</tr>
<tr>
<td>color</td>
<td>String | Object</td>
@ -1062,7 +1067,12 @@ var options = {
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>arrowScaleFactor</td>
<td>Number</td>
<td>1</td>
<td>If you are using arrows, this will scale the arrow. Values < 1 give smaller arrows, > 1 larger arrows. Default: 1.</td>
</tr>
<tr>
<td>color</td>
<td>String | Object</td>

+ 8
- 4
src/graph/Edge.js View File

@ -35,6 +35,7 @@ function Edge (properties, graph, constants) {
this.customLength = false;
this.selected = false;
this.smooth = constants.smoothCurves;
this.arrowScaleFactor = constants.edges.arrowScaleFactor;
this.from = null; // a node
this.to = null; // a node
@ -95,6 +96,9 @@ Edge.prototype.setProperties = function(properties, constants) {
if (properties.length !== undefined) {this.length = properties.length;
this.customLength = true;}
// scale the arrow
if (properties.arrowScaleFactor !== undefined) {this.arrowScaleFactor = properties.arrowScaleFactor};
// Added to support dashed lines
// David Jordan
// 2012-08-08
@ -511,7 +515,7 @@ Edge.prototype._drawArrowCenter = function(ctx) {
this._line(ctx);
var angle = Math.atan2((this.to.y - this.from.y), (this.to.x - this.from.x));
var length = 10 + 5 * this.width; // TODO: make customizable?
var length = (10 + 5 * this.width) * this.arrowScaleFactor;
// draw an arrow halfway the line
if (this.smooth == true) {
var midpointX = 0.5*(0.5*(this.from.x + this.via.x) + 0.5*(this.to.x + this.via.x));
@ -551,7 +555,7 @@ Edge.prototype._drawArrowCenter = function(ctx) {
// draw all arrows
var angle = 0.2 * Math.PI;
var length = 10 + 5 * this.width; // TODO: make customizable?
var length = (10 + 5 * this.width) * this.arrowScaleFactor;
point = this._pointOnCircle(x, y, radius, 0.5);
ctx.arrow(point.x, point.y, angle, length);
ctx.fill();
@ -625,7 +629,7 @@ Edge.prototype._drawArrow = function(ctx) {
ctx.stroke();
// draw arrow at the end of the line
length = 10 + 5 * this.width;
length = (10 + 5 * this.width) * this.arrowScaleFactor;
ctx.arrow(xTo, yTo, angle, length);
ctx.fill();
ctx.stroke();
@ -676,7 +680,7 @@ Edge.prototype._drawArrow = function(ctx) {
ctx.stroke();
// draw all arrows
length = 10 + 5 * this.width; // TODO: make customizable?
var length = (10 + 5 * this.width) * this.arrowScaleFactor;
ctx.arrow(arrow.x, arrow.y, arrow.angle, length);
ctx.fill();
ctx.stroke();

+ 2
- 0
src/graph/Graph.js View File

@ -73,6 +73,7 @@ function Graph (container, data, options) {
fontSize: 14, // px
fontFace: 'arial',
fontFill: 'white',
arrowScaleFactor: 1,
dash: {
length: 10,
gap: 5,
@ -627,6 +628,7 @@ Graph.prototype.setOptions = function (options) {
}
}
if (options.edges.color !== undefined) {
if (util.isString(options.edges.color)) {
this.constants.edges.color = {};

Loading…
Cancel
Save