ConnectionDocking.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @memberOf djs.layout
  3. */
  4. /**
  5. * @class DockingPointDescriptor
  6. */
  7. /**
  8. * @name DockingPointDescriptor#point
  9. * @type djs.Point
  10. */
  11. /**
  12. * @name DockingPointDescriptor#actual
  13. * @type djs.Point
  14. */
  15. /**
  16. * @name DockingPointDescriptor#idx
  17. * @type Number
  18. */
  19. /**
  20. * A layout component for connections that retrieves waypoint information.
  21. *
  22. * @class
  23. * @constructor
  24. */
  25. export default function ConnectionDocking() {}
  26. /**
  27. * Return the actual waypoints of the connection (visually).
  28. *
  29. * @param {djs.model.Connection} connection
  30. * @param {djs.model.Base} [source]
  31. * @param {djs.model.Base} [target]
  32. *
  33. * @return {Array<Point>}
  34. */
  35. ConnectionDocking.prototype.getCroppedWaypoints = function(connection, source, target) {
  36. return connection.waypoints;
  37. };
  38. /**
  39. * Return the connection docking point on the specified shape
  40. *
  41. * @param {djs.model.Connection} connection
  42. * @param {djs.model.Shape} shape
  43. * @param {Boolean} [dockStart=false]
  44. *
  45. * @return {DockingPointDescriptor}
  46. */
  47. ConnectionDocking.prototype.getDockingPoint = function(connection, shape, dockStart) {
  48. var waypoints = connection.waypoints,
  49. dockingIdx,
  50. dockingPoint;
  51. dockingIdx = dockStart ? 0 : waypoints.length - 1;
  52. dockingPoint = waypoints[dockingIdx];
  53. return {
  54. point: dockingPoint,
  55. actual: dockingPoint,
  56. idx: dockingIdx
  57. };
  58. };