vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1360 lines
40 KiB

10 years ago
9 years ago
10 years ago
  1. var util = require('../util');
  2. var Node = require('./Node');
  3. /**
  4. * @class Edge
  5. *
  6. * A edge connects two nodes
  7. * @param {Object} properties Object with properties. Must contain
  8. * At least properties from and to.
  9. * Available properties: from (number),
  10. * to (number), label (string, color (string),
  11. * width (number), style (string),
  12. * length (number), title (string)
  13. * @param {Network} network A Network object, used to find and edge to
  14. * nodes.
  15. * @param {Object} constants An object with default values for
  16. * example for the color
  17. */
  18. function Edge (properties, network, networkConstants) {
  19. if (!network) {
  20. throw "No network provided";
  21. }
  22. var fields = ['edges','physics'];
  23. var constants = util.selectiveBridgeObject(fields,networkConstants);
  24. this.options = constants.edges;
  25. this.physics = constants.physics;
  26. this.options['smoothCurves'] = networkConstants['smoothCurves'];
  27. this.network = network;
  28. // initialize variables
  29. this.id = undefined;
  30. this.fromId = undefined;
  31. this.toId = undefined;
  32. this.title = undefined;
  33. this.widthSelected = this.options.width * this.options.widthSelectionMultiplier;
  34. this.value = undefined;
  35. this.selected = false;
  36. this.hover = false;
  37. this.labelDimensions = {top:0,left:0,width:0,height:0,yLine:0}; // could be cached
  38. this.dirtyLabel = true;
  39. this.colorDirty = true;
  40. this.from = null; // a node
  41. this.to = null; // a node
  42. this.via = null; // a temp node
  43. this.fromBackup = null; // used to clean up after reconnect
  44. this.toBackup = null;; // used to clean up after reconnect
  45. // we use this to be able to reconnect the edge to a cluster if its node is put into a cluster
  46. // by storing the original information we can revert to the original connection when the cluser is opened.
  47. this.originalFromId = [];
  48. this.originalToId = [];
  49. this.connected = false;
  50. this.widthFixed = false;
  51. this.lengthFixed = false;
  52. this.setProperties(properties);
  53. this.controlNodesEnabled = false;
  54. this.controlNodes = {from:null, to:null, positions:{}};
  55. this.connectedNode = null;
  56. }
  57. /**
  58. * Set or overwrite properties for the edge
  59. * @param {Object} properties an object with properties
  60. * @param {Object} constants and object with default, global properties
  61. */
  62. Edge.prototype.setProperties = function(properties) {
  63. this.colorDirty = true;
  64. if (!properties) {
  65. return;
  66. }
  67. var fields = ['style','fontSize','fontFace','fontColor','fontFill','fontStrokeWidth','fontStrokeColor','width',
  68. 'widthSelectionMultiplier','hoverWidth','arrowScaleFactor','dash','inheritColor','labelAlignment', 'opacity',
  69. 'customScalingFunction'
  70. ];
  71. util.selectiveDeepExtend(fields, this.options, properties);
  72. if (properties.from !== undefined) {this.fromId = properties.from;}
  73. if (properties.to !== undefined) {this.toId = properties.to;}
  74. if (properties.id !== undefined) {this.id = properties.id;}
  75. if (properties.label !== undefined) {this.label = properties.label; this.dirtyLabel = true;}
  76. if (properties.title !== undefined) {this.title = properties.title;}
  77. if (properties.value !== undefined) {this.value = properties.value;}
  78. if (properties.length !== undefined) {this.physics.springLength = properties.length;}
  79. if (properties.color !== undefined) {
  80. this.options.inheritColor = false;
  81. if (util.isString(properties.color)) {
  82. this.options.color.color = properties.color;
  83. this.options.color.highlight = properties.color;
  84. }
  85. else {
  86. if (properties.color.color !== undefined) {this.options.color.color = properties.color.color;}
  87. if (properties.color.highlight !== undefined) {this.options.color.highlight = properties.color.highlight;}
  88. if (properties.color.hover !== undefined) {this.options.color.hover = properties.color.hover;}
  89. }
  90. }
  91. // A node is connected when it has a from and to node.
  92. this.connect();
  93. this.widthFixed = this.widthFixed || (properties.width !== undefined);
  94. this.lengthFixed = this.lengthFixed || (properties.length !== undefined);
  95. this.widthSelected = this.options.width* this.options.widthSelectionMultiplier;
  96. // set draw method based on style
  97. switch (this.options.style) {
  98. case 'line': this.draw = this._drawLine; break;
  99. case 'arrow': this.draw = this._drawArrow; break;
  100. case 'arrow-center': this.draw = this._drawArrowCenter; break;
  101. case 'dash-line': this.draw = this._drawDashLine; break;
  102. default: this.draw = this._drawLine; break;
  103. }
  104. };
  105. /**
  106. * Connect an edge to its nodes
  107. */
  108. Edge.prototype.connect = function () {
  109. this.disconnect();
  110. this.from = this.network.nodes[this.fromId] || null;
  111. this.to = this.network.nodes[this.toId] || null;
  112. this.connected = (this.from && this.to);
  113. if (this.connected) {
  114. this.from.attachEdge(this);
  115. this.to.attachEdge(this);
  116. }
  117. else {
  118. if (this.from) {
  119. this.from.detachEdge(this);
  120. }
  121. if (this.to) {
  122. this.to.detachEdge(this);
  123. }
  124. }
  125. };
  126. /**
  127. * Disconnect an edge from its nodes
  128. */
  129. Edge.prototype.disconnect = function () {
  130. if (this.from) {
  131. this.from.detachEdge(this);
  132. this.from = null;
  133. }
  134. if (this.to) {
  135. this.to.detachEdge(this);
  136. this.to = null;
  137. }
  138. this.connected = false;
  139. };
  140. /**
  141. * get the title of this edge.
  142. * @return {string} title The title of the edge, or undefined when no title
  143. * has been set.
  144. */
  145. Edge.prototype.getTitle = function() {
  146. return typeof this.title === "function" ? this.title() : this.title;
  147. };
  148. /**
  149. * Retrieve the value of the edge. Can be undefined
  150. * @return {Number} value
  151. */
  152. Edge.prototype.getValue = function() {
  153. return this.value;
  154. };
  155. /**
  156. * Adjust the value range of the edge. The edge will adjust it's width
  157. * based on its value.
  158. * @param {Number} min
  159. * @param {Number} max
  160. */
  161. Edge.prototype.setValueRange = function(min, max, total) {
  162. if (!this.widthFixed && this.value !== undefined) {
  163. var scale = this.options.customScalingFunction(min, max, total, this.value);
  164. var widthDiff = this.options.widthMax - this.options.widthMin;
  165. this.options.width = this.options.widthMin + scale * widthDiff;
  166. this.widthSelected = this.options.width* this.options.widthSelectionMultiplier;
  167. }
  168. };
  169. /**
  170. * Redraw a edge
  171. * Draw this edge in the given canvas
  172. * The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
  173. * @param {CanvasRenderingContext2D} ctx
  174. */
  175. Edge.prototype.draw = function(ctx) {
  176. throw "Method draw not initialized in edge";
  177. };
  178. /**
  179. * Check if this object is overlapping with the provided object
  180. * @param {Object} obj an object with parameters left, top
  181. * @return {boolean} True if location is located on the edge
  182. */
  183. Edge.prototype.isOverlappingWith = function(obj) {
  184. if (this.connected) {
  185. var distMax = 10;
  186. var xFrom = this.from.x;
  187. var yFrom = this.from.y;
  188. var xTo = this.to.x;
  189. var yTo = this.to.y;
  190. var xObj = obj.left;
  191. var yObj = obj.top;
  192. var dist = this._getDistanceToEdge(xFrom, yFrom, xTo, yTo, xObj, yObj);
  193. return (dist < distMax);
  194. }
  195. else {
  196. return false
  197. }
  198. };
  199. Edge.prototype._getColor = function() {
  200. var colorObj = this.options.color;
  201. if (this.colorDirty === true) {
  202. if (this.options.inheritColor == "to") {
  203. colorObj = {
  204. highlight: this.to.options.color.highlight.border,
  205. hover: this.to.options.color.hover.border,
  206. color: util.overrideOpacity(this.from.options.color.border, this.options.opacity)
  207. };
  208. }
  209. else if (this.options.inheritColor == "from" || this.options.inheritColor == true) {
  210. colorObj = {
  211. highlight: this.from.options.color.highlight.border,
  212. hover: this.from.options.color.hover.border,
  213. color: util.overrideOpacity(this.from.options.color.border, this.options.opacity)
  214. };
  215. }
  216. this.options.color = colorObj;
  217. this.colorDirty = false;
  218. }
  219. if (this.selected == true) {return colorObj.highlight;}
  220. else if (this.hover == true) {return colorObj.hover;}
  221. else {return colorObj.color;}
  222. };
  223. /**
  224. * Redraw a edge as a line
  225. * Draw this edge in the given canvas
  226. * The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
  227. * @param {CanvasRenderingContext2D} ctx
  228. * @private
  229. */
  230. Edge.prototype._drawLine = function(ctx) {
  231. // set style
  232. ctx.strokeStyle = this._getColor();
  233. ctx.lineWidth = this._getLineWidth();
  234. if (this.from != this.to) {
  235. // draw line
  236. var via = this._line(ctx);
  237. // draw label
  238. var point;
  239. if (this.label) {
  240. if (this.options.smoothCurves.enabled == true && via != null) {
  241. var midpointX = 0.5*(0.5*(this.from.x + via.x) + 0.5*(this.to.x + via.x));
  242. var midpointY = 0.5*(0.5*(this.from.y + via.y) + 0.5*(this.to.y + via.y));
  243. point = {x:midpointX, y:midpointY};
  244. }
  245. else {
  246. point = this._pointOnLine(0.5);
  247. }
  248. this._label(ctx, this.label, point.x, point.y);
  249. }
  250. }
  251. else {
  252. var x, y;
  253. var radius = this.physics.springLength / 4;
  254. var node = this.from;
  255. if (!node.width) {
  256. node.resize(ctx);
  257. }
  258. if (node.width > node.height) {
  259. x = node.x + node.width / 2;
  260. y = node.y - radius;
  261. }
  262. else {
  263. x = node.x + radius;
  264. y = node.y - node.height / 2;
  265. }
  266. this._circle(ctx, x, y, radius);
  267. point = this._pointOnCircle(x, y, radius, 0.5);
  268. this._label(ctx, this.label, point.x, point.y);
  269. }
  270. };
  271. /**
  272. * Get the line width of the edge. Depends on width and whether one of the
  273. * connected nodes is selected.
  274. * @return {Number} width
  275. * @private
  276. */
  277. Edge.prototype._getLineWidth = function() {
  278. if (this.selected == true) {
  279. return Math.max(Math.min(this.widthSelected, this.options.widthMax), 0.3*this.networkScaleInv);
  280. }
  281. else {
  282. if (this.hover == true) {
  283. return Math.max(Math.min(this.options.hoverWidth, this.options.widthMax), 0.3*this.networkScaleInv);
  284. }
  285. else {
  286. return Math.max(this.options.width, 0.3*this.networkScaleInv);
  287. }
  288. }
  289. };
  290. Edge.prototype._getViaCoordinates = function () {
  291. if (this.options.smoothCurves.dynamic == true && this.options.smoothCurves.enabled == true ) {
  292. return this.via;
  293. }
  294. else if (this.options.smoothCurves.enabled == false) {
  295. return {x:0,y:0};
  296. }
  297. else {
  298. var xVia = null;
  299. var yVia = null;
  300. var factor = this.options.smoothCurves.roundness;
  301. var type = this.options.smoothCurves.type;
  302. var dx = Math.abs(this.from.x - this.to.x);
  303. var dy = Math.abs(this.from.y - this.to.y);
  304. if (type == 'discrete' || type == 'diagonalCross') {
  305. if (Math.abs(this.from.x - this.to.x) < Math.abs(this.from.y - this.to.y)) {
  306. if (this.from.y > this.to.y) {
  307. if (this.from.x < this.to.x) {
  308. xVia = this.from.x + factor * dy;
  309. yVia = this.from.y - factor * dy;
  310. }
  311. else if (this.from.x > this.to.x) {
  312. xVia = this.from.x - factor * dy;
  313. yVia = this.from.y - factor * dy;
  314. }
  315. }
  316. else if (this.from.y < this.to.y) {
  317. if (this.from.x < this.to.x) {
  318. xVia = this.from.x + factor * dy;
  319. yVia = this.from.y + factor * dy;
  320. }
  321. else if (this.from.x > this.to.x) {
  322. xVia = this.from.x - factor * dy;
  323. yVia = this.from.y + factor * dy;
  324. }
  325. }
  326. if (type == "discrete") {
  327. xVia = dx < factor * dy ? this.from.x : xVia;
  328. }
  329. }
  330. else if (Math.abs(this.from.x - this.to.x) > Math.abs(this.from.y - this.to.y)) {
  331. if (this.from.y > this.to.y) {
  332. if (this.from.x < this.to.x) {
  333. xVia = this.from.x + factor * dx;
  334. yVia = this.from.y - factor * dx;
  335. }
  336. else if (this.from.x > this.to.x) {
  337. xVia = this.from.x - factor * dx;
  338. yVia = this.from.y - factor * dx;
  339. }
  340. }
  341. else if (this.from.y < this.to.y) {
  342. if (this.from.x < this.to.x) {
  343. xVia = this.from.x + factor * dx;
  344. yVia = this.from.y + factor * dx;
  345. }
  346. else if (this.from.x > this.to.x) {
  347. xVia = this.from.x - factor * dx;
  348. yVia = this.from.y + factor * dx;
  349. }
  350. }
  351. if (type == "discrete") {
  352. yVia = dy < factor * dx ? this.from.y : yVia;
  353. }
  354. }
  355. }
  356. else if (type == "straightCross") {
  357. if (Math.abs(this.from.x - this.to.x) < Math.abs(this.from.y - this.to.y)) { // up - down
  358. xVia = this.from.x;
  359. if (this.from.y < this.to.y) {
  360. yVia = this.to.y - (1 - factor) * dy;
  361. }
  362. else {
  363. yVia = this.to.y + (1 - factor) * dy;
  364. }
  365. }
  366. else if (Math.abs(this.from.x - this.to.x) > Math.abs(this.from.y - this.to.y)) { // left - right
  367. if (this.from.x < this.to.x) {
  368. xVia = this.to.x - (1 - factor) * dx;
  369. }
  370. else {
  371. xVia = this.to.x + (1 - factor) * dx;
  372. }
  373. yVia = this.from.y;
  374. }
  375. }
  376. else if (type == 'horizontal') {
  377. if (this.from.x < this.to.x) {
  378. xVia = this.to.x - (1 - factor) * dx;
  379. }
  380. else {
  381. xVia = this.to.x + (1 - factor) * dx;
  382. }
  383. yVia = this.from.y;
  384. }
  385. else if (type == 'vertical') {
  386. xVia = this.from.x;
  387. if (this.from.y < this.to.y) {
  388. yVia = this.to.y - (1 - factor) * dy;
  389. }
  390. else {
  391. yVia = this.to.y + (1 - factor) * dy;
  392. }
  393. }
  394. else { // continuous
  395. if (Math.abs(this.from.x - this.to.x) < Math.abs(this.from.y - this.to.y)) {
  396. if (this.from.y > this.to.y) {
  397. if (this.from.x < this.to.x) {
  398. // console.log(1)
  399. xVia = this.from.x + factor * dy;
  400. yVia = this.from.y - factor * dy;
  401. xVia = this.to.x < xVia ? this.to.x : xVia;
  402. }
  403. else if (this.from.x > this.to.x) {
  404. // console.log(2)
  405. xVia = this.from.x - factor * dy;
  406. yVia = this.from.y - factor * dy;
  407. xVia = this.to.x > xVia ? this.to.x : xVia;
  408. }
  409. }
  410. else if (this.from.y < this.to.y) {
  411. if (this.from.x < this.to.x) {
  412. // console.log(3)
  413. xVia = this.from.x + factor * dy;
  414. yVia = this.from.y + factor * dy;
  415. xVia = this.to.x < xVia ? this.to.x : xVia;
  416. }
  417. else if (this.from.x > this.to.x) {
  418. // console.log(4, this.from.x, this.to.x)
  419. xVia = this.from.x - factor * dy;
  420. yVia = this.from.y + factor * dy;
  421. xVia = this.to.x > xVia ? this.to.x : xVia;
  422. }
  423. }
  424. }
  425. else if (Math.abs(this.from.x - this.to.x) > Math.abs(this.from.y - this.to.y)) {
  426. if (this.from.y > this.to.y) {
  427. if (this.from.x < this.to.x) {
  428. // console.log(5)
  429. xVia = this.from.x + factor * dx;
  430. yVia = this.from.y - factor * dx;
  431. yVia = this.to.y > yVia ? this.to.y : yVia;
  432. }
  433. else if (this.from.x > this.to.x) {
  434. // console.log(6)
  435. xVia = this.from.x - factor * dx;
  436. yVia = this.from.y - factor * dx;
  437. yVia = this.to.y > yVia ? this.to.y : yVia;
  438. }
  439. }
  440. else if (this.from.y < this.to.y) {
  441. if (this.from.x < this.to.x) {
  442. // console.log(7)
  443. xVia = this.from.x + factor * dx;
  444. yVia = this.from.y + factor * dx;
  445. yVia = this.to.y < yVia ? this.to.y : yVia;
  446. }
  447. else if (this.from.x > this.to.x) {
  448. // console.log(8)
  449. xVia = this.from.x - factor * dx;
  450. yVia = this.from.y + factor * dx;
  451. yVia = this.to.y < yVia ? this.to.y : yVia;
  452. }
  453. }
  454. }
  455. }
  456. return {x: xVia, y: yVia};
  457. }
  458. };
  459. /**
  460. * Draw a line between two nodes
  461. * @param {CanvasRenderingContext2D} ctx
  462. * @private
  463. */
  464. Edge.prototype._line = function (ctx) {
  465. // draw a straight line
  466. ctx.beginPath();
  467. ctx.moveTo(this.from.x, this.from.y);
  468. if (this.options.smoothCurves.enabled == true) {
  469. if (this.options.smoothCurves.dynamic == false) {
  470. var via = this._getViaCoordinates();
  471. if (via.x == null) {
  472. ctx.lineTo(this.to.x, this.to.y);
  473. ctx.stroke();
  474. return null;
  475. }
  476. else {
  477. // this.via.x = via.x;
  478. // this.via.y = via.y;
  479. ctx.quadraticCurveTo(via.x,via.y,this.to.x, this.to.y);
  480. ctx.stroke();
  481. return via;
  482. }
  483. }
  484. else {
  485. ctx.quadraticCurveTo(this.via.x,this.via.y,this.to.x, this.to.y);
  486. ctx.stroke();
  487. return this.via;
  488. }
  489. }
  490. else {
  491. ctx.lineTo(this.to.x, this.to.y);
  492. ctx.stroke();
  493. return null;
  494. }
  495. };
  496. /**
  497. * Draw a line from a node to itself, a circle
  498. * @param {CanvasRenderingContext2D} ctx
  499. * @param {Number} x
  500. * @param {Number} y
  501. * @param {Number} radius
  502. * @private
  503. */
  504. Edge.prototype._circle = function (ctx, x, y, radius) {
  505. // draw a circle
  506. ctx.beginPath();
  507. ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
  508. ctx.stroke();
  509. };
  510. /**
  511. * Draw label with white background and with the middle at (x, y)
  512. * @param {CanvasRenderingContext2D} ctx
  513. * @param {String} text
  514. * @param {Number} x
  515. * @param {Number} y
  516. * @private
  517. */
  518. Edge.prototype._label = function (ctx, text, x, y) {
  519. if (text) {
  520. ctx.font = ((this.from.selected || this.to.selected) ? "bold " : "") +
  521. this.options.fontSize + "px " + this.options.fontFace;
  522. var yLine;
  523. if (this.dirtyLabel == true) {
  524. var lines = String(text).split('\n');
  525. var lineCount = lines.length;
  526. var fontSize = Number(this.options.fontSize);
  527. yLine = y + (1 - lineCount) / 2 * fontSize;
  528. var width = ctx.measureText(lines[0]).width;
  529. for (var i = 1; i < lineCount; i++) {
  530. var lineWidth = ctx.measureText(lines[i]).width;
  531. width = lineWidth > width ? lineWidth : width;
  532. }
  533. var height = this.options.fontSize * lineCount;
  534. var left = x - width / 2;
  535. var top = y - height / 2;
  536. // cache
  537. this.labelDimensions = {top:top,left:left,width:width,height:height,yLine:yLine};
  538. }
  539. var yLine = this.labelDimensions.yLine;
  540. ctx.save();
  541. if (this.options.labelAlignment != "horizontal"){
  542. ctx.translate(x, yLine);
  543. this._rotateForLabelAlignment(ctx);
  544. x = 0;
  545. yLine = 0;
  546. }
  547. this._drawLabelRect(ctx);
  548. this._drawLabelText(ctx,x,yLine, lines, lineCount, fontSize);
  549. ctx.restore();
  550. }
  551. };
  552. /**
  553. * Rotates the canvas so the text is most readable
  554. * @param {CanvasRenderingContext2D} ctx
  555. * @private
  556. */
  557. Edge.prototype._rotateForLabelAlignment = function(ctx) {
  558. var dy = this.from.y - this.to.y;
  559. var dx = this.from.x - this.to.x;
  560. var angleInDegrees = Math.atan2(dy, dx);
  561. // rotate so label it is readable
  562. if((angleInDegrees < -1 && dx < 0) || (angleInDegrees > 0 && dx < 0)){
  563. angleInDegrees = angleInDegrees + Math.PI;
  564. }
  565. ctx.rotate(angleInDegrees);
  566. };
  567. /**
  568. * Draws the label rectangle
  569. * @param {CanvasRenderingContext2D} ctx
  570. * @param {String} labelAlignment
  571. * @private
  572. */
  573. Edge.prototype._drawLabelRect = function(ctx) {
  574. if (this.options.fontFill !== undefined && this.options.fontFill !== null && this.options.fontFill !== "none") {
  575. ctx.fillStyle = this.options.fontFill;
  576. var lineMargin = 2;
  577. if (this.options.labelAlignment == 'line-center') {
  578. ctx.fillRect(-this.labelDimensions.width * 0.5, -this.labelDimensions.height * 0.5, this.labelDimensions.width, this.labelDimensions.height);
  579. }
  580. else if (this.options.labelAlignment == 'line-above') {
  581. ctx.fillRect(-this.labelDimensions.width * 0.5, -(this.labelDimensions.height + lineMargin), this.labelDimensions.width, this.labelDimensions.height);
  582. }
  583. else if (this.options.labelAlignment == 'line-below') {
  584. ctx.fillRect(-this.labelDimensions.width * 0.5, lineMargin, this.labelDimensions.width, this.labelDimensions.height);
  585. }
  586. else {
  587. ctx.fillRect(this.labelDimensions.left, this.labelDimensions.top, this.labelDimensions.width, this.labelDimensions.height);
  588. }
  589. }
  590. };
  591. /**
  592. * Draws the label text
  593. * @param {CanvasRenderingContext2D} ctx
  594. * @param {Number} x
  595. * @param {Number} yLine
  596. * @param {Array} lines
  597. * @param {Number} lineCount
  598. * @param {Number} fontSize
  599. * @private
  600. */
  601. Edge.prototype._drawLabelText = function(ctx, x, yLine, lines, lineCount, fontSize) {
  602. // draw text
  603. ctx.fillStyle = this.options.fontColor || "black";
  604. ctx.textAlign = "center";
  605. // check for label alignment
  606. if (this.options.labelAlignment != 'horizontal') {
  607. var lineMargin = 2;
  608. if (this.options.labelAlignment == 'line-above') {
  609. ctx.textBaseline = "alphabetic";
  610. yLine -= 2 * lineMargin; // distance from edge, required because we use alphabetic. Alphabetic has less difference between browsers
  611. }
  612. else if (this.options.labelAlignment == 'line-below') {
  613. ctx.textBaseline = "hanging";
  614. yLine += 2 * lineMargin;// distance from edge, required because we use hanging. Hanging has less difference between browsers
  615. }
  616. else {
  617. ctx.textBaseline = "middle";
  618. }
  619. }
  620. else {
  621. ctx.textBaseline = "middle";
  622. }
  623. // check for strokeWidth
  624. if (this.options.fontStrokeWidth > 0){
  625. ctx.lineWidth = this.options.fontStrokeWidth;
  626. ctx.strokeStyle = this.options.fontStrokeColor;
  627. ctx.lineJoin = 'round';
  628. }
  629. for (var i = 0; i < lineCount; i++) {
  630. if(this.options.fontStrokeWidth > 0){
  631. ctx.strokeText(lines[i], x, yLine);
  632. }
  633. ctx.fillText(lines[i], x, yLine);
  634. yLine += fontSize;
  635. }
  636. };
  637. /**
  638. * Redraw a edge as a dashed line
  639. * Draw this edge in the given canvas
  640. * @author David Jordan
  641. * @date 2012-08-08
  642. * The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
  643. * @param {CanvasRenderingContext2D} ctx
  644. * @private
  645. */
  646. Edge.prototype._drawDashLine = function(ctx) {
  647. // set style
  648. ctx.strokeStyle = this._getColor();
  649. ctx.lineWidth = this._getLineWidth();
  650. var via = null;
  651. // only firefox and chrome support this method, else we use the legacy one.
  652. if (ctx.setLineDash !== undefined) {
  653. ctx.save();
  654. // configure the dash pattern
  655. var pattern = [0];
  656. if (this.options.dash.length !== undefined && this.options.dash.gap !== undefined) {
  657. pattern = [this.options.dash.length,this.options.dash.gap];
  658. }
  659. else {
  660. pattern = [5,5];
  661. }
  662. // set dash settings for chrome or firefox
  663. ctx.setLineDash(pattern);
  664. ctx.lineDashOffset = 0;
  665. // draw the line
  666. via = this._line(ctx);
  667. // restore the dash settings.
  668. ctx.setLineDash([0]);
  669. ctx.lineDashOffset = 0;
  670. ctx.restore();
  671. }
  672. else { // unsupporting smooth lines
  673. // draw dashed line
  674. ctx.beginPath();
  675. ctx.lineCap = 'round';
  676. if (this.options.dash.altLength !== undefined) //If an alt dash value has been set add to the array this value
  677. {
  678. ctx.dashedLine(this.from.x,this.from.y,this.to.x,this.to.y,
  679. [this.options.dash.length,this.options.dash.gap,this.options.dash.altLength,this.options.dash.gap]);
  680. }
  681. else if (this.options.dash.length !== undefined && this.options.dash.gap !== undefined) //If a dash and gap value has been set add to the array this value
  682. {
  683. ctx.dashedLine(this.from.x,this.from.y,this.to.x,this.to.y,
  684. [this.options.dash.length,this.options.dash.gap]);
  685. }
  686. else //If all else fails draw a line
  687. {
  688. ctx.moveTo(this.from.x, this.from.y);
  689. ctx.lineTo(this.to.x, this.to.y);
  690. }
  691. ctx.stroke();
  692. }
  693. // draw label
  694. if (this.label) {
  695. var point;
  696. if (this.options.smoothCurves.enabled == true && via != null) {
  697. var midpointX = 0.5*(0.5*(this.from.x + via.x) + 0.5*(this.to.x + via.x));
  698. var midpointY = 0.5*(0.5*(this.from.y + via.y) + 0.5*(this.to.y + via.y));
  699. point = {x:midpointX, y:midpointY};
  700. }
  701. else {
  702. point = this._pointOnLine(0.5);
  703. }
  704. this._label(ctx, this.label, point.x, point.y);
  705. }
  706. };
  707. /**
  708. * Get a point on a line
  709. * @param {Number} percentage. Value between 0 (line start) and 1 (line end)
  710. * @return {Object} point
  711. * @private
  712. */
  713. Edge.prototype._pointOnLine = function (percentage) {
  714. return {
  715. x: (1 - percentage) * this.from.x + percentage * this.to.x,
  716. y: (1 - percentage) * this.from.y + percentage * this.to.y
  717. }
  718. };
  719. /**
  720. * Get a point on a circle
  721. * @param {Number} x
  722. * @param {Number} y
  723. * @param {Number} radius
  724. * @param {Number} percentage. Value between 0 (line start) and 1 (line end)
  725. * @return {Object} point
  726. * @private
  727. */
  728. Edge.prototype._pointOnCircle = function (x, y, radius, percentage) {
  729. var angle = (percentage - 3/8) * 2 * Math.PI;
  730. return {
  731. x: x + radius * Math.cos(angle),
  732. y: y - radius * Math.sin(angle)
  733. }
  734. };
  735. /**
  736. * Redraw a edge as a line with an arrow halfway the line
  737. * Draw this edge in the given canvas
  738. * The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
  739. * @param {CanvasRenderingContext2D} ctx
  740. * @private
  741. */
  742. Edge.prototype._drawArrowCenter = function(ctx) {
  743. var point;
  744. // set style
  745. ctx.strokeStyle = this._getColor();
  746. ctx.fillStyle = ctx.strokeStyle;
  747. ctx.lineWidth = this._getLineWidth();
  748. if (this.from != this.to) {
  749. // draw line
  750. var via = this._line(ctx);
  751. var angle = Math.atan2((this.to.y - this.from.y), (this.to.x - this.from.x));
  752. var length = (10 + 5 * this.options.width) * this.options.arrowScaleFactor;
  753. // draw an arrow halfway the line
  754. if (this.options.smoothCurves.enabled == true && via != null) {
  755. var midpointX = 0.5*(0.5*(this.from.x + via.x) + 0.5*(this.to.x + via.x));
  756. var midpointY = 0.5*(0.5*(this.from.y + via.y) + 0.5*(this.to.y + via.y));
  757. point = {x:midpointX, y:midpointY};
  758. }
  759. else {
  760. point = this._pointOnLine(0.5);
  761. }
  762. ctx.arrow(point.x, point.y, angle, length);
  763. ctx.fill();
  764. ctx.stroke();
  765. // draw label
  766. if (this.label) {
  767. this._label(ctx, this.label, point.x, point.y);
  768. }
  769. }
  770. else {
  771. // draw circle
  772. var x, y;
  773. var radius = 0.25 * Math.max(100,this.physics.springLength);
  774. var node = this.from;
  775. if (!node.width) {
  776. node.resize(ctx);
  777. }
  778. if (node.width > node.height) {
  779. x = node.x + node.width * 0.5;
  780. y = node.y - radius;
  781. }
  782. else {
  783. x = node.x + radius;
  784. y = node.y - node.height * 0.5;
  785. }
  786. this._circle(ctx, x, y, radius);
  787. // draw all arrows
  788. var angle = 0.2 * Math.PI;
  789. var length = (10 + 5 * this.options.width) * this.options.arrowScaleFactor;
  790. point = this._pointOnCircle(x, y, radius, 0.5);
  791. ctx.arrow(point.x, point.y, angle, length);
  792. ctx.fill();
  793. ctx.stroke();
  794. // draw label
  795. if (this.label) {
  796. point = this._pointOnCircle(x, y, radius, 0.5);
  797. this._label(ctx, this.label, point.x, point.y);
  798. }
  799. }
  800. };
  801. Edge.prototype._pointOnBezier = function(t) {
  802. var via = this._getViaCoordinates();
  803. var x = Math.pow(1-t,2)*this.from.x + (2*t*(1 - t))*via.x + Math.pow(t,2)*this.to.x;
  804. var y = Math.pow(1-t,2)*this.from.y + (2*t*(1 - t))*via.y + Math.pow(t,2)*this.to.y;
  805. return {x:x,y:y};
  806. }
  807. /**
  808. * This function uses binary search to look for the point where the bezier curve crosses the border of the node.
  809. *
  810. * @param from
  811. * @param ctx
  812. * @returns {*}
  813. * @private
  814. */
  815. Edge.prototype._findBorderPosition = function(from,ctx) {
  816. var maxIterations = 10;
  817. var iteration = 0;
  818. var low = 0;
  819. var high = 1;
  820. var pos,angle,distanceToBorder, distanceToNodes, difference;
  821. var threshold = 0.2;
  822. var node = this.to;
  823. if (from == true) {
  824. node = this.from;
  825. }
  826. while (low <= high && iteration < maxIterations) {
  827. var middle = (low + high) * 0.5;
  828. pos = this._pointOnBezier(middle);
  829. angle = Math.atan2((node.y - pos.y), (node.x - pos.x));
  830. distanceToBorder = node.distanceToBorder(ctx,angle);
  831. distanceToNodes = Math.sqrt(Math.pow(pos.x-node.x,2) + Math.pow(pos.y-node.y,2));
  832. difference = distanceToBorder - distanceToNodes;
  833. if (Math.abs(difference) < threshold) {
  834. break; // found
  835. }
  836. else if (difference < 0) { // distance to nodes is larger than distance to border --> t needs to be bigger if we're looking at the to node.
  837. if (from == false) {
  838. low = middle;
  839. }
  840. else {
  841. high = middle;
  842. }
  843. }
  844. else {
  845. if (from == false) {
  846. high = middle;
  847. }
  848. else {
  849. low = middle;
  850. }
  851. }
  852. iteration++;
  853. }
  854. pos.t = middle;
  855. return pos;
  856. };
  857. /**
  858. * Redraw a edge as a line with an arrow
  859. * Draw this edge in the given canvas
  860. * The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
  861. * @param {CanvasRenderingContext2D} ctx
  862. * @private
  863. */
  864. Edge.prototype._drawArrow = function(ctx) {
  865. // set style
  866. ctx.strokeStyle = this._getColor();
  867. ctx.fillStyle = ctx.strokeStyle;
  868. ctx.lineWidth = this._getLineWidth();
  869. // set vars
  870. var angle, length, arrowPos;
  871. // if not connected to itself
  872. if (this.from != this.to) {
  873. // draw line
  874. this._line(ctx);
  875. // draw arrow head
  876. if (this.options.smoothCurves.enabled == true) {
  877. var via = this._getViaCoordinates();
  878. arrowPos = this._findBorderPosition(false, ctx);
  879. var guidePos = this._pointOnBezier(Math.max(0.0, arrowPos.t - 0.1))
  880. angle = Math.atan2((arrowPos.y - guidePos.y), (arrowPos.x - guidePos.x));
  881. }
  882. else {
  883. angle = Math.atan2((this.to.y - this.from.y), (this.to.x - this.from.x));
  884. var dx = (this.to.x - this.from.x);
  885. var dy = (this.to.y - this.from.y);
  886. var edgeSegmentLength = Math.sqrt(dx * dx + dy * dy);
  887. var toBorderDist = this.to.distanceToBorder(ctx, angle);
  888. var toBorderPoint = (edgeSegmentLength - toBorderDist) / edgeSegmentLength;
  889. arrowPos = {};
  890. arrowPos.x = (1 - toBorderPoint) * this.from.x + toBorderPoint * this.to.x;
  891. arrowPos.y = (1 - toBorderPoint) * this.from.y + toBorderPoint * this.to.y;
  892. }
  893. // draw arrow at the end of the line
  894. length = (10 + 5 * this.options.width) * this.options.arrowScaleFactor;
  895. ctx.arrow(arrowPos.x,arrowPos.y, angle, length);
  896. ctx.fill();
  897. ctx.stroke();
  898. // draw label
  899. if (this.label) {
  900. var point;
  901. if (this.options.smoothCurves.enabled == true && via != null) {
  902. point = this._pointOnBezier(0.5);
  903. }
  904. else {
  905. point = this._pointOnLine(0.5);
  906. }
  907. this._label(ctx, this.label, point.x, point.y);
  908. }
  909. }
  910. else {
  911. // draw circle
  912. var node = this.from;
  913. var x, y, arrow;
  914. var radius = 0.25 * Math.max(100,this.physics.springLength);
  915. if (!node.width) {
  916. node.resize(ctx);
  917. }
  918. if (node.width > node.height) {
  919. x = node.x + node.width * 0.5;
  920. y = node.y - radius;
  921. arrow = {
  922. x: x,
  923. y: node.y,
  924. angle: 0.9 * Math.PI
  925. };
  926. }
  927. else {
  928. x = node.x + radius;
  929. y = node.y - node.height * 0.5;
  930. arrow = {
  931. x: node.x,
  932. y: y,
  933. angle: 0.6 * Math.PI
  934. };
  935. }
  936. ctx.beginPath();
  937. // TODO: similarly, for a line without arrows, draw to the border of the nodes instead of the center
  938. ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
  939. ctx.stroke();
  940. // draw all arrows
  941. var length = (10 + 5 * this.options.width) * this.options.arrowScaleFactor;
  942. ctx.arrow(arrow.x, arrow.y, arrow.angle, length);
  943. ctx.fill();
  944. ctx.stroke();
  945. // draw label
  946. if (this.label) {
  947. point = this._pointOnCircle(x, y, radius, 0.5);
  948. this._label(ctx, this.label, point.x, point.y);
  949. }
  950. }
  951. };
  952. /**
  953. * Calculate the distance between a point (x3,y3) and a line segment from
  954. * (x1,y1) to (x2,y2).
  955. * http://stackoverflow.com/questions/849211/shortest-distancae-between-a-point-and-a-line-segment
  956. * @param {number} x1
  957. * @param {number} y1
  958. * @param {number} x2
  959. * @param {number} y2
  960. * @param {number} x3
  961. * @param {number} y3
  962. * @private
  963. */
  964. Edge.prototype._getDistanceToEdge = function (x1,y1, x2,y2, x3,y3) { // x3,y3 is the point
  965. var returnValue = 0;
  966. if (this.from != this.to) {
  967. if (this.options.smoothCurves.enabled == true) {
  968. var xVia, yVia;
  969. if (this.options.smoothCurves.enabled == true && this.options.smoothCurves.dynamic == true) {
  970. xVia = this.via.x;
  971. yVia = this.via.y;
  972. }
  973. else {
  974. var via = this._getViaCoordinates();
  975. xVia = via.x;
  976. yVia = via.y;
  977. }
  978. var minDistance = 1e9;
  979. var distance;
  980. var i,t,x,y, lastX, lastY;
  981. for (i = 0; i < 10; i++) {
  982. t = 0.1*i;
  983. x = Math.pow(1-t,2)*x1 + (2*t*(1 - t))*xVia + Math.pow(t,2)*x2;
  984. y = Math.pow(1-t,2)*y1 + (2*t*(1 - t))*yVia + Math.pow(t,2)*y2;
  985. if (i > 0) {
  986. distance = this._getDistanceToLine(lastX,lastY,x,y, x3,y3);
  987. minDistance = distance < minDistance ? distance : minDistance;
  988. }
  989. lastX = x; lastY = y;
  990. }
  991. returnValue = minDistance;
  992. }
  993. else {
  994. returnValue = this._getDistanceToLine(x1,y1,x2,y2,x3,y3);
  995. }
  996. }
  997. else {
  998. var x, y, dx, dy;
  999. var radius = 0.25 * this.physics.springLength;
  1000. var node = this.from;
  1001. if (node.width > node.height) {
  1002. x = node.x + 0.5 * node.width;
  1003. y = node.y - radius;
  1004. }
  1005. else {
  1006. x = node.x + radius;
  1007. y = node.y - 0.5 * node.height;
  1008. }
  1009. dx = x - x3;
  1010. dy = y - y3;
  1011. returnValue = Math.abs(Math.sqrt(dx*dx + dy*dy) - radius);
  1012. }
  1013. if (this.labelDimensions.left < x3 &&
  1014. this.labelDimensions.left + this.labelDimensions.width > x3 &&
  1015. this.labelDimensions.top < y3 &&
  1016. this.labelDimensions.top + this.labelDimensions.height > y3) {
  1017. return 0;
  1018. }
  1019. else {
  1020. return returnValue;
  1021. }
  1022. };
  1023. Edge.prototype._getDistanceToLine = function(x1,y1,x2,y2,x3,y3) {
  1024. var px = x2-x1,
  1025. py = y2-y1,
  1026. something = px*px + py*py,
  1027. u = ((x3 - x1) * px + (y3 - y1) * py) / something;
  1028. if (u > 1) {
  1029. u = 1;
  1030. }
  1031. else if (u < 0) {
  1032. u = 0;
  1033. }
  1034. var x = x1 + u * px,
  1035. y = y1 + u * py,
  1036. dx = x - x3,
  1037. dy = y - y3;
  1038. //# Note: If the actual distance does not matter,
  1039. //# if you only want to compare what this function
  1040. //# returns to other results of this function, you
  1041. //# can just return the squared distance instead
  1042. //# (i.e. remove the sqrt) to gain a little performance
  1043. return Math.sqrt(dx*dx + dy*dy);
  1044. };
  1045. /**
  1046. * This allows the zoom level of the network to influence the rendering
  1047. *
  1048. * @param scale
  1049. */
  1050. Edge.prototype.setScale = function(scale) {
  1051. this.networkScaleInv = 1.0/scale;
  1052. };
  1053. Edge.prototype.select = function() {
  1054. this.selected = true;
  1055. };
  1056. Edge.prototype.unselect = function() {
  1057. this.selected = false;
  1058. };
  1059. Edge.prototype.positionBezierNode = function() {
  1060. if (this.via !== null && this.from !== null && this.to !== null) {
  1061. this.via.x = 0.5 * (this.from.x + this.to.x);
  1062. this.via.y = 0.5 * (this.from.y + this.to.y);
  1063. }
  1064. else if (this.via !== null) {
  1065. this.via.x = 0;
  1066. this.via.y = 0;
  1067. }
  1068. };
  1069. /**
  1070. * This function draws the control nodes for the manipulator.
  1071. * In order to enable this, only set the this.controlNodesEnabled to true.
  1072. * @param ctx
  1073. */
  1074. Edge.prototype._drawControlNodes = function(ctx) {
  1075. if (this.controlNodesEnabled == true) {
  1076. if (this.controlNodes.from === null && this.controlNodes.to === null) {
  1077. var nodeIdFrom = "edgeIdFrom:".concat(this.id);
  1078. var nodeIdTo = "edgeIdTo:".concat(this.id);
  1079. var constants = {
  1080. nodes:{group:'', radius:7, borderWidth:2, borderWidthSelected: 2},
  1081. physics:{damping:0},
  1082. clustering: {maxNodeSizeIncrements: 0 ,nodeScaling: {width:0, height: 0, radius:0}}
  1083. };
  1084. this.controlNodes.from = new Node(
  1085. {id:nodeIdFrom,
  1086. shape:'dot',
  1087. color:{background:'#ff0000', border:'#3c3c3c', highlight: {background:'#07f968'}}
  1088. },{},{},constants);
  1089. this.controlNodes.to = new Node(
  1090. {id:nodeIdTo,
  1091. shape:'dot',
  1092. color:{background:'#ff0000', border:'#3c3c3c', highlight: {background:'#07f968'}}
  1093. },{},{},constants);
  1094. }
  1095. this.controlNodes.positions = {};
  1096. if (this.controlNodes.from.selected == false) {
  1097. this.controlNodes.positions.from = this.getControlNodeFromPosition(ctx);
  1098. this.controlNodes.from.x = this.controlNodes.positions.from.x;
  1099. this.controlNodes.from.y = this.controlNodes.positions.from.y;
  1100. }
  1101. if (this.controlNodes.to.selected == false) {
  1102. this.controlNodes.positions.to = this.getControlNodeToPosition(ctx);
  1103. this.controlNodes.to.x = this.controlNodes.positions.to.x;
  1104. this.controlNodes.to.y = this.controlNodes.positions.to.y;
  1105. }
  1106. this.controlNodes.from.draw(ctx);
  1107. this.controlNodes.to.draw(ctx);
  1108. }
  1109. else {
  1110. this.controlNodes = {from:null, to:null, positions:{}};
  1111. }
  1112. };
  1113. /**
  1114. * Enable control nodes.
  1115. * @private
  1116. */
  1117. Edge.prototype._enableControlNodes = function() {
  1118. this.fromBackup = this.from;
  1119. this.toBackup = this.to;
  1120. this.controlNodesEnabled = true;
  1121. };
  1122. /**
  1123. * disable control nodes and remove from dynamicEdges from old node
  1124. * @private
  1125. */
  1126. Edge.prototype._disableControlNodes = function() {
  1127. this.fromId = this.from.id;
  1128. this.toId = this.to.id;
  1129. if (this.fromId != this.fromBackup.id) { // from was changed, remove edge from old 'from' node dynamic edges
  1130. this.fromBackup.detachEdge(this);
  1131. }
  1132. else if (this.toId != this.toBackup.id) { // to was changed, remove edge from old 'to' node dynamic edges
  1133. this.toBackup.detachEdge(this);
  1134. }
  1135. this.fromBackup = null;
  1136. this.toBackup = null;
  1137. this.controlNodesEnabled = false;
  1138. };
  1139. /**
  1140. * This checks if one of the control nodes is selected and if so, returns the control node object. Else it returns null.
  1141. * @param x
  1142. * @param y
  1143. * @returns {null}
  1144. * @private
  1145. */
  1146. Edge.prototype._getSelectedControlNode = function(x,y) {
  1147. var positions = this.controlNodes.positions;
  1148. var fromDistance = Math.sqrt(Math.pow(x - positions.from.x,2) + Math.pow(y - positions.from.y,2));
  1149. var toDistance = Math.sqrt(Math.pow(x - positions.to.x ,2) + Math.pow(y - positions.to.y ,2));
  1150. if (fromDistance < 15) {
  1151. this.connectedNode = this.from;
  1152. this.from = this.controlNodes.from;
  1153. return this.controlNodes.from;
  1154. }
  1155. else if (toDistance < 15) {
  1156. this.connectedNode = this.to;
  1157. this.to = this.controlNodes.to;
  1158. return this.controlNodes.to;
  1159. }
  1160. else {
  1161. return null;
  1162. }
  1163. };
  1164. /**
  1165. * this resets the control nodes to their original position.
  1166. * @private
  1167. */
  1168. Edge.prototype._restoreControlNodes = function() {
  1169. if (this.controlNodes.from.selected == true) {
  1170. this.from = this.connectedNode;
  1171. this.connectedNode = null;
  1172. this.controlNodes.from.unselect();
  1173. }
  1174. else if (this.controlNodes.to.selected == true) {
  1175. this.to = this.connectedNode;
  1176. this.connectedNode = null;
  1177. this.controlNodes.to.unselect();
  1178. }
  1179. };
  1180. /**
  1181. * this calculates the position of the control nodes on the edges of the parent nodes.
  1182. *
  1183. * @param ctx
  1184. * @returns {x: *, y: *}
  1185. */
  1186. Edge.prototype.getControlNodeFromPosition = function(ctx) {
  1187. // draw arrow head
  1188. var controlnodeFromPos;
  1189. if (this.options.smoothCurves.enabled == true) {
  1190. controlnodeFromPos = this._findBorderPosition(true, ctx);
  1191. }
  1192. else {
  1193. var angle = Math.atan2((this.to.y - this.from.y), (this.to.x - this.from.x));
  1194. var dx = (this.to.x - this.from.x);
  1195. var dy = (this.to.y - this.from.y);
  1196. var edgeSegmentLength = Math.sqrt(dx * dx + dy * dy);
  1197. var fromBorderDist = this.from.distanceToBorder(ctx, angle + Math.PI);
  1198. var fromBorderPoint = (edgeSegmentLength - fromBorderDist) / edgeSegmentLength;
  1199. controlnodeFromPos = {};
  1200. controlnodeFromPos.x = (fromBorderPoint) * this.from.x + (1 - fromBorderPoint) * this.to.x;
  1201. controlnodeFromPos.y = (fromBorderPoint) * this.from.y + (1 - fromBorderPoint) * this.to.y;
  1202. }
  1203. return controlnodeFromPos;
  1204. };
  1205. /**
  1206. * this calculates the position of the control nodes on the edges of the parent nodes.
  1207. *
  1208. * @param ctx
  1209. * @returns {{from: {x: number, y: number}, to: {x: *, y: *}}}
  1210. */
  1211. Edge.prototype.getControlNodeToPosition = function(ctx) {
  1212. // draw arrow head
  1213. var controlnodeFromPos,controlnodeToPos;
  1214. if (this.options.smoothCurves.enabled == true) {
  1215. controlnodeToPos = this._findBorderPosition(false, ctx);
  1216. }
  1217. else {
  1218. var angle = Math.atan2((this.to.y - this.from.y), (this.to.x - this.from.x));
  1219. var dx = (this.to.x - this.from.x);
  1220. var dy = (this.to.y - this.from.y);
  1221. var edgeSegmentLength = Math.sqrt(dx * dx + dy * dy);
  1222. var toBorderDist = this.to.distanceToBorder(ctx, angle);
  1223. var toBorderPoint = (edgeSegmentLength - toBorderDist) / edgeSegmentLength;
  1224. controlnodeToPos = {};
  1225. controlnodeToPos.x = (1 - toBorderPoint) * this.from.x + toBorderPoint * this.to.x;
  1226. controlnodeToPos.y = (1 - toBorderPoint) * this.from.y + toBorderPoint * this.to.y;
  1227. }
  1228. return controlnodeToPos;
  1229. };
  1230. module.exports = Edge;