bbox.js 1.1 KB

12345678910111213141516171819202122232425
  1. import { NumberExt } from '@antv/x6-common';
  2. export const center = createBBoxAnchor('center');
  3. export const top = createBBoxAnchor('topCenter');
  4. export const bottom = createBBoxAnchor('bottomCenter');
  5. export const left = createBBoxAnchor('leftMiddle');
  6. export const right = createBBoxAnchor('rightMiddle');
  7. export const topLeft = createBBoxAnchor('topLeft');
  8. export const topRight = createBBoxAnchor('topRight');
  9. export const bottomLeft = createBBoxAnchor('bottomLeft');
  10. export const bottomRight = createBBoxAnchor('bottomRight');
  11. function createBBoxAnchor(method) {
  12. return function (view, magnet, ref, options = {}) {
  13. const bbox = options.rotate
  14. ? view.getUnrotatedBBoxOfElement(magnet)
  15. : view.getBBoxOfElement(magnet);
  16. const result = bbox[method];
  17. result.x += NumberExt.normalizePercentage(options.dx, bbox.width);
  18. result.y += NumberExt.normalizePercentage(options.dy, bbox.height);
  19. const cell = view.cell;
  20. return options.rotate
  21. ? result.rotate(-cell.getAngle(), cell.getBBox().getCenter())
  22. : result;
  23. };
  24. }
  25. //# sourceMappingURL=bbox.js.map