base.js 1.8 KB

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