LabelLayoutUtil.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { findNewLineStartIndex, getAnchorPointAdjustment } from './LayoutUtil';
  2. import { getMid } from 'diagram-js/lib/layout/LayoutUtil';
  3. /**
  4. * @typedef {import('./LineAttachmentUtil').Attachment} Attachment
  5. *
  6. * @typedef {import('./LayoutUtil').FindNewLineStartIndexHints} FindNewLineStartIndexHints
  7. *
  8. * @typedef {import('../../../../model/Types').Label} Label
  9. *
  10. * @typedef {import('diagram-js/lib/util/Types').Point} Point
  11. */
  12. /**
  13. * @param {Point[]} oldWaypoints
  14. * @param {Point[]} newWaypoints
  15. * @param {Attachment} attachment
  16. * @param {FindNewLineStartIndexHints} hints
  17. *
  18. * @return {number}
  19. */
  20. export function findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints) {
  21. return findNewLineStartIndex(oldWaypoints, newWaypoints, attachment, hints);
  22. }
  23. /**
  24. * Calculate the required adjustment (move delta) for the given label
  25. * after the connection waypoints got updated.
  26. *
  27. * @param {Label} label
  28. * @param {Point[]} newWaypoints
  29. * @param {Point[]} oldWaypoints
  30. * @param {FindNewLineStartIndexHints} hints
  31. *
  32. * @return {Point}
  33. */
  34. export function getLabelAdjustment(label, newWaypoints, oldWaypoints, hints) {
  35. var labelPosition = getMid(label);
  36. return getAnchorPointAdjustment(labelPosition, newWaypoints, oldWaypoints, hints).delta;
  37. }