shape.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.isVertical = exports.isHorizontal = exports.createTempText = exports.getLocalBBox = exports.getShapeSpace = void 0;
  4. var tslib_1 = require("tslib");
  5. var selection_1 = require("./selection");
  6. /**
  7. * 获得图形的x、y、width、height
  8. */
  9. function getShapeSpace(shape) {
  10. var bounds = shape && shape.getRenderBounds();
  11. if (!bounds)
  12. return {
  13. width: 0,
  14. height: 0,
  15. };
  16. var max = bounds.getMax();
  17. var min = bounds.getMin();
  18. return {
  19. width: max[0] - min[0],
  20. height: max[1] - min[1],
  21. };
  22. }
  23. exports.getShapeSpace = getShapeSpace;
  24. function getLocalBBox(shape) {
  25. var _a = shape.getLocalBounds(), min = _a.min, max = _a.max;
  26. var _b = tslib_1.__read([min, max], 2), _c = tslib_1.__read(_b[0], 2), x1 = _c[0], y1 = _c[1], _d = tslib_1.__read(_b[1], 2), x2 = _d[0], y2 = _d[1];
  27. return { x: x1, y: y1, width: x2 - x1, height: y2 - y1, left: x1, bottom: y2, top: y1, right: x2 };
  28. }
  29. exports.getLocalBBox = getLocalBBox;
  30. function createTempText(group, attrs) {
  31. var textNode = (0, selection_1.select)(group).append('text').node();
  32. textNode.attr(tslib_1.__assign(tslib_1.__assign({}, attrs), { visibility: 'hidden' }));
  33. return textNode;
  34. }
  35. exports.createTempText = createTempText;
  36. function isHorizontal(p1, p2) {
  37. var _a = tslib_1.__read(p1, 2), x1 = _a[0], y1 = _a[1];
  38. var _b = tslib_1.__read(p2, 2), x2 = _b[0], y2 = _b[1];
  39. return x1 !== x2 && y1 === y2;
  40. }
  41. exports.isHorizontal = isHorizontal;
  42. function isVertical(p1, p2) {
  43. var _a = tslib_1.__read(p1, 2), x1 = _a[0], y1 = _a[1];
  44. var _b = tslib_1.__read(p2, 2), x2 = _b[0], y2 = _b[1];
  45. return x1 === x2 && y1 !== y2;
  46. }
  47. exports.isVertical = isVertical;
  48. //# sourceMappingURL=shape.js.map