poly.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. "use strict";
  2. var __rest = (this && this.__rest) || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  5. t[p] = s[p];
  6. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  7. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  8. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  9. t[p[i]] = s[p[i]];
  10. }
  11. return t;
  12. };
  13. Object.defineProperty(exports, "__esModule", { value: true });
  14. exports.Poly = void 0;
  15. const x6_geometry_1 = require("@antv/x6-geometry");
  16. const x6_common_1 = require("@antv/x6-common");
  17. const base_1 = require("./base");
  18. class Poly extends base_1.Base {
  19. get points() {
  20. return this.getPoints();
  21. }
  22. set points(pts) {
  23. this.setPoints(pts);
  24. }
  25. getPoints() {
  26. return this.getAttrByPath('body/refPoints');
  27. }
  28. setPoints(points, options) {
  29. if (points == null) {
  30. this.removePoints();
  31. }
  32. else {
  33. this.setAttrByPath('body/refPoints', Poly.pointsToString(points), options);
  34. }
  35. return this;
  36. }
  37. removePoints() {
  38. this.removeAttrByPath('body/refPoints');
  39. return this;
  40. }
  41. }
  42. exports.Poly = Poly;
  43. (function (Poly) {
  44. function pointsToString(points) {
  45. return typeof points === 'string'
  46. ? points
  47. : points
  48. .map((p) => {
  49. if (Array.isArray(p)) {
  50. return p.join(',');
  51. }
  52. if (x6_geometry_1.Point.isPointLike(p)) {
  53. return `${p.x}, ${p.y}`;
  54. }
  55. return '';
  56. })
  57. .join(' ');
  58. }
  59. Poly.pointsToString = pointsToString;
  60. Poly.config({
  61. propHooks(metadata) {
  62. const { points } = metadata, others = __rest(metadata, ["points"]);
  63. if (points) {
  64. const data = pointsToString(points);
  65. if (data) {
  66. x6_common_1.ObjectExt.setByPath(others, 'attrs/body/refPoints', data);
  67. }
  68. }
  69. return others;
  70. },
  71. });
  72. })(Poly = exports.Poly || (exports.Poly = {}));
  73. //# sourceMappingURL=poly.js.map