shape.js 1.4 KB

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