base.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.Base = void 0;
  15. const x6_common_1 = require("@antv/x6-common");
  16. const model_1 = require("../model");
  17. class Base extends model_1.Node {
  18. get label() {
  19. return this.getLabel();
  20. }
  21. set label(val) {
  22. this.setLabel(val);
  23. }
  24. getLabel() {
  25. return this.getAttrByPath('text/text');
  26. }
  27. setLabel(label, options) {
  28. if (label == null) {
  29. this.removeLabel();
  30. }
  31. else {
  32. this.setAttrByPath('text/text', label, options);
  33. }
  34. return this;
  35. }
  36. removeLabel() {
  37. this.removeAttrByPath('text/text');
  38. return this;
  39. }
  40. }
  41. exports.Base = Base;
  42. (function (Base) {
  43. Base.bodyAttr = {
  44. fill: '#ffffff',
  45. stroke: '#333333',
  46. strokeWidth: 2,
  47. };
  48. Base.labelAttr = {
  49. fontSize: 14,
  50. fill: '#000000',
  51. refX: 0.5,
  52. refY: 0.5,
  53. textAnchor: 'middle',
  54. textVerticalAnchor: 'middle',
  55. fontFamily: 'Arial, helvetica, sans-serif',
  56. };
  57. Base.config({
  58. attrs: { text: Object.assign({}, Base.labelAttr) },
  59. propHooks(metadata) {
  60. const { label } = metadata, others = __rest(metadata, ["label"]);
  61. if (label) {
  62. x6_common_1.ObjectExt.setByPath(others, 'attrs/text/text', label);
  63. }
  64. return others;
  65. },
  66. visible: true,
  67. });
  68. })(Base = exports.Base || (exports.Base = {}));
  69. //# sourceMappingURL=base.js.map