jsPlumb-defaults-1.3.5-RC1.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  1. /*
  2. * jsPlumb
  3. *
  4. * Title:jsPlumb 1.3.5
  5. *
  6. * Provides a way to visually connect elements on an HTML page, using either SVG, Canvas
  7. * elements, or VML.
  8. *
  9. * This file contains the default Connectors, Endpoint and Overlay definitions.
  10. *
  11. * Copyright (c) 2010 - 2012 Simon Porritt (http://jsplumb.org)
  12. *
  13. * http://jsplumb.org
  14. * http://github.com/sporritt/jsplumb
  15. * http://code.google.com/p/jsplumb
  16. *
  17. * Dual licensed under the MIT and GPL2 licenses.
  18. */
  19. (function() {
  20. /**
  21. *
  22. * Helper class to consume unused mouse events by components that are DOM elements and
  23. * are used by all of the different rendering modes.
  24. *
  25. */
  26. jsPlumb.DOMElementComponent = function(params) {
  27. jsPlumb.jsPlumbUIComponent.apply(this, arguments);
  28. // when render mode is canvas, these functions may be called by the canvas mouse handler.
  29. // this component is safe to pipe this stuff to /dev/null.
  30. this.mousemove =
  31. this.dblclick =
  32. this.click =
  33. this.mousedown =
  34. this.mouseup = function(e) { };
  35. };
  36. /**
  37. * Class: Connectors.Straight
  38. * The Straight connector draws a simple straight line between the two anchor points. It does not have any constructor parameters.
  39. */
  40. jsPlumb.Connectors.Straight = function() {
  41. this.type = "Straight";
  42. var self = this,
  43. currentPoints = null,
  44. _m, _m2, _b, _dx, _dy, _theta, _theta2, _sx, _sy, _tx, _ty, _segment, _length;
  45. /**
  46. * Computes the new size and position of the canvas.
  47. */
  48. this.compute = function(sourcePos, targetPos, sourceEndpoint, targetEndpoint, sourceAnchor, targetAnchor, lineWidth, minWidth) {
  49. var w = Math.abs(sourcePos[0] - targetPos[0]),
  50. h = Math.abs(sourcePos[1] - targetPos[1]),
  51. // these are padding to ensure the whole connector line appears
  52. xo = 0.45 * w, yo = 0.45 * h;
  53. // these are padding to ensure the whole connector line appears
  54. w *= 1.9; h *=1.9;
  55. var x = Math.min(sourcePos[0], targetPos[0]) - xo;
  56. var y = Math.min(sourcePos[1], targetPos[1]) - yo;
  57. // minimum size is 2 * line Width if minWidth was not given.
  58. var calculatedMinWidth = Math.max(2 * lineWidth, minWidth);
  59. if (w < calculatedMinWidth) {
  60. w = calculatedMinWidth;
  61. x = sourcePos[0] + ((targetPos[0] - sourcePos[0]) / 2) - (calculatedMinWidth / 2);
  62. xo = (w - Math.abs(sourcePos[0]-targetPos[0])) / 2;
  63. }
  64. if (h < calculatedMinWidth) {
  65. h = calculatedMinWidth;
  66. y = sourcePos[1] + ((targetPos[1] - sourcePos[1]) / 2) - (calculatedMinWidth / 2);
  67. yo = (h - Math.abs(sourcePos[1]-targetPos[1])) / 2;
  68. }
  69. _sx = sourcePos[0] < targetPos[0] ? xo : w-xo;
  70. _sy = sourcePos[1] < targetPos[1] ? yo:h-yo;
  71. _tx = sourcePos[0] < targetPos[0] ? w-xo : xo;
  72. _ty = sourcePos[1] < targetPos[1] ? h-yo : yo;
  73. currentPoints = [ x, y, w, h, _sx, _sy, _tx, _ty ];
  74. _dx = _tx - _sx, _dy = _ty - _sy;
  75. //_m = _dy / _dx, _m2 = -1 / _m;
  76. _m = jsPlumb.util.gradient({x:_sx, y:_sy}, {x:_tx, y:_ty}), _m2 = -1 / _m;
  77. _b = -1 * ((_m * _sx) - _sy);
  78. _theta = Math.atan(_m); _theta2 = Math.atan(_m2);
  79. //_segment = jsPlumb.util.segment({x:_sx, y:_sy}, {x:_tx, y:_ty});
  80. _length = Math.sqrt((_dx * _dx) + (_dy * _dy));
  81. return currentPoints;
  82. };
  83. /**
  84. * returns the point on the connector's path that is 'location' along the length of the path, where 'location' is a decimal from
  85. * 0 to 1 inclusive. for the straight line connector this is simple maths. for Bezier, not so much.
  86. */
  87. this.pointOnPath = function(location) {
  88. if (location == 0)
  89. return { x:_sx, y:_sy };
  90. else if (location == 1)
  91. return { x:_tx, y:_ty };
  92. else
  93. return jsPlumb.util.pointOnLine({x:_sx, y:_sy}, {x:_tx, y:_ty}, location * _length);
  94. };
  95. /**
  96. * returns the gradient of the connector at the given point - which for us is constant.
  97. */
  98. this.gradientAtPoint = function(location) {
  99. return _m;
  100. };
  101. /**
  102. * returns the point on the connector's path that is 'distance' along the length of the path from 'location', where
  103. * 'location' is a decimal from 0 to 1 inclusive, and 'distance' is a number of pixels.
  104. * this hands off to jsPlumb.util to do the maths, supplying our gradient and position and whether or
  105. * not the coords should be flipped
  106. */
  107. this.pointAlongPathFrom = function(location, distance) {
  108. var p = self.pointOnPath(location);
  109. return jsPlumb.util.pointOnLine(p, {x:_tx,y:_ty}, distance);
  110. };
  111. };
  112. /**
  113. * Class:Connectors.Bezier
  114. * This Connector draws a Bezier curve with two control points. You can provide a 'curviness' value which gets applied to jsPlumb's
  115. * internal voodoo machine and ends up generating locations for the two control points. See the constructor documentation below.
  116. */
  117. /**
  118. * Function:Constructor
  119. *
  120. * Parameters:
  121. * curviness - How 'curvy' you want the curve to be! This is a directive for the placement of control points, not endpoints of the curve, so your curve does not
  122. * actually touch the given point, but it has the tendency to lean towards it. The larger this value, the greater the curve is pulled from a straight line.
  123. * Optional; defaults to 150.
  124. *
  125. */
  126. jsPlumb.Connectors.Bezier = function(params) {
  127. var self = this;
  128. params = params || {};
  129. this.majorAnchor = params.curviness || 150;
  130. this.minorAnchor = 10;
  131. var currentPoints = null;
  132. this.type = "Bezier";
  133. this._findControlPoint = function(point, sourceAnchorPosition, targetAnchorPosition, sourceEndpoint, targetEndpoint, sourceAnchor, targetAnchor) {
  134. // determine if the two anchors are perpendicular to each other in their orientation. we swap the control
  135. // points around if so (code could be tightened up)
  136. var soo = sourceAnchor.getOrientation(sourceEndpoint),
  137. too = targetAnchor.getOrientation(targetEndpoint),
  138. perpendicular = soo[0] != too[0] || soo[1] == too[1],
  139. p = [],
  140. ma = self.majorAnchor, mi = self.minorAnchor;
  141. if (!perpendicular) {
  142. if (soo[0] == 0) // X
  143. p.push(sourceAnchorPosition[0] < targetAnchorPosition[0] ? point[0] + mi : point[0] - mi);
  144. else p.push(point[0] - (ma * soo[0]));
  145. if (soo[1] == 0) // Y
  146. p.push(sourceAnchorPosition[1] < targetAnchorPosition[1] ? point[1] + mi : point[1] - mi);
  147. else p.push(point[1] + (ma * too[1]));
  148. }
  149. else {
  150. if (too[0] == 0) // X
  151. p.push(targetAnchorPosition[0] < sourceAnchorPosition[0] ? point[0] + mi : point[0] - mi);
  152. else p.push(point[0] + (ma * too[0]));
  153. if (too[1] == 0) // Y
  154. p.push(targetAnchorPosition[1] < sourceAnchorPosition[1] ? point[1] + mi : point[1] - mi);
  155. else p.push(point[1] + (ma * soo[1]));
  156. }
  157. return p;
  158. };
  159. var _CP, _CP2, _sx, _tx, _ty, _sx, _sy, _canvasX, _canvasY, _w, _h;
  160. this.compute = function(sourcePos, targetPos, sourceEndpoint, targetEndpoint, sourceAnchor, targetAnchor, lineWidth, minWidth) {
  161. lineWidth = lineWidth || 0;
  162. _w = Math.abs(sourcePos[0] - targetPos[0]) + lineWidth;
  163. _h = Math.abs(sourcePos[1] - targetPos[1]) + lineWidth;
  164. _canvasX = Math.min(sourcePos[0], targetPos[0])-(lineWidth/2);
  165. _canvasY = Math.min(sourcePos[1], targetPos[1])-(lineWidth/2);
  166. _sx = sourcePos[0] < targetPos[0] ? _w - (lineWidth/2): (lineWidth/2);
  167. _sy = sourcePos[1] < targetPos[1] ? _h - (lineWidth/2) : (lineWidth/2);
  168. _tx = sourcePos[0] < targetPos[0] ? (lineWidth/2) : _w - (lineWidth/2);
  169. _ty = sourcePos[1] < targetPos[1] ? (lineWidth/2) : _h - (lineWidth/2);
  170. _CP = self._findControlPoint([_sx,_sy], sourcePos, targetPos, sourceEndpoint, targetEndpoint, sourceAnchor, targetAnchor);
  171. _CP2 = self._findControlPoint([_tx,_ty], targetPos, sourcePos, sourceEndpoint, targetEndpoint, targetAnchor, sourceAnchor);
  172. var minx1 = Math.min(_sx,_tx), minx2 = Math.min(_CP[0], _CP2[0]), minx = Math.min(minx1,minx2),
  173. maxx1 = Math.max(_sx,_tx), maxx2 = Math.max(_CP[0], _CP2[0]), maxx = Math.max(maxx1,maxx2);
  174. if (maxx > _w) _w = maxx;
  175. if (minx < 0) {
  176. _canvasX += minx; var ox = Math.abs(minx);
  177. _w += ox; _CP[0] += ox; _sx += ox; _tx +=ox; _CP2[0] += ox;
  178. }
  179. var miny1 = Math.min(_sy,_ty), miny2 = Math.min(_CP[1], _CP2[1]), miny = Math.min(miny1,miny2),
  180. maxy1 = Math.max(_sy,_ty), maxy2 = Math.max(_CP[1], _CP2[1]), maxy = Math.max(maxy1,maxy2);
  181. if (maxy > _h) _h = maxy;
  182. if (miny < 0) {
  183. _canvasY += miny; var oy = Math.abs(miny);
  184. _h += oy; _CP[1] += oy; _sy += oy; _ty +=oy; _CP2[1] += oy;
  185. }
  186. if (minWidth && _w < minWidth) {
  187. var posAdjust = (minWidth - _w) / 2;
  188. _w = minWidth;
  189. _canvasX -= posAdjust; _sx = _sx + posAdjust ; _tx = _tx + posAdjust; _CP[0] = _CP[0] + posAdjust; _CP2[0] = _CP2[0] + posAdjust;
  190. }
  191. if (minWidth && _h < minWidth) {
  192. var posAdjust = (minWidth - _h) / 2;
  193. _h = minWidth;
  194. _canvasY -= posAdjust; _sy = _sy + posAdjust ; _ty = _ty + posAdjust; _CP[1] = _CP[1] + posAdjust; _CP2[1] = _CP2[1] + posAdjust;
  195. }
  196. currentPoints = [_canvasX, _canvasY, _w, _h, _sx, _sy, _tx, _ty, _CP[0], _CP[1], _CP2[0], _CP2[1] ];
  197. return currentPoints;
  198. };
  199. var _makeCurve = function() {
  200. return [
  201. { x:_sx, y:_sy },
  202. { x:_CP[0], y:_CP[1] },
  203. { x:_CP2[0], y:_CP2[1] },
  204. { x:_tx, y:_ty }
  205. ];
  206. };
  207. /**
  208. * returns the point on the connector's path that is 'location' along the length of the path, where 'location' is a decimal from
  209. * 0 to 1 inclusive. for the straight line connector this is simple maths. for Bezier, not so much.
  210. */
  211. this.pointOnPath = function(location) {
  212. return jsBezier.pointOnCurve(_makeCurve(), location);
  213. };
  214. /**
  215. * returns the gradient of the connector at the given point.
  216. */
  217. this.gradientAtPoint = function(location) {
  218. return jsBezier.gradientAtPoint(_makeCurve(), location);
  219. };
  220. /**
  221. * for Bezier curves this method is a little tricky, cos calculating path distance algebraically is notoriously difficult.
  222. * this method is iterative, jumping forward .05% of the path at a time and summing the distance between this point and the previous
  223. * one, until the sum reaches 'distance'. the method may turn out to be computationally expensive; we'll see.
  224. * another drawback of this method is that if the connector gets quite long, .05% of the length of it is not necessarily smaller
  225. * than the desired distance, in which case the loop returns immediately and the arrow is mis-shapen. so a better strategy might be to
  226. * calculate the step as a function of distance/distance between endpoints.
  227. */
  228. this.pointAlongPathFrom = function(location, distance) {
  229. return jsBezier.pointAlongCurveFrom(_makeCurve(), location, distance);
  230. };
  231. };
  232. /**
  233. * Class: Connectors.Flowchart
  234. * Provides 'flowchart' connectors, consisting of vertical and horizontal line segments.
  235. */
  236. /**
  237. * Function: Constructor
  238. *
  239. * Parameters:
  240. * stub - minimum length for the stub at each end of the connector. defaults to 30 pixels.
  241. */
  242. jsPlumb.Connectors.Flowchart = function(params) {
  243. this.type = "Flowchart";
  244. params = params || {};
  245. var self = this,
  246. minStubLength = params.stub || params.minStubLength /* bwds compat. */ || 30,
  247. segments = [],
  248. totalLength = 0,
  249. segmentProportions = [],
  250. segmentProportionalLengths = [],
  251. points = [],
  252. swapX,
  253. swapY,
  254. /**
  255. * recalculates the points at which the segments begin and end, proportional to the total length travelled
  256. * by all the segments that constitute the connector. we use this to help with pointOnPath calculations.
  257. */
  258. updateSegmentProportions = function(startX, startY, endX, endY) {
  259. var curLoc = 0;
  260. for (var i = 0; i < segments.length; i++) {
  261. segmentProportionalLengths[i] = segments[i][5] / totalLength;
  262. segmentProportions[i] = [curLoc, (curLoc += (segments[i][5] / totalLength)) ];
  263. }
  264. },
  265. appendSegmentsToPoints = function() {
  266. points.push(segments.length);
  267. for (var i = 0; i < segments.length; i++) {
  268. points.push(segments[i][0]);
  269. points.push(segments[i][1]);
  270. }
  271. },
  272. /**
  273. * helper method to add a segment.
  274. */
  275. addSegment = function(x, y, sx, sy, tx, ty) {
  276. var lx = segments.length == 0 ? sx : segments[segments.length - 1][0],
  277. ly = segments.length == 0 ? sy : segments[segments.length - 1][1],
  278. m = x == lx ? Infinity : 0,
  279. l = Math.abs(x == lx ? y - ly : x - lx);
  280. segments.push([x, y, lx, ly, m, l]);
  281. totalLength += l;
  282. },
  283. /**
  284. * returns [segment, proportion of travel in segment, segment index] for the segment
  285. * that contains the point which is 'location' distance along the entire path, where
  286. * 'location' is a decimal between 0 and 1 inclusive. in this connector type, paths
  287. * are made up of a list of segments, each of which contributes some fraction to
  288. * the total length.
  289. */
  290. findSegmentForLocation = function(location) {
  291. var idx = segmentProportions.length - 1, inSegmentProportion = 0;
  292. for (var i = 0; i < segmentProportions.length; i++) {
  293. if (segmentProportions[i][1] >= location) {
  294. idx = i;
  295. inSegmentProportion = (location - segmentProportions[i][0]) / segmentProportionalLengths[i];
  296. break;
  297. }
  298. }
  299. return { segment:segments[idx], proportion:inSegmentProportion, index:idx };
  300. };
  301. this.compute = function(sourcePos, targetPos, sourceEndpoint, targetEndpoint,
  302. sourceAnchor, targetAnchor, lineWidth, minWidth, sourceInfo, targetInfo) {
  303. segments = [];
  304. totalLength = 0;
  305. segmentProportionalLengths = [];
  306. swapX = targetPos[0] < sourcePos[0];
  307. swapY = targetPos[1] < sourcePos[1];
  308. var lw = lineWidth || 1,
  309. offx = (lw / 2) + (minStubLength * 2),
  310. offy = (lw / 2) + (minStubLength * 2),
  311. so = sourceAnchor.orientation || sourceAnchor.getOrientation(sourceEndpoint),
  312. to = targetAnchor.orientation || targetAnchor.getOrientation(targetEndpoint),
  313. x = swapX ? targetPos[0] : sourcePos[0],
  314. y = swapY ? targetPos[1] : sourcePos[1],
  315. w = Math.abs(targetPos[0] - sourcePos[0]) + 2*offx,
  316. h = Math.abs(targetPos[1] - sourcePos[1]) + 2*offy;
  317. // if either anchor does not have an orientation set, we derive one from their relative
  318. // positions. we fix the axis to be the one in which the two elements are further apart, and
  319. // point each anchor at the other element. this is also used when dragging a new connection.
  320. if (so[0] == 0 && so[1] == 0 || to[0] == 0 && to[1] == 0) {
  321. var index = w > h ? 0 : 1, oIndex = [1,0][index];
  322. so = []; to = [];
  323. so[index] = sourcePos[index] > targetPos[index] ? -1 : 1;
  324. to[index] = sourcePos[index] > targetPos[index] ? 1 : -1;
  325. so[oIndex] = 0;
  326. to[oIndex] = 0;
  327. }
  328. if (w < minWidth) {
  329. offx += (minWidth - w) / 2;
  330. w = minWidth;
  331. }
  332. if (h < minWidth) {
  333. offy += (minWidth - h) / 2;
  334. h = minWidth;
  335. }
  336. var sx = swapX ? w-offx : offx,
  337. sy = swapY ? h-offy : offy,
  338. tx = swapX ? offx : w-offx ,
  339. ty = swapY ? offy : h-offy,
  340. startStubX = sx + (so[0] * minStubLength),
  341. startStubY = sy + (so[1] * minStubLength),
  342. endStubX = tx + (to[0] * minStubLength),
  343. endStubY = ty + (to[1] * minStubLength),
  344. isXGreaterThanStubTimes2 = Math.abs(sx - tx) > 2 * minStubLength,
  345. isYGreaterThanStubTimes2 = Math.abs(sy - ty) > 2 * minStubLength,
  346. midx = startStubX + ((endStubX - startStubX) / 2),
  347. midy = startStubY + ((endStubY - startStubY) / 2),
  348. oProduct = ((so[0] * to[0]) + (so[1] * to[1])),
  349. opposite = oProduct == -1,
  350. perpendicular = oProduct == 0,
  351. orthogonal = oProduct == 1;
  352. x -= offx; y -= offy;
  353. points = [x, y, w, h, sx, sy, tx, ty];
  354. var extraPoints = [];
  355. addSegment(startStubX, startStubY, sx, sy, tx, ty);
  356. var sourceAxis = so[0] == 0 ? "y" : "x",
  357. anchorOrientation = opposite ? "opposite" : orthogonal ? "orthogonal" : "perpendicular",
  358. segment = jsPlumb.util.segment([sx, sy], [tx, ty]),
  359. flipSourceSegments = so[sourceAxis == "x" ? 0 : 1] == -1,
  360. flipSegments = {
  361. "x":[null, 4, 3, 2, 1],
  362. "y":[null, 2, 1, 4, 3]
  363. }
  364. if (flipSourceSegments)
  365. segment = flipSegments[sourceAxis][segment];
  366. var findClearedLine = function(start, mult, anchorPos, dimension) {
  367. return start + (mult * (( 1 - anchorPos) * dimension) + minStubLength);
  368. //mx = so[0] == 0 ? startStubX + ((1 - sourceAnchor.x) * sourceInfo.width) + minStubLength : startStubX,
  369. },
  370. lineCalculators = {
  371. oppositex : function() {
  372. if (sourceEndpoint.elementId == targetEndpoint.elementId) {
  373. var _y = startStubY + ((1 - sourceAnchor.y) * sourceInfo.height) + minStubLength;
  374. return [ [ startStubX, _y ], [ endStubX, _y ]];
  375. }
  376. else if (isXGreaterThanStubTimes2 && (segment == 1 || segment == 2)) {
  377. return [[ midx, sy ], [ midx, ty ]];
  378. }
  379. else {
  380. return [[ startStubX, midy ], [endStubX, midy ]];
  381. }
  382. },
  383. orthogonalx : function() {
  384. if (segment == 1 || segment == 2) {
  385. return [ [ endStubX, startStubY ]];
  386. }
  387. else {
  388. return [ [ startStubX, endStubY ]];
  389. }
  390. },
  391. perpendicularx : function() {
  392. var my = (ty + sy) / 2;
  393. if ((segment == 1 && to[1] == 1) || (segment == 2 && to[1] == -1)) {
  394. if (Math.abs(tx - sx) > minStubLength)
  395. return [ [endStubX, startStubY ]];
  396. else
  397. return [ [startStubX, startStubY ], [ startStubX, my ], [ endStubX, my ]];
  398. }
  399. else if ((segment == 3 && to[1] == -1) || (segment == 4 && to[1] == 1)) {
  400. return [ [ startStubX, my ], [ endStubX, my ]];
  401. }
  402. else if ((segment == 3 && to[1] == 1) || (segment == 4 && to[1] == -1)) {
  403. return [ [ startStubX, endStubY ]];
  404. }
  405. else if ((segment == 1 && to[1] == -1) || (segment == 2 && to[1] == 1)) {
  406. if (Math.abs(tx - sx) > minStubLength)
  407. return [ [ midx, startStubY ], [ midx, endStubY ]];
  408. else
  409. return [ [ startStubX, endStubY ]];
  410. }
  411. },
  412. oppositey : function() {
  413. if (sourceEndpoint.elementId == targetEndpoint.elementId) {
  414. var _x = startStubX + ((1 - sourceAnchor.x) * sourceInfo.width) + minStubLength;
  415. return [ [ _x, startStubY ], [ _x, endStubY ]];
  416. }
  417. else if (isYGreaterThanStubTimes2 && (segment == 2 || segment == 3)) {
  418. return [[ sx, midy ], [ tx, midy ]];
  419. }
  420. else {
  421. return [[ midx, startStubY ], [midx, endStubY ]];
  422. }
  423. },
  424. orthogonaly : function() {
  425. if (segment == 2 || segment == 3) {
  426. return [ [ startStubX, endStubY ]];
  427. }
  428. else {
  429. return [ [ endStubX, startStubY ]];
  430. }
  431. },
  432. perpendiculary : function() {
  433. var mx = (tx + sx) / 2;
  434. if ((segment == 2 && to[0] == -1) || (segment == 3 && to[0] == 1)) {
  435. if (Math.abs(tx - sx) > minStubLength)
  436. return [ [startStubX, endStubY ]];
  437. else
  438. return [ [startStubX, midy ], [ endStubX, midy ]];
  439. }
  440. else if ((segment == 1 && to[0] == -1) || (segment == 4 && to[0] == 1)) {
  441. var mx = (tx + sx) / 2;
  442. return [ [ mx, startStubY ], [ mx, endStubY ]];
  443. }
  444. else if ((segment == 1 && to[0] == 1) || (segment == 4 && to[0] == -1)) {
  445. return [ [ endStubX, startStubY ]];
  446. }
  447. else if ((segment == 2 && to[0] == 1) || (segment == 3 && to[0] == -1)) {
  448. if (Math.abs(ty - sy) > minStubLength)
  449. return [ [ startStubX, midy ], [ endStubX, midy ]];
  450. else
  451. return [ [ endStubX, startStubY ]];
  452. }
  453. }
  454. };
  455. var pointFinder = lineCalculators[anchorOrientation + sourceAxis];
  456. var p = pointFinder();
  457. if (p) {
  458. for (var i = 0; i < p.length; i++) {
  459. addSegment(p[i][0], p[i][1], sx, sy, tx, ty);
  460. }
  461. }
  462. addSegment(endStubX, endStubY, sx, sy, tx, ty);
  463. addSegment(tx, ty, sx, sy, tx, ty);
  464. appendSegmentsToPoints();
  465. updateSegmentProportions(sx, sy, tx, ty);
  466. return points;
  467. };
  468. /**
  469. * returns the point on the connector's path that is 'location' along the length of the path, where 'location' is a decimal from
  470. * 0 to 1 inclusive. for this connector we must first figure out which segment the given point lies in, and then compute the x,y position
  471. * from our knowledge of the segment's start and end points.
  472. */
  473. this.pointOnPath = function(location) {
  474. return self.pointAlongPathFrom(location, 0);
  475. };
  476. /**
  477. * returns the gradient of the connector at the given point; the gradient will be either 0 or Infinity, depending on the direction of the
  478. * segment the point falls in. segment gradients are calculated in the compute method.
  479. */
  480. this.gradientAtPoint = function(location) {
  481. return segments[findSegmentForLocation(location)["index"]][4];
  482. };
  483. /**
  484. * returns the point on the connector's path that is 'distance' along the length of the path from 'location', where
  485. * 'location' is a decimal from 0 to 1 inclusive, and 'distance' is a number of pixels. when you consider this concept from the point of view
  486. * of this connector, it starts to become clear that there's a problem with the overlay paint code: given that this connector makes several
  487. * 90 degree turns, it's entirely possible that an arrow overlay could be forced to paint itself around a corner, which would look stupid. this is
  488. * because jsPlumb uses this method (and pointOnPath) so determine the locations of the various points that go to make up an overlay. a better
  489. * solution would probably be to just use pointOnPath along with gradientAtPoint, and draw the overlay so that its axis ran along
  490. * a tangent to the connector. for straight line connectors this would obviously mean the overlay was painted directly on the connector, since a
  491. * tangent to a straight line is the line itself, which is what we want; for this connector, and for beziers, the results would probably be better. an additional
  492. * advantage is, of course, that there's less computation involved doing it that way.
  493. */
  494. this.pointAlongPathFrom = function(location, distance) {
  495. var s = findSegmentForLocation(location), seg = s.segment, p = s.proportion, sl = segments[s.index][5], m = segments[s.index][4];
  496. var e = {
  497. x : m == Infinity ? seg[2] : seg[2] > seg[0] ? seg[0] + ((1 - p) * sl) - distance : seg[2] + (p * sl) + distance,
  498. y : m == 0 ? seg[3] : seg[3] > seg[1] ? seg[1] + ((1 - p) * sl) - distance : seg[3] + (p * sl) + distance,
  499. segmentInfo : s
  500. };
  501. return e;
  502. };
  503. };
  504. // ********************************* END OF CONNECTOR TYPES *******************************************************************
  505. // ********************************* ENDPOINT TYPES *******************************************************************
  506. /**
  507. * Class: Endpoints.Dot
  508. * A round endpoint, with default radius 10 pixels.
  509. */
  510. /**
  511. * Function: Constructor
  512. *
  513. * Parameters:
  514. *
  515. * radius - radius of the endpoint. defaults to 10 pixels.
  516. */
  517. jsPlumb.Endpoints.Dot = function(params) {
  518. this.type = "Dot";
  519. var self = this;
  520. params = params || {};
  521. this.radius = params.radius || 10;
  522. this.defaultOffset = 0.5 * this.radius;
  523. this.defaultInnerRadius = this.radius / 3;
  524. this.compute = function(anchorPoint, orientation, endpointStyle, connectorPaintStyle) {
  525. var r = endpointStyle.radius || self.radius,
  526. x = anchorPoint[0] - r,
  527. y = anchorPoint[1] - r;
  528. return [ x, y, r * 2, r * 2, r ];
  529. };
  530. };
  531. /**
  532. * Class: Endpoints.Rectangle
  533. * A Rectangular Endpoint, with default size 20x20.
  534. */
  535. /**
  536. * Function: Constructor
  537. *
  538. * Parameters:
  539. *
  540. * width - width of the endpoint. defaults to 20 pixels.
  541. * height - height of the endpoint. defaults to 20 pixels.
  542. */
  543. jsPlumb.Endpoints.Rectangle = function(params) {
  544. this.type = "Rectangle";
  545. var self = this;
  546. params = params || {};
  547. this.width = params.width || 20;
  548. this.height = params.height || 20;
  549. this.compute = function(anchorPoint, orientation, endpointStyle, connectorPaintStyle) {
  550. var width = endpointStyle.width || self.width,
  551. height = endpointStyle.height || self.height,
  552. x = anchorPoint[0] - (width/2),
  553. y = anchorPoint[1] - (height/2);
  554. return [ x, y, width, height];
  555. };
  556. };
  557. var DOMElementEndpoint = function(params) {
  558. jsPlumb.DOMElementComponent.apply(this, arguments);
  559. var self = this;
  560. var displayElements = [ ];
  561. this.getDisplayElements = function() {
  562. return displayElements;
  563. };
  564. this.appendDisplayElement = function(el) {
  565. displayElements.push(el);
  566. };
  567. };
  568. /**
  569. * Class: Endpoints.Image
  570. * Draws an image as the Endpoint.
  571. */
  572. /**
  573. * Function: Constructor
  574. *
  575. * Parameters:
  576. *
  577. * src - location of the image to use.
  578. */
  579. jsPlumb.Endpoints.Image = function(params) {
  580. this.type = "Image";
  581. DOMElementEndpoint.apply(this, arguments);
  582. var self = this,
  583. initialized = false,
  584. widthToUse = params.width,
  585. heightToUse = params.height,
  586. _onload = null,
  587. _endpoint = params.endpoint;
  588. this.img = new Image();
  589. self.ready = false;
  590. this.img.onload = function() {
  591. self.ready = true;
  592. widthToUse = widthToUse || self.img.width;
  593. heightToUse = heightToUse || self.img.height;
  594. if (_onload) {
  595. _onload(self);
  596. }
  597. };
  598. _endpoint.setImage = function(img, onload) {
  599. var s = img.constructor == String ? img : img.src;
  600. _onload = onload;
  601. self.img.src = img;
  602. };
  603. _endpoint.setImage(params.src || params.url, params.onload);
  604. this.compute = function(anchorPoint, orientation, endpointStyle, connectorPaintStyle) {
  605. self.anchorPoint = anchorPoint;
  606. if (self.ready) return [anchorPoint[0] - widthToUse / 2, anchorPoint[1] - heightToUse / 2,
  607. widthToUse, heightToUse];
  608. else return [0,0,0,0];
  609. };
  610. self.canvas = document.createElement("img"), initialized = false;
  611. self.canvas.style["margin"] = 0;
  612. self.canvas.style["padding"] = 0;
  613. self.canvas.style["outline"] = 0;
  614. self.canvas.style["position"] = "absolute";
  615. var clazz = params.cssClass ? " " + params.cssClass : "";
  616. self.canvas.className = jsPlumb.endpointClass + clazz;
  617. if (widthToUse) self.canvas.setAttribute("width", widthToUse);
  618. if (heightToUse) self.canvas.setAttribute("height", heightToUse);
  619. jsPlumb.appendElement(self.canvas, params.parent);
  620. self.attachListeners(self.canvas, self);
  621. var actuallyPaint = function(d, style, anchor) {
  622. if (!initialized) {
  623. self.canvas.setAttribute("src", self.img.src);
  624. initialized = true;
  625. }
  626. var x = self.anchorPoint[0] - (widthToUse / 2),
  627. y = self.anchorPoint[1] - (heightToUse / 2);
  628. jsPlumb.sizeCanvas(self.canvas, x, y, widthToUse, heightToUse);
  629. };
  630. this.paint = function(d, style, anchor) {
  631. if (self.ready) {
  632. actuallyPaint(d, style, anchor);
  633. }
  634. else {
  635. window.setTimeout(function() {
  636. self.paint(d, style, anchor);
  637. }, 200);
  638. }
  639. };
  640. };
  641. /**
  642. * Class: Endpoints.Blank
  643. * An Endpoint that paints nothing (visible) on the screen. Supports cssClass and hoverClass parameters like all Endpoints.
  644. */
  645. jsPlumb.Endpoints.Blank = function(params) {
  646. var self = this;
  647. this.type = "Blank";
  648. DOMElementEndpoint.apply(this, arguments);
  649. this.compute = function(anchorPoint, orientation, endpointStyle, connectorPaintStyle) {
  650. return [anchorPoint[0], anchorPoint[1],10,0];
  651. };
  652. self.canvas = document.createElement("div");
  653. self.canvas.style.display = "block";
  654. self.canvas.style.width = "1px";
  655. self.canvas.style.height = "1px";
  656. self.canvas.style.background = "transparent";
  657. self.canvas.style.position = "absolute";
  658. self.canvas.className = self._jsPlumb.endpointClass;
  659. jsPlumb.appendElement(self.canvas, params.parent);
  660. this.paint = function(d, style, anchor) {
  661. jsPlumb.sizeCanvas(self.canvas, d[0], d[1], d[2], d[3]);
  662. };
  663. };
  664. /**
  665. * Class: Endpoints.Triangle
  666. * A triangular Endpoint.
  667. */
  668. /**
  669. * Function: Constructor
  670. *
  671. * Parameters:
  672. *
  673. * width - width of the triangle's base. defaults to 55 pixels.
  674. * height - height of the triangle from base to apex. defaults to 55 pixels.
  675. */
  676. jsPlumb.Endpoints.Triangle = function(params) {
  677. this.type = "Triangle";
  678. params = params || { };
  679. params.width = params.width || 55;
  680. params.height = params.height || 55;
  681. this.width = params.width;
  682. this.height = params.height;
  683. this.compute = function(anchorPoint, orientation, endpointStyle, connectorPaintStyle) {
  684. var width = endpointStyle.width || self.width,
  685. height = endpointStyle.height || self.height,
  686. x = anchorPoint[0] - (width/2),
  687. y = anchorPoint[1] - (height/2);
  688. return [ x, y, width, height ];
  689. };
  690. };
  691. // ********************************* END OF ENDPOINT TYPES *******************************************************************
  692. // ********************************* OVERLAY DEFINITIONS ***********************************************************************
  693. var AbstractOverlay = function(params) {
  694. var visible = true, self = this;
  695. this.isAppendedAtTopLevel = true;
  696. this.component = params.component;
  697. this.loc = params.location == null ? 0.5 : params.location;
  698. this.endpointLoc = params.endpointLocation == null ? [ 0.5, 0.5] : params.endpointLocation;
  699. this.setVisible = function(val) {
  700. visible = val;
  701. self.component.repaint();
  702. };
  703. this.isVisible = function() { return visible; };
  704. this.hide = function() { self.setVisible(false); };
  705. this.show = function() { self.setVisible(true); };
  706. this.incrementLocation = function(amount) {
  707. self.loc += amount;
  708. self.component.repaint();
  709. };
  710. this.setLocation = function(l) {
  711. self.loc = l;
  712. self.component.repaint();
  713. };
  714. this.getLocation = function() {
  715. return self.loc;
  716. };
  717. };
  718. /**
  719. * Class: Overlays.Arrow
  720. *
  721. * An arrow overlay, defined by four points: the head, the two sides of the tail, and a 'foldback' point at some distance along the length
  722. * of the arrow that lines from each tail point converge into. The foldback point is defined using a decimal that indicates some fraction
  723. * of the length of the arrow and has a default value of 0.623. A foldback point value of 1 would mean that the arrow had a straight line
  724. * across the tail.
  725. */
  726. /**
  727. * Function: Constructor
  728. *
  729. * Parameters:
  730. *
  731. * length - distance in pixels from head to tail baseline. default 20.
  732. * width - width in pixels of the tail baseline. default 20.
  733. * fillStyle - style to use when filling the arrow. defaults to "black".
  734. * strokeStyle - style to use when stroking the arrow. defaults to null, which means the arrow is not stroked.
  735. * lineWidth - line width to use when stroking the arrow. defaults to 1, but only used if strokeStyle is not null.
  736. * foldback - distance (as a decimal from 0 to 1 inclusive) along the length of the arrow marking the point the tail points should fold back to. defaults to 0.623.
  737. * location - distance (as a decimal from 0 to 1 inclusive) marking where the arrow should sit on the connector. defaults to 0.5.
  738. * direction - indicates the direction the arrow points in. valid values are -1 and 1; 1 is default.
  739. */
  740. jsPlumb.Overlays.Arrow = function(params) {
  741. this.type = "Arrow";
  742. AbstractOverlay.apply(this, arguments);
  743. this.isAppendedAtTopLevel = false;
  744. params = params || {};
  745. var self = this;
  746. this.length = params.length || 20;
  747. this.width = params.width || 20;
  748. this.id = params.id;
  749. var direction = (params.direction || 1) < 0 ? -1 : 1,
  750. paintStyle = params.paintStyle || { lineWidth:1 },
  751. // how far along the arrow the lines folding back in come to. default is 62.3%.
  752. foldback = params.foldback || 0.623;
  753. this.computeMaxSize = function() { return self.width * 1.5; };
  754. this.cleanup = function() { }; // nothing to clean up for Arrows
  755. this.draw = function(connector, currentConnectionPaintStyle, connectorDimensions) {
  756. var hxy, mid, txy, tail, cxy;
  757. if (connector.pointAlongPathFrom) {
  758. if (self.loc == 1) {
  759. hxy = connector.pointOnPath(self.loc);
  760. mid = connector.pointAlongPathFrom(self.loc, -1);
  761. txy = jsPlumb.util.pointOnLine(hxy, mid, self.length);
  762. }
  763. else if (self.loc == 0) {
  764. txy = connector.pointOnPath(self.loc);
  765. mid = connector.pointAlongPathFrom(self.loc, 1);
  766. hxy = jsPlumb.util.pointOnLine(txy, mid, self.length);
  767. }
  768. else {
  769. hxy = connector.pointAlongPathFrom(self.loc, direction * self.length / 2),
  770. mid = connector.pointOnPath(self.loc),
  771. txy = jsPlumb.util.pointOnLine(hxy, mid, self.length);
  772. }
  773. tail = jsPlumb.util.perpendicularLineTo(hxy, txy, self.width);
  774. cxy = jsPlumb.util.pointOnLine(hxy, txy, foldback * self.length);
  775. var minx = Math.min(hxy.x, tail[0].x, tail[1].x),
  776. maxx = Math.max(hxy.x, tail[0].x, tail[1].x),
  777. miny = Math.min(hxy.y, tail[0].y, tail[1].y),
  778. maxy = Math.max(hxy.y, tail[0].y, tail[1].y);
  779. var d = { hxy:hxy, tail:tail, cxy:cxy },
  780. strokeStyle = paintStyle.strokeStyle || currentConnectionPaintStyle.strokeStyle,
  781. fillStyle = paintStyle.fillStyle || currentConnectionPaintStyle.strokeStyle,
  782. lineWidth = paintStyle.lineWidth || currentConnectionPaintStyle.lineWidth;
  783. self.paint(connector, d, lineWidth, strokeStyle, fillStyle, connectorDimensions);
  784. return [ minx, maxx, miny, maxy];
  785. }
  786. else return [0,0,0,0];
  787. };
  788. };
  789. /**
  790. * Class: Overlays.PlainArrow
  791. *
  792. * A basic arrow. This is in fact just one instance of the more generic case in which the tail folds back on itself to some
  793. * point along the length of the arrow: in this case, that foldback point is the full length of the arrow. so it just does
  794. * a 'call' to Arrow with foldback set appropriately.
  795. */
  796. /**
  797. * Function: Constructor
  798. * See <Overlays.Arrow> for allowed parameters for this overlay.
  799. */
  800. jsPlumb.Overlays.PlainArrow = function(params) {
  801. params = params || {};
  802. var p = jsPlumb.extend(params, {foldback:1});
  803. jsPlumb.Overlays.Arrow.call(this, p);
  804. this.type = "PlainArrow";
  805. };
  806. /**
  807. * Class: Overlays.Diamond
  808. *
  809. * A diamond. Like PlainArrow, this is a concrete case of the more generic case of the tail points converging on some point...it just
  810. * happens that in this case, that point is greater than the length of the the arrow.
  811. *
  812. * this could probably do with some help with positioning...due to the way it reuses the Arrow paint code, what Arrow thinks is the
  813. * center is actually 1/4 of the way along for this guy. but we don't have any knowledge of pixels at this point, so we're kind of
  814. * stuck when it comes to helping out the Arrow class. possibly we could pass in a 'transpose' parameter or something. the value
  815. * would be -l/4 in this case - move along one quarter of the total length.
  816. */
  817. /**
  818. * Function: Constructor
  819. * See <Overlays.Arrow> for allowed parameters for this overlay.
  820. */
  821. jsPlumb.Overlays.Diamond = function(params) {
  822. params = params || {};
  823. var l = params.length || 40,
  824. p = jsPlumb.extend(params, {length:l/2, foldback:2});
  825. jsPlumb.Overlays.Arrow.call(this, p);
  826. this.type = "Diamond";
  827. };
  828. /**
  829. * Class: Overlays.Label
  830. * A Label overlay. For all different renderer types (SVG/Canvas/VML), jsPlumb draws a Label overlay as a styled DIV. Version 1.3.0 of jsPlumb
  831. * introduced the ability to set css classes on the label; this is now the preferred way for you to style a label. The 'labelStyle' parameter
  832. * is still supported in 1.3.0 but its usage is deprecated. Under the hood, jsPlumb just turns that object into a bunch of CSS directive that it
  833. * puts on the Label's 'style' attribute, so the end result is the same.
  834. */
  835. /**
  836. * Function: Constructor
  837. *
  838. * Parameters:
  839. * cssClass - optional css class string to append to css class. This string is appended "as-is", so you can of course have multiple classes
  840. * defined. This parameter is preferred to using labelStyle, borderWidth and borderStyle.
  841. * label - the label to paint. May be a string or a function that returns a string. Nothing will be painted if your label is null or your
  842. * label function returns null. empty strings _will_ be painted.
  843. * location - distance (as a decimal from 0 to 1 inclusive) marking where the label should sit on the connector. defaults to 0.5.
  844. *
  845. */
  846. jsPlumb.Overlays.Label = function(params) {
  847. this.type = "Label";
  848. jsPlumb.DOMElementComponent.apply(this, arguments);
  849. AbstractOverlay.apply(this, arguments);
  850. this.labelStyle = params.labelStyle || jsPlumb.Defaults.LabelStyle;
  851. this.id = params.id;
  852. this.cachedDimensions = null; // setting on 'this' rather than using closures uses a lot less memory. just don't monkey with it!
  853. var label = params.label || "",
  854. self = this,
  855. initialised = false,
  856. div = document.createElement("div"),
  857. labelText = null;
  858. div.style["position"] = "absolute";
  859. var clazz = params["_jsPlumb"].overlayClass + " " +
  860. (self.labelStyle.cssClass ? self.labelStyle.cssClass :
  861. params.cssClass ? params.cssClass : "");
  862. div.className = clazz;
  863. jsPlumb.appendElement(div, params.component.parent);
  864. jsPlumb.getId(div);
  865. self.attachListeners(div, self);
  866. self.canvas = div;
  867. //override setVisible
  868. var osv = self.setVisible;
  869. self.setVisible = function(state) {
  870. osv(state); // call superclass
  871. div.style.display = state ? "block" : "none";
  872. };
  873. this.getElement = function() {
  874. return div;
  875. };
  876. this.cleanup = function() {
  877. if (div != null) jsPlumb.CurrentLibrary.removeElement(div);
  878. };
  879. /*
  880. * Function: setLabel
  881. * sets the label's, um, label. you would think i'd call this function
  882. * 'setText', but you can pass either a Function or a String to this, so
  883. * it makes more sense as 'setLabel'.
  884. */
  885. this.setLabel = function(l) {
  886. label = l;
  887. labelText = null;
  888. self.component.repaint();
  889. };
  890. this.getLabel = function() {
  891. return label;
  892. };
  893. this.paint = function(component, d, componentDimensions) {
  894. if (!initialised) {
  895. component.appendDisplayElement(div);
  896. self.attachListeners(div, component);
  897. initialised = true;
  898. }
  899. div.style.left = (componentDimensions[0] + d.minx) + "px";
  900. div.style.top = (componentDimensions[1] + d.miny) + "px";
  901. };
  902. this.getTextDimensions = function() {
  903. if (typeof label == "function") {
  904. var lt = label(self);
  905. div.innerHTML = lt.replace(/\r\n/g, "<br/>");
  906. }
  907. else {
  908. if (labelText == null) {
  909. labelText = label;
  910. div.innerHTML = labelText.replace(/\r\n/g, "<br/>");
  911. }
  912. }
  913. var de = jsPlumb.CurrentLibrary.getElementObject(div),
  914. s = jsPlumb.CurrentLibrary.getSize(de);
  915. return {width:s[0], height:s[1]};
  916. };
  917. this.computeMaxSize = function(connector) {
  918. var td = self.getTextDimensions(connector);
  919. return td.width ? Math.max(td.width, td.height) * 1.5 : 0;
  920. };
  921. this.draw = function(component, currentConnectionPaintStyle, componentDimensions) {
  922. var td = self.getTextDimensions(component);
  923. if (td.width != null) {
  924. var cxy = {x:0,y:0};
  925. if (component.pointOnPath)
  926. cxy = component.pointOnPath(self.loc); // a connection
  927. else {
  928. var locToUse = self.loc.constructor == Array ? self.loc : self.endpointLoc;
  929. cxy = { x:locToUse[0] * componentDimensions[2],
  930. y:locToUse[1] * componentDimensions[3] };
  931. }
  932. minx = cxy.x - (td.width / 2),
  933. miny = cxy.y - (td.height / 2);
  934. self.paint(component, {
  935. minx:minx,
  936. miny:miny,
  937. td:td,
  938. cxy:cxy
  939. }, componentDimensions);
  940. return [minx, minx+td.width, miny, miny+td.height];
  941. }
  942. else return [0,0,0,0];
  943. };
  944. this.reattachListeners = function(connector) {
  945. if (div) {
  946. self.reattachListenersForElement(div, self, connector);
  947. }
  948. };
  949. };
  950. // this is really just a test overlay, so its undocumented and doesnt take any parameters. but i was loth to delete it.
  951. jsPlumb.Overlays.GuideLines = function() {
  952. var self = this;
  953. self.length = 50;
  954. self.lineWidth = 5;
  955. this.type = "GuideLines";
  956. AbstractOverlay.apply(this, arguments);
  957. jsPlumb.jsPlumbUIComponent.apply(this, arguments);
  958. this.draw = function(connector, currentConnectionPaintStyle, connectorDimensions) {
  959. var head = connector.pointAlongPathFrom(self.loc, self.length / 2),
  960. mid = connector.pointOnPath(self.loc),
  961. tail = jsPlumb.util.pointOnLine(head, mid, self.length),
  962. tailLine = jsPlumb.util.perpendicularLineTo(head, tail, 40),
  963. headLine = jsPlumb.util.perpendicularLineTo(tail, head, 20);
  964. self.paint(connector, [head, tail, tailLine, headLine], self.lineWidth, "red", null, connectorDimensions);
  965. return [Math.min(head.x, tail.x), Math.min(head.y, tail.y), Math.max(head.x, tail.x), Math.max(head.y,tail.y)];
  966. };
  967. this.computeMaxSize = function() { return 50; };
  968. this.cleanup = function() { }; // nothing to clean up for GuideLines
  969. };
  970. // ********************************* END OF OVERLAY DEFINITIONS ***********************************************************************
  971. // ********************************* OVERLAY CANVAS RENDERERS***********************************************************************
  972. // ********************************* END OF OVERLAY CANVAS RENDERERS ***********************************************************************
  973. })();