CustomLayouter.js 977 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { getMid } from 'lib/layout/LayoutUtil';
  2. /**
  3. * A base connection layouter implementation
  4. * that layouts the connection by directly connecting
  5. * mid(source) + mid(target).
  6. */
  7. export default function CustomLayouter() {}
  8. /**
  9. * Return the new layouted waypoints for the given connection.
  10. *
  11. * @param {djs.model.Connection} connection
  12. * @param {Object} [hints]
  13. * @param {Boolean} [hints.connectionStart]
  14. * @param {Boolean} [hints.connectionEnd]
  15. *
  16. * @return {Array<Point>} the layouted connection waypoints
  17. */
  18. CustomLayouter.prototype.layoutConnection = function(connection, hints) {
  19. hints = hints || {};
  20. var startMid = hints.connectionStart || getMid(connection.source),
  21. endMid = hints.connectionEnd || getMid(connection.target);
  22. var start = {
  23. x: startMid.x + 50,
  24. y: startMid.y + 50,
  25. original: startMid
  26. };
  27. var end = {
  28. x: endMid.x - 50,
  29. y: endMid.y - 50,
  30. original: endMid
  31. };
  32. return [
  33. start,
  34. end
  35. ];
  36. };