options.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.Options = void 0;
  15. const x6_common_1 = require("@antv/x6-common");
  16. const config_1 = require("../config");
  17. const shape_1 = require("../shape");
  18. var Options;
  19. (function (Options) {
  20. function get(options) {
  21. const { grid, panning, mousewheel, embedding } = options, others = __rest(options
  22. // size
  23. // ----
  24. , ["grid", "panning", "mousewheel", "embedding"]);
  25. // size
  26. // ----
  27. const container = options.container;
  28. if (container != null) {
  29. if (others.width == null) {
  30. others.width = container.clientWidth;
  31. }
  32. if (others.height == null) {
  33. others.height = container.clientHeight;
  34. }
  35. }
  36. else {
  37. throw new Error(`Ensure the container of the graph is specified and valid`);
  38. }
  39. const result = x6_common_1.ObjectExt.merge({}, Options.defaults, others);
  40. // grid
  41. // ----
  42. const defaultGrid = { size: 10, visible: false };
  43. if (typeof grid === 'number') {
  44. result.grid = { size: grid, visible: false };
  45. }
  46. else if (typeof grid === 'boolean') {
  47. result.grid = Object.assign(Object.assign({}, defaultGrid), { visible: grid });
  48. }
  49. else {
  50. result.grid = Object.assign(Object.assign({}, defaultGrid), grid);
  51. }
  52. // booleas
  53. // -------
  54. const booleas = [
  55. 'panning',
  56. 'mousewheel',
  57. 'embedding',
  58. ];
  59. booleas.forEach((key) => {
  60. const val = options[key];
  61. if (typeof val === 'boolean') {
  62. result[key].enabled = val;
  63. }
  64. else {
  65. result[key] = Object.assign(Object.assign({}, result[key]), val);
  66. }
  67. });
  68. return result;
  69. }
  70. Options.get = get;
  71. })(Options = exports.Options || (exports.Options = {}));
  72. (function (Options) {
  73. Options.defaults = {
  74. x: 0,
  75. y: 0,
  76. scaling: {
  77. min: 0.01,
  78. max: 16,
  79. },
  80. grid: {
  81. size: 10,
  82. visible: false,
  83. },
  84. background: false,
  85. panning: {
  86. enabled: false,
  87. eventTypes: ['leftMouseDown'],
  88. },
  89. mousewheel: {
  90. enabled: false,
  91. factor: 1.2,
  92. zoomAtMousePosition: true,
  93. },
  94. highlighting: {
  95. default: {
  96. name: 'stroke',
  97. args: {
  98. padding: 3,
  99. },
  100. },
  101. nodeAvailable: {
  102. name: 'className',
  103. args: {
  104. className: config_1.Config.prefix('available-node'),
  105. },
  106. },
  107. magnetAvailable: {
  108. name: 'className',
  109. args: {
  110. className: config_1.Config.prefix('available-magnet'),
  111. },
  112. },
  113. },
  114. connecting: {
  115. snap: false,
  116. allowLoop: true,
  117. allowNode: true,
  118. allowEdge: false,
  119. allowPort: true,
  120. allowBlank: true,
  121. allowMulti: true,
  122. highlight: false,
  123. anchor: 'center',
  124. edgeAnchor: 'ratio',
  125. connectionPoint: 'boundary',
  126. router: 'normal',
  127. connector: 'normal',
  128. validateConnection({ type, sourceView, targetView }) {
  129. const view = type === 'target' ? targetView : sourceView;
  130. return view != null;
  131. },
  132. createEdge() {
  133. return new shape_1.Edge();
  134. },
  135. },
  136. translating: {
  137. restrict: false,
  138. },
  139. embedding: {
  140. enabled: false,
  141. findParent: 'bbox',
  142. frontOnly: true,
  143. validate: () => true,
  144. },
  145. moveThreshold: 0,
  146. clickThreshold: 0,
  147. magnetThreshold: 0,
  148. preventDefaultDblClick: true,
  149. preventDefaultMouseDown: false,
  150. preventDefaultContextMenu: true,
  151. preventDefaultBlankAction: true,
  152. interacting: {
  153. edgeLabelMovable: false,
  154. },
  155. async: true,
  156. virtual: false,
  157. guard: () => false,
  158. };
  159. })(Options = exports.Options || (exports.Options = {}));
  160. //# sourceMappingURL=options.js.map