poly.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 { Point } from '@antv/x6-geometry';
  13. import { ObjectExt } from '@antv/x6-common';
  14. import { Base } from './base';
  15. export class Poly extends Base {
  16. get points() {
  17. return this.getPoints();
  18. }
  19. set points(pts) {
  20. this.setPoints(pts);
  21. }
  22. getPoints() {
  23. return this.getAttrByPath('body/refPoints');
  24. }
  25. setPoints(points, options) {
  26. if (points == null) {
  27. this.removePoints();
  28. }
  29. else {
  30. this.setAttrByPath('body/refPoints', Poly.pointsToString(points), options);
  31. }
  32. return this;
  33. }
  34. removePoints() {
  35. this.removeAttrByPath('body/refPoints');
  36. return this;
  37. }
  38. }
  39. (function (Poly) {
  40. function pointsToString(points) {
  41. return typeof points === 'string'
  42. ? points
  43. : points
  44. .map((p) => {
  45. if (Array.isArray(p)) {
  46. return p.join(',');
  47. }
  48. if (Point.isPointLike(p)) {
  49. return `${p.x}, ${p.y}`;
  50. }
  51. return '';
  52. })
  53. .join(' ');
  54. }
  55. Poly.pointsToString = pointsToString;
  56. Poly.config({
  57. propHooks(metadata) {
  58. const { points } = metadata, others = __rest(metadata, ["points"]);
  59. if (points) {
  60. const data = pointsToString(points);
  61. if (data) {
  62. ObjectExt.setByPath(others, 'attrs/body/refPoints', data);
  63. }
  64. }
  65. return others;
  66. },
  67. });
  68. })(Poly || (Poly = {}));
  69. //# sourceMappingURL=poly.js.map