boundary.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. var __rest = (this && this.__rest) || function (s, e) {
  26. var t = {};
  27. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  28. t[p] = s[p];
  29. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  30. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  31. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  32. t[p[i]] = s[p[i]];
  33. }
  34. return t;
  35. };
  36. Object.defineProperty(exports, "__esModule", { value: true });
  37. exports.Boundary = void 0;
  38. const x6_common_1 = require("@antv/x6-common");
  39. const tool_1 = require("../../view/tool");
  40. const Util = __importStar(require("./util"));
  41. class Boundary extends tool_1.ToolsView.ToolItem {
  42. onRender() {
  43. x6_common_1.Dom.addClass(this.container, this.prefixClassName('cell-tool-boundary'));
  44. if (this.options.attrs) {
  45. const _a = this.options.attrs, { class: className } = _a, attrs = __rest(_a, ["class"]);
  46. x6_common_1.Dom.attr(this.container, x6_common_1.Dom.kebablizeAttrs(attrs));
  47. if (className) {
  48. x6_common_1.Dom.addClass(this.container, className);
  49. }
  50. }
  51. this.update();
  52. }
  53. update() {
  54. const view = this.cellView;
  55. const options = this.options;
  56. const { useCellGeometry, rotate } = options;
  57. const padding = x6_common_1.NumberExt.normalizeSides(options.padding);
  58. let bbox = Util.getViewBBox(view, useCellGeometry).moveAndExpand({
  59. x: -padding.left,
  60. y: -padding.top,
  61. width: padding.left + padding.right,
  62. height: padding.top + padding.bottom,
  63. });
  64. const cell = view.cell;
  65. if (cell.isNode()) {
  66. const angle = cell.getAngle();
  67. if (angle) {
  68. if (rotate) {
  69. const origin = cell.getBBox().getCenter();
  70. x6_common_1.Dom.rotate(this.container, angle, origin.x, origin.y, {
  71. absolute: true,
  72. });
  73. }
  74. else {
  75. bbox = bbox.bbox(angle);
  76. }
  77. }
  78. }
  79. x6_common_1.Dom.attr(this.container, bbox.toJSON());
  80. return this;
  81. }
  82. }
  83. exports.Boundary = Boundary;
  84. (function (Boundary) {
  85. Boundary.config({
  86. name: 'boundary',
  87. tagName: 'rect',
  88. padding: 10,
  89. useCellGeometry: true,
  90. attrs: {
  91. fill: 'none',
  92. stroke: '#333',
  93. 'stroke-width': 0.5,
  94. 'stroke-dasharray': '5, 5',
  95. 'pointer-events': 'none',
  96. },
  97. });
  98. })(Boundary = exports.Boundary || (exports.Boundary = {}));
  99. //# sourceMappingURL=boundary.js.map