boundary.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var __rest = (this && this.__rest) || function (s, e) {
  2. var t = {};
  3. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  4. t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  6. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  7. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  8. t[p[i]] = s[p[i]];
  9. }
  10. return t;
  11. };
  12. import { NumberExt, Dom } from '@antv/x6-common';
  13. import { ToolsView } from '../../view/tool';
  14. import * as Util from './util';
  15. export class Boundary extends ToolsView.ToolItem {
  16. onRender() {
  17. Dom.addClass(this.container, this.prefixClassName('cell-tool-boundary'));
  18. if (this.options.attrs) {
  19. const _a = this.options.attrs, { class: className } = _a, attrs = __rest(_a, ["class"]);
  20. Dom.attr(this.container, Dom.kebablizeAttrs(attrs));
  21. if (className) {
  22. Dom.addClass(this.container, className);
  23. }
  24. }
  25. this.update();
  26. }
  27. update() {
  28. const view = this.cellView;
  29. const options = this.options;
  30. const { useCellGeometry, rotate } = options;
  31. const padding = NumberExt.normalizeSides(options.padding);
  32. let bbox = Util.getViewBBox(view, useCellGeometry).moveAndExpand({
  33. x: -padding.left,
  34. y: -padding.top,
  35. width: padding.left + padding.right,
  36. height: padding.top + padding.bottom,
  37. });
  38. const cell = view.cell;
  39. if (cell.isNode()) {
  40. const angle = cell.getAngle();
  41. if (angle) {
  42. if (rotate) {
  43. const origin = cell.getBBox().getCenter();
  44. Dom.rotate(this.container, angle, origin.x, origin.y, {
  45. absolute: true,
  46. });
  47. }
  48. else {
  49. bbox = bbox.bbox(angle);
  50. }
  51. }
  52. }
  53. Dom.attr(this.container, bbox.toJSON());
  54. return this;
  55. }
  56. }
  57. (function (Boundary) {
  58. Boundary.config({
  59. name: 'boundary',
  60. tagName: 'rect',
  61. padding: 10,
  62. useCellGeometry: true,
  63. attrs: {
  64. fill: 'none',
  65. stroke: '#333',
  66. 'stroke-width': 0.5,
  67. 'stroke-dasharray': '5, 5',
  68. 'pointer-events': 'none',
  69. },
  70. });
  71. })(Boundary || (Boundary = {}));
  72. //# sourceMappingURL=boundary.js.map