@react-fabric/graph 1.0.0-beta.62 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/dist/cjs/context/context.js +16 -0
  2. package/dist/cjs/graph/index.js +62 -385
  3. package/dist/cjs/index.js +25 -21
  4. package/dist/cjs/utils/edge.js +76 -0
  5. package/dist/cjs/utils/node.js +93 -0
  6. package/dist/cjs/utils/sdfFolder.js +107 -0
  7. package/dist/cjs/viewer/Graph.js +174 -0
  8. package/dist/esm/context/context.js +15 -0
  9. package/dist/esm/graph/index.js +63 -386
  10. package/dist/esm/index.js +24 -20
  11. package/dist/esm/utils/edge.js +75 -0
  12. package/dist/esm/utils/node.js +92 -0
  13. package/dist/esm/utils/sdfFolder.js +107 -0
  14. package/dist/esm/viewer/Graph.js +174 -0
  15. package/dist/types/context/context.d.ts +35 -0
  16. package/dist/types/graph/index.d.ts +47 -24
  17. package/dist/types/index.d.ts +28 -2
  18. package/dist/types/types/index.d.ts +124 -175
  19. package/dist/types/utils/edge.d.ts +28 -0
  20. package/dist/types/utils/node.d.ts +28 -0
  21. package/dist/types/utils/sdfFolder.d.ts +75 -0
  22. package/dist/types/viewer/Graph.d.ts +31 -0
  23. package/package.json +19 -25
  24. package/src/context/context.tsx +43 -0
  25. package/src/graph/index.ts +76 -399
  26. package/src/index.ts +24 -26
  27. package/src/types/index.ts +139 -185
  28. package/src/utils/edge.ts +65 -0
  29. package/src/utils/node.ts +105 -0
  30. package/src/utils/sdfFolder.ts +141 -0
  31. package/src/viewer/Graph.tsx +159 -0
  32. package/css/styles.css +0 -56
  33. package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -14
  34. package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -9
  35. package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +0 -35
  36. package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -11
  37. package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -20
  38. package/dist/cjs/_virtual/elk-worker.js +0 -8
  39. package/dist/cjs/components/Context.js +0 -107
  40. package/dist/cjs/components/ContextMenu.js +0 -133
  41. package/dist/cjs/components/Tools.js +0 -205
  42. package/dist/cjs/components/Viewer.js +0 -58
  43. package/dist/cjs/constants/index.js +0 -16
  44. package/dist/cjs/hooks/sigmaDragSelect.js +0 -169
  45. package/dist/cjs/hooks/sigmaHilighter.js +0 -83
  46. package/dist/cjs/hooks/sigmaMouseActions.js +0 -145
  47. package/dist/cjs/hooks/useGraphology.js +0 -41
  48. package/dist/cjs/hooks/useSigma.js +0 -112
  49. package/dist/cjs/programs/arrow-head/frag.glsl.js +0 -8
  50. package/dist/cjs/programs/arrow-head/index.js +0 -142
  51. package/dist/cjs/programs/arrow-head/vert.glsl.js +0 -8
  52. package/dist/cjs/programs/edge-curve/drawLabel.js +0 -136
  53. package/dist/cjs/programs/edge-curve/frag.glsl.js +0 -8
  54. package/dist/cjs/programs/edge-curve/index.js +0 -157
  55. package/dist/cjs/programs/edge-curve/vert.glsl.js +0 -8
  56. package/dist/cjs/programs/edge-line/drawLabel.js +0 -70
  57. package/dist/cjs/programs/edge-line/frag.glsl.js +0 -8
  58. package/dist/cjs/programs/edge-line/index.js +0 -166
  59. package/dist/cjs/programs/edge-line/vert.glsl.js +0 -8
  60. package/dist/cjs/programs/node-badge/factory.js +0 -249
  61. package/dist/cjs/programs/node-badge/frag.glsl.js +0 -8
  62. package/dist/cjs/programs/node-badge/index.js +0 -33
  63. package/dist/cjs/programs/node-badge/texture.js +0 -455
  64. package/dist/cjs/programs/node-badge/vert.glsl.js +0 -19
  65. package/dist/cjs/programs/node-circle/base/drawHover.js +0 -71
  66. package/dist/cjs/programs/node-circle/base/drawLabel.js +0 -113
  67. package/dist/cjs/programs/node-circle/base/frag.glsl.js +0 -8
  68. package/dist/cjs/programs/node-circle/base/index.js +0 -136
  69. package/dist/cjs/programs/node-circle/base/vert.glsl.js +0 -8
  70. package/dist/cjs/programs/node-circle/index.js +0 -15
  71. package/dist/cjs/programs/node-image/factory.js +0 -223
  72. package/dist/cjs/programs/node-image/frag.glsl.js +0 -8
  73. package/dist/cjs/programs/node-image/index.js +0 -14
  74. package/dist/cjs/programs/node-image/texture.js +0 -472
  75. package/dist/cjs/programs/node-image/vert.glsl.js +0 -8
  76. package/dist/cjs/programs/node-rect/base/drawHover.js +0 -68
  77. package/dist/cjs/programs/node-rect/base/drawLabel.js +0 -107
  78. package/dist/cjs/programs/node-rect/base/frag.glsl.js +0 -8
  79. package/dist/cjs/programs/node-rect/base/index.js +0 -135
  80. package/dist/cjs/programs/node-rect/base/vert.glsl.js +0 -8
  81. package/dist/cjs/programs/node-rect/index.js +0 -15
  82. package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -14
  83. package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -9
  84. package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +0 -34
  85. package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -13
  86. package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -20
  87. package/dist/esm/_virtual/elk-worker.js +0 -8
  88. package/dist/esm/components/Context.js +0 -106
  89. package/dist/esm/components/ContextMenu.js +0 -133
  90. package/dist/esm/components/Tools.js +0 -205
  91. package/dist/esm/components/Viewer.js +0 -58
  92. package/dist/esm/constants/index.js +0 -16
  93. package/dist/esm/hooks/sigmaDragSelect.js +0 -169
  94. package/dist/esm/hooks/sigmaHilighter.js +0 -83
  95. package/dist/esm/hooks/sigmaMouseActions.js +0 -145
  96. package/dist/esm/hooks/useGraphology.js +0 -41
  97. package/dist/esm/hooks/useSigma.js +0 -112
  98. package/dist/esm/programs/arrow-head/frag.glsl.js +0 -8
  99. package/dist/esm/programs/arrow-head/index.js +0 -141
  100. package/dist/esm/programs/arrow-head/vert.glsl.js +0 -8
  101. package/dist/esm/programs/edge-curve/drawLabel.js +0 -136
  102. package/dist/esm/programs/edge-curve/frag.glsl.js +0 -8
  103. package/dist/esm/programs/edge-curve/index.js +0 -156
  104. package/dist/esm/programs/edge-curve/vert.glsl.js +0 -8
  105. package/dist/esm/programs/edge-line/drawLabel.js +0 -70
  106. package/dist/esm/programs/edge-line/frag.glsl.js +0 -8
  107. package/dist/esm/programs/edge-line/index.js +0 -166
  108. package/dist/esm/programs/edge-line/vert.glsl.js +0 -8
  109. package/dist/esm/programs/node-badge/factory.js +0 -249
  110. package/dist/esm/programs/node-badge/frag.glsl.js +0 -8
  111. package/dist/esm/programs/node-badge/index.js +0 -32
  112. package/dist/esm/programs/node-badge/texture.js +0 -445
  113. package/dist/esm/programs/node-badge/vert.glsl.js +0 -19
  114. package/dist/esm/programs/node-circle/base/drawHover.js +0 -71
  115. package/dist/esm/programs/node-circle/base/drawLabel.js +0 -113
  116. package/dist/esm/programs/node-circle/base/frag.glsl.js +0 -8
  117. package/dist/esm/programs/node-circle/base/index.js +0 -136
  118. package/dist/esm/programs/node-circle/base/vert.glsl.js +0 -8
  119. package/dist/esm/programs/node-circle/index.js +0 -15
  120. package/dist/esm/programs/node-image/factory.js +0 -223
  121. package/dist/esm/programs/node-image/frag.glsl.js +0 -8
  122. package/dist/esm/programs/node-image/index.js +0 -13
  123. package/dist/esm/programs/node-image/texture.js +0 -462
  124. package/dist/esm/programs/node-image/vert.glsl.js +0 -8
  125. package/dist/esm/programs/node-rect/base/drawHover.js +0 -68
  126. package/dist/esm/programs/node-rect/base/drawLabel.js +0 -107
  127. package/dist/esm/programs/node-rect/base/frag.glsl.js +0 -8
  128. package/dist/esm/programs/node-rect/base/index.js +0 -135
  129. package/dist/esm/programs/node-rect/base/vert.glsl.js +0 -8
  130. package/dist/esm/programs/node-rect/index.js +0 -15
  131. package/dist/types/components/Context.d.ts +0 -18
  132. package/dist/types/components/ContextMenu.d.ts +0 -1
  133. package/dist/types/components/Tools.d.ts +0 -1
  134. package/dist/types/components/Viewer.d.ts +0 -2
  135. package/dist/types/constants/index.d.ts +0 -12
  136. package/dist/types/graph/layout.worker.d.ts +0 -1
  137. package/dist/types/hooks/sigmaDragSelect.d.ts +0 -8
  138. package/dist/types/hooks/sigmaHilighter.d.ts +0 -3
  139. package/dist/types/hooks/sigmaMouseActions.d.ts +0 -3
  140. package/dist/types/hooks/useGraphology.d.ts +0 -6
  141. package/dist/types/hooks/useSigma.d.ts +0 -8
  142. package/dist/types/i18n/index.d.ts +0 -0
  143. package/dist/types/programs/arrow-head/frag.glsl.d.ts +0 -2
  144. package/dist/types/programs/arrow-head/index.d.ts +0 -9
  145. package/dist/types/programs/arrow-head/vert.glsl.d.ts +0 -2
  146. package/dist/types/programs/edge-curve/drawLabel.d.ts +0 -6
  147. package/dist/types/programs/edge-curve/frag.glsl.d.ts +0 -2
  148. package/dist/types/programs/edge-curve/index.d.ts +0 -43
  149. package/dist/types/programs/edge-curve/vert.glsl.d.ts +0 -2
  150. package/dist/types/programs/edge-line/drawLabel.d.ts +0 -5
  151. package/dist/types/programs/edge-line/frag.glsl.d.ts +0 -2
  152. package/dist/types/programs/edge-line/index.d.ts +0 -11
  153. package/dist/types/programs/edge-line/vert.glsl.d.ts +0 -2
  154. package/dist/types/programs/node-badge/factory.d.ts +0 -27
  155. package/dist/types/programs/node-badge/frag.glsl.d.ts +0 -2
  156. package/dist/types/programs/node-badge/index.d.ts +0 -5
  157. package/dist/types/programs/node-badge/texture.d.ts +0 -102
  158. package/dist/types/programs/node-badge/vert.glsl.d.ts +0 -2
  159. package/dist/types/programs/node-circle/base/drawHover.d.ts +0 -8
  160. package/dist/types/programs/node-circle/base/drawLabel.d.ts +0 -8
  161. package/dist/types/programs/node-circle/base/frag.glsl.d.ts +0 -2
  162. package/dist/types/programs/node-circle/base/index.d.ts +0 -37
  163. package/dist/types/programs/node-circle/base/vert.glsl.d.ts +0 -2
  164. package/dist/types/programs/node-circle/index.d.ts +0 -11
  165. package/dist/types/programs/node-image/factory.d.ts +0 -25
  166. package/dist/types/programs/node-image/frag.glsl.d.ts +0 -2
  167. package/dist/types/programs/node-image/index.d.ts +0 -5
  168. package/dist/types/programs/node-image/texture.d.ts +0 -102
  169. package/dist/types/programs/node-image/vert.glsl.d.ts +0 -2
  170. package/dist/types/programs/node-rect/base/drawHover.d.ts +0 -8
  171. package/dist/types/programs/node-rect/base/drawLabel.d.ts +0 -8
  172. package/dist/types/programs/node-rect/base/frag.glsl.d.ts +0 -2
  173. package/dist/types/programs/node-rect/base/index.d.ts +0 -34
  174. package/dist/types/programs/node-rect/base/vert.glsl.d.ts +0 -2
  175. package/dist/types/programs/node-rect/index.d.ts +0 -11
  176. package/src/components/Context.tsx +0 -143
  177. package/src/components/ContextMenu.tsx +0 -174
  178. package/src/components/Tools.tsx +0 -106
  179. package/src/components/Viewer.tsx +0 -76
  180. package/src/constants/index.ts +0 -22
  181. package/src/graph/layout.worker.ts +0 -42
  182. package/src/hooks/sigmaDragSelect.ts +0 -219
  183. package/src/hooks/sigmaHilighter.ts +0 -107
  184. package/src/hooks/sigmaMouseActions.ts +0 -153
  185. package/src/hooks/useGraphology.ts +0 -31
  186. package/src/hooks/useSigma.ts +0 -118
  187. package/src/i18n/index.ts +0 -0
  188. package/src/programs/arrow-head/frag.glsl.ts +0 -18
  189. package/src/programs/arrow-head/index.ts +0 -157
  190. package/src/programs/arrow-head/vert.glsl.ts +0 -75
  191. package/src/programs/edge-curve/drawLabel.ts +0 -166
  192. package/src/programs/edge-curve/frag.glsl.ts +0 -86
  193. package/src/programs/edge-curve/index.ts +0 -158
  194. package/src/programs/edge-curve/vert.glsl.ts +0 -110
  195. package/src/programs/edge-line/drawLabel.ts +0 -113
  196. package/src/programs/edge-line/frag.glsl.ts +0 -34
  197. package/src/programs/edge-line/index.ts +0 -165
  198. package/src/programs/edge-line/vert.glsl.ts +0 -104
  199. package/src/programs/node-badge/factory.ts +0 -327
  200. package/src/programs/node-badge/frag.glsl.ts +0 -79
  201. package/src/programs/node-badge/index.ts +0 -35
  202. package/src/programs/node-badge/texture.ts +0 -425
  203. package/src/programs/node-badge/vert.glsl.ts +0 -99
  204. package/src/programs/node-circle/base/drawHover.ts +0 -80
  205. package/src/programs/node-circle/base/drawLabel.ts +0 -145
  206. package/src/programs/node-circle/base/frag.glsl.ts +0 -72
  207. package/src/programs/node-circle/base/index.ts +0 -102
  208. package/src/programs/node-circle/base/vert.glsl.ts +0 -83
  209. package/src/programs/node-circle/index.ts +0 -19
  210. package/src/programs/node-image/factory.ts +0 -301
  211. package/src/programs/node-image/frag.glsl.ts +0 -97
  212. package/src/programs/node-image/index.ts +0 -7
  213. package/src/programs/node-image/texture.ts +0 -435
  214. package/src/programs/node-image/vert.glsl.ts +0 -60
  215. package/src/programs/node-rect/base/drawHover.ts +0 -77
  216. package/src/programs/node-rect/base/drawLabel.ts +0 -149
  217. package/src/programs/node-rect/base/frag.glsl.ts +0 -67
  218. package/src/programs/node-rect/base/index.ts +0 -109
  219. package/src/programs/node-rect/base/vert.glsl.ts +0 -87
  220. package/src/programs/node-rect/index.ts +0 -19
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
+ var react = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
+ var Context = /*#__PURE__*/react.createContext({});
10
+ var Provider = function Provider(props) {
11
+ var Provider = Context.Provider;
12
+ return /*#__PURE__*/jsxRuntime.jsx(Provider, _objectSpread({}, props));
13
+ };
14
+
15
+ exports.Context = Context;
16
+ exports.Provider = Provider;
@@ -1,430 +1,107 @@
1
1
  'use strict';
2
2
 
3
- var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
4
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
6
- var _typeof = require('@babel/runtime/helpers/typeof');
7
3
  var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
8
4
  var _createClass = require('@babel/runtime/helpers/createClass');
9
5
  var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn');
10
- var _get = require('@babel/runtime/helpers/get');
11
6
  var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
7
+ var _get = require('@babel/runtime/helpers/get');
12
8
  var _inherits = require('@babel/runtime/helpers/inherits');
13
- var _regeneratorRuntime = require('@babel/runtime/regenerator');
14
- var utilities = require('@react-fabric/utilities');
15
- var edgeCurve = require('@sigma/edge-curve');
16
- var ElkConstructor = require('elkjs/lib/elk.bundled');
17
9
  var Graphology = require('graphology');
18
10
  var graphologyLayout = require('graphology-layout');
19
11
  var forceAtlas2 = require('graphology-layout-forceatlas2');
20
- var ForceAtlas2Worker = require('graphology-layout-forceatlas2/worker');
21
- var utils = require('sigma/utils');
22
- var elkWorker = require('../_virtual/elk-worker.js');
23
12
 
24
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
25
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
26
13
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
27
14
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
15
+ function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(t.prototype ), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
28
16
  var Graph = /*#__PURE__*/function (_Graphology) {
29
- function Graph(options) {
30
- var _this;
17
+ function Graph() {
31
18
  _classCallCheck(this, Graph);
32
- _this = _callSuper(this, Graph, [options]);
33
- var edgeHandler = utilities.debounce(function () {
34
- return _this.checkParallelEdges();
35
- });
36
- _this.on("edgeAdded", edgeHandler);
37
- _this.on("edgeDropped", edgeHandler);
38
- var fireNodeSelect = utilities.debounce(function () {
39
- _this.emit("nodesSelected", _this.filterNodes(function (_, atts) {
40
- return atts.selected;
41
- }));
42
- });
43
- var nodeSelectHandler = function nodeSelectHandler(_ref) {
44
- var name = _ref.name;
45
- if (name === "selected") {
46
- fireNodeSelect();
47
- }
48
- };
49
- _this.on("nodeDropped", fireNodeSelect);
50
- _this.on("nodeAttributesUpdated", nodeSelectHandler);
51
- return _this;
19
+ return _callSuper(this, Graph, [{
20
+ multi: true
21
+ }]);
52
22
  }
53
23
  _inherits(Graph, _Graphology);
54
24
  return _createClass(Graph, [{
25
+ key: "importGraph",
26
+ value: function importGraph(data) {
27
+ var _this = this;
28
+ var applyLayout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
29
+ _superPropGet(Graph, "clear", this, 3)([]);
30
+ _superPropGet(Graph, "import", this, 3)([{
31
+ nodes: data.nodes.map(function (n) {
32
+ return {
33
+ key: n.id,
34
+ attributes: _this.enrichNodeAttributes(n)
35
+ };
36
+ }),
37
+ edges: data.edges.map(function (e) {
38
+ return {
39
+ key: e.id,
40
+ source: e.source,
41
+ target: e.target,
42
+ attributes: e
43
+ };
44
+ })
45
+ }, false]);
46
+ setTimeout(function () {
47
+ if (applyLayout) {
48
+ graphologyLayout.random.assign(_this);
49
+ var settings = forceAtlas2.inferSettings(_this);
50
+ forceAtlas2.assign(_this, {
51
+ iterations: 500,
52
+ settings: settings
53
+ });
54
+ }
55
+ _this.emit("layoutDone");
56
+ }, 500);
57
+ return this;
58
+ }
59
+ }, {
55
60
  key: "on",
56
61
  value: function on(type, listener) {
57
- return _get(_getPrototypeOf(Graph.prototype), "on", this).call(this, type, listener);
62
+ return _superPropGet(Graph, "on", this, 3)([type, listener]);
58
63
  }
59
64
  }, {
60
65
  key: "off",
61
66
  value: function off(type, listener) {
62
- return _get(_getPrototypeOf(Graph.prototype), "off", this).call(this, type, listener);
67
+ return _superPropGet(Graph, "off", this, 3)([type, listener]);
63
68
  }
64
69
  }, {
65
70
  key: "emit",
66
71
  value: function emit(type) {
67
- var _get2;
68
72
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
69
73
  args[_key - 1] = arguments[_key];
70
74
  }
71
- return (_get2 = _get(_getPrototypeOf(Graph.prototype), "emit", this)).call.apply(_get2, [this, type].concat(args));
72
- }
73
- }, {
74
- key: "mergeNodes",
75
- value: function mergeNodes(key, nodes, attributesOrNodeReducer, edgeReducer) {
76
- var _this2 = this;
77
- if (!nodes.length) return;
78
- var newNodeAttributes = {};
79
- var edgeList = [];
80
- var attributeList = [];
81
- nodes.forEach(function (n) {
82
- var atts = _this2.getNodeAttributes(n);
83
- if (atts) {
84
- attributeList.push(atts);
85
- }
86
- var edges = _this2.edges(n);
87
- if (edges.length) {
88
- edges.forEach(function (e) {
89
- var source = _this2.source(e);
90
- var target = _this2.target(e);
91
- var edge = _this2.getEdgeAttributes(e);
92
- if (edge) {
93
- edgeList.push({
94
- key: e,
95
- // move source to new node if source is old node
96
- source: source === n ? key : source,
97
- // move target to new node if target is old node
98
- target: target === n ? key : target,
99
- attributes: edge
100
- });
101
- }
102
- });
103
- }
104
- });
105
- if (typeof attributesOrNodeReducer === "function") {
106
- newNodeAttributes = attributesOrNodeReducer(attributeList);
107
- } else if (_typeof(attributesOrNodeReducer) === "object") {
108
- Object.assign(newNodeAttributes, attributesOrNodeReducer);
109
- }
110
- if (typeof edgeReducer === "function") {
111
- edgeList = edgeReducer(edgeList);
112
- }
113
- this.dropNodes(nodes);
114
- this["import"]({
115
- nodes: [{
116
- key: key,
117
- attributes: newNodeAttributes
118
- }],
119
- edges: edgeList
120
- }, true);
121
- return this;
122
- }
123
- }, {
124
- key: "groupNodes",
125
- value: function groupNodes(key, nodes, attributesOrNodeReducer, edgeReducer) {
126
- var _this3 = this;
127
- if (!nodes.length) return;
128
- var newNodeAttributes = {
129
- nodeList: nodes,
130
- isGroup: true,
131
- expanded: false
132
- };
133
- var edgeList = [];
134
- var movedEdges = [];
135
- var attributeList = [];
136
- nodes.forEach(function (n) {
137
- var atts = _this3.getNodeAttributes(n);
138
- if (atts) {
139
- attributeList.push(atts);
140
- }
141
- var edges = _this3.edges(n);
142
- if (edges.length) {
143
- var nodeEdges = edges.map(function (e) {
144
- var source = _this3.source(e);
145
- var target = _this3.target(e);
146
- var edge = _this3.getEdgeAttributes(e);
147
- if (edge) {
148
- movedEdges.push({
149
- key: e,
150
- // move source to group node if source is not old node
151
- source: source === n ? n : key,
152
- // move target to group node if target is not old node
153
- target: target === n ? n : key,
154
- attributes: edge
155
- });
156
- // make new connection to neighboring node
157
- edgeList.push({
158
- key: "".concat(key, "-").concat(e),
159
- source: source === n ? key : source,
160
- target: target === n ? key : target,
161
- attributes: edge
162
- });
163
- }
164
- _this3.dropEdge(e);
165
- return {
166
- key: e,
167
- // move source to group node if source is not old node
168
- source: source,
169
- // move target to group node if target is not old node
170
- target: target,
171
- attributes: edge
172
- };
173
- });
174
- _this3.setNodeAttribute(n, "hidden", true);
175
- _this3.setNodeAttribute(n, "selected", false);
176
- // store original edges for grouped node
177
- _this3.setNodeAttribute(n, "originalEdges", nodeEdges);
178
- }
179
- });
180
- if (typeof attributesOrNodeReducer === "function") {
181
- newNodeAttributes = Object.assign(newNodeAttributes, attributesOrNodeReducer(attributeList));
182
- } else if (_typeof(attributesOrNodeReducer) === "object") {
183
- Object.assign(newNodeAttributes, attributesOrNodeReducer);
184
- }
185
- if (typeof edgeReducer === "function") {
186
- edgeList = edgeReducer(edgeList);
187
- }
188
- this["import"]({
189
- nodes: [{
190
- key: key,
191
- attributes: newNodeAttributes
192
- }],
193
- edges: edgeList.concat(movedEdges)
194
- }, true);
195
- return this;
196
- }
197
- }, {
198
- key: "ungroupNode",
199
- value: function ungroupNode(node) {
200
- var _atts$nodeList,
201
- _this4 = this;
202
- var atts = this.getNodeAttributes(node);
203
- if (!atts || !atts.isGroup) return;
204
- var nodes = (_atts$nodeList = atts.nodeList) !== null && _atts$nodeList !== void 0 ? _atts$nodeList : [];
205
- nodes.forEach(function (n) {
206
- var originalEdges = _this4.getNodeAttribute(n, "originalEdges");
207
- if (originalEdges && Array.isArray(originalEdges)) {
208
- originalEdges.forEach(function (e) {
209
- _this4.addEdgeWithKey(e.key, e.source, e.target, e.attributes);
210
- });
211
- }
212
- _this4.setNodeAttribute(n, "hidden", false);
213
- _this4.removeNodeAttribute(n, "originalEdges");
214
- });
215
- this.dropNode(node);
216
- return this;
217
- }
218
- }, {
219
- key: "toggleExpanded",
220
- value: function toggleExpanded(node, force) {
221
- var _this5 = this;
222
- var expanded = force !== null && force !== void 0 ? force : !this.getNodeAttribute(node, "expanded");
223
- var nodes = this.getNodeAttribute(node, "nodeList");
224
- this.setNodeAttribute(node, "expanded", expanded);
225
- nodes === null || nodes === void 0 || nodes.forEach(function (n) {
226
- _this5.setNodeAttribute(n, "hidden", !expanded);
227
- });
228
- return this;
75
+ return _superPropGet(Graph, "emit", this, 3)([type].concat(args));
229
76
  }
230
77
 
231
- // @ts-expect-error ignore
78
+ /**
79
+ * @deprecated
80
+ * use `importGraph` instead
81
+ */
232
82
  }, {
233
83
  key: "import",
234
- value: function _import(data, merge) {
235
- var newNodes = [];
236
- if (data instanceof Graph) {
237
- newNodes.push.apply(newNodes, _toConsumableArray(data.nodes()));
238
- } else {
239
- newNodes.push.apply(newNodes, _toConsumableArray(data.nodes.map(function (n) {
240
- return n.key;
241
- })));
242
- }
243
- _get(_getPrototypeOf(Graph.prototype), "import", this).call(this, data, merge);
244
- // fire events for nodes added
245
- this.emit("nodesLoaded", newNodes);
246
- // apply random positions for nodes
247
- // const positions = random(this as any);
248
- // animateNodes(
249
- // this as any,
250
- // positions,
251
- // {
252
- // duration: 200,
253
- // },
254
- // () => {
255
- // // fire layout done event
256
- // this.emit("layoutDone");
257
- // },
258
- // );
259
- void this.elkLayout("force");
260
- return this;
261
- }
262
- }, {
263
- key: "circularLayout",
264
- value: function circularLayout() {
265
- var _this6 = this;
266
- if (this.size === 0) return this;
267
- var positions = graphologyLayout.circular(this);
268
- utils.animateNodes(this, positions, {
269
- duration: 200
270
- }, function () {
271
- _this6.emit("layoutDone");
272
- });
273
- return this;
274
- }
275
- }, {
276
- key: "forceLayout",
277
- value: function forceLayout() {
278
- var _this$_worker,
279
- _this$_worker2,
280
- _this7 = this;
281
- var settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
282
- if (this.size === 0) return this;
283
- var sensibleSettings = forceAtlas2.inferSettings(this);
284
- if ((_this$_worker = this._worker) !== null && _this$_worker !== void 0 && _this$_worker.isRunning()) {
285
- clearTimeout(this._timer);
286
- }
287
- (_this$_worker2 = this._worker) === null || _this$_worker2 === void 0 || _this$_worker2.kill();
288
- this._worker = new ForceAtlas2Worker(this, {
289
- settings: _objectSpread(_objectSpread({}, sensibleSettings), settings)
290
- });
291
- this.emit("layoutRunning", true);
292
- this._worker.start();
293
- this._timer = setTimeout(function () {
294
- var _this7$_worker, _this7$_worker2;
295
- (_this7$_worker = _this7._worker) === null || _this7$_worker === void 0 || _this7$_worker.stop();
296
- (_this7$_worker2 = _this7._worker) === null || _this7$_worker2 === void 0 || _this7$_worker2.kill();
297
- _this7.emit("layoutRunning", false);
298
- _this7.emit("layoutDone");
299
- },
300
- // @ts-expect-error ignore
301
- this.nodes().length * window.__GRAPH_LAYOUT_DURATION_MULTIPLIER__);
302
- return this;
303
- }
304
-
305
- // @ts-expect-error ignore
306
- }, {
307
- key: "elkLayout",
308
- value: function () {
309
- var _elkLayout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(type) {
310
- var _this8 = this;
311
- return _regeneratorRuntime.wrap(function _callee$(_context) {
312
- while (1) switch (_context.prev = _context.next) {
313
- case 0:
314
- if (!this.elk) this.elk = new ElkConstructor({
315
- workerFactory: function workerFactory() {
316
- return new elkWorker();
317
- }
318
- });
319
- this.emit("layoutRunning", true);
320
- this.elk.layout({
321
- id: "root",
322
- // width: 1600,
323
- // height: 900,
324
- children: this.mapNodes(function (node, atts) {
325
- var _atts$size, _atts$weight, _atts$size2, _atts$weight2;
326
- return {
327
- id: node,
328
- width: (_atts$size = atts.size) !== null && _atts$size !== void 0 ? _atts$size : Math.max(16, ((_atts$weight = atts.weight) !== null && _atts$weight !== void 0 ? _atts$weight : 0) * 3),
329
- height: (_atts$size2 = atts.size) !== null && _atts$size2 !== void 0 ? _atts$size2 : Math.max(16, ((_atts$weight2 = atts.weight) !== null && _atts$weight2 !== void 0 ? _atts$weight2 : 0) * 3)
330
- };
331
- }),
332
- edges: this.mapEdges(function (edge, _, source, target) {
333
- return {
334
- id: edge,
335
- sources: [source],
336
- targets: [target]
337
- };
338
- })
339
- }, {
340
- logging: true,
341
- measureExecutionTime: true,
342
- layoutOptions: {
343
- "elk.algorithm": type
344
- }
345
- }).then(function (graph) {
346
- var _graph$children$map, _graph$children;
347
- var positions = Object.fromEntries((_graph$children$map = (_graph$children = graph.children) === null || _graph$children === void 0 ? void 0 : _graph$children.map(function (node) {
348
- var _node$x, _node$y;
349
- return [node.id, {
350
- x: (_node$x = node.x) !== null && _node$x !== void 0 ? _node$x : 0,
351
- y: (_node$y = node.y) !== null && _node$y !== void 0 ? _node$y : 0
352
- }];
353
- })) !== null && _graph$children$map !== void 0 ? _graph$children$map : []);
354
- utils.animateNodes(_this8, positions, {
355
- duration: 200
356
- }, function () {
357
- setTimeout(function () {
358
- _this8.emit("layoutDone");
359
- }, 100);
360
- });
361
- })["catch"](console.error)["finally"](function () {
362
- _this8.emit("layoutRunning", false);
363
- });
364
- case 3:
365
- case "end":
366
- return _context.stop();
367
- }
368
- }, _callee, this);
369
- }));
370
- function elkLayout(_x) {
371
- return _elkLayout.apply(this, arguments);
372
- }
373
- return elkLayout;
374
- }()
375
- }, {
376
- key: "dropNodes",
377
- value: function dropNodes(nodes) {
378
- var _this9 = this;
379
- if (!nodes.length) return;
380
- nodes.forEach(function (n) {
381
- return _this9.dropNode(n);
382
- });
84
+ value: function _import() {
85
+ throw new Error("Graphology import is deprecated, use `importGraph` instead");
383
86
  }
384
87
 
385
88
  /**
386
- * parallel edge check to be called after adding edges
89
+ * @deprecated
90
+ * use `exportGraph` instead
387
91
  */
388
92
  }, {
389
- key: "getCurvature",
390
- value: function getCurvature(index) {
391
- var maxIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
392
- if (maxIndex <= 0) throw new Error("Invalid maxIndex");
393
- if (index < 0) return -this.getCurvature(-index, maxIndex);
394
- var amplitude = 0.25;
395
- var maxCurvature = amplitude * (1 - Math.exp(-maxIndex / amplitude)) * edgeCurve.DEFAULT_EDGE_CURVATURE;
396
- return maxCurvature * index / maxIndex;
93
+ key: "export",
94
+ value: function _export() {
95
+ throw new Error("Graphology export is deprecated, use `exportGraph` instead");
397
96
  }
398
97
  }, {
399
- key: "checkParallelEdges",
400
- value: function checkParallelEdges() {
401
- var _this10 = this;
402
- // Use dedicated helper to identify parallel edges:
403
- // @ts-expect-error ignore
404
- edgeCurve.indexParallelEdgesIndex(this, {
405
- edgeIndexAttribute: "parallelIndex",
406
- edgeMinIndexAttribute: "parallelMinIndex",
407
- edgeMaxIndexAttribute: "parallelMaxIndex"
408
- });
409
- // Adapt types and curvature of parallel edges for rendering:
410
- this.forEachEdge(function (edge, _ref2) {
411
- var parallelIndex = _ref2.parallelIndex,
412
- parallelMinIndex = _ref2.parallelMinIndex,
413
- parallelMaxIndex = _ref2.parallelMaxIndex;
414
- if (typeof parallelMinIndex === "number") {
415
- _this10.mergeEdgeAttributes(edge, {
416
- type: parallelIndex ? "curved" : "line",
417
- curvature: _this10.getCurvature(parallelIndex !== null && parallelIndex !== void 0 ? parallelIndex : 1, parallelMaxIndex !== null && parallelMaxIndex !== void 0 ? parallelMaxIndex : 1)
418
- });
419
- } else if (typeof parallelIndex === "number") {
420
- _this10.mergeEdgeAttributes(edge, {
421
- type: "curved",
422
- curvature: _this10.getCurvature(parallelIndex !== null && parallelIndex !== void 0 ? parallelIndex : 1, parallelMaxIndex !== null && parallelMaxIndex !== void 0 ? parallelMaxIndex : 1)
423
- });
424
- } else {
425
- _this10.setEdgeAttribute(edge, "type", "line");
426
- }
427
- });
98
+ key: "enrichNodeAttributes",
99
+ value: function enrichNodeAttributes(node) {
100
+ if (!node.x && !node.y) {
101
+ node.x = 0;
102
+ node.y = 0;
103
+ }
104
+ return node;
428
105
  }
429
106
  }]);
430
107
  }(Graphology);
package/dist/cjs/index.js CHANGED
@@ -1,33 +1,37 @@
1
1
  'use strict';
2
2
 
3
- var Viewer = require('./components/Viewer.js');
4
3
  var index = require('./graph/index.js');
4
+ var Graph = require('./viewer/Graph.js');
5
5
 
6
- /*
6
+ /**
7
7
  * React Fabric
8
- * @version: 1.0.0
8
+ * @version 1.0.0
9
+ * @license MIT
10
+ * @copyright 2024 Adarsh Pastakia
9
11
  *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
10
18
  *
11
- * The MIT License (MIT)
12
- * Copyright (c) 2024 Adarsh Pastakia
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
13
21
  *
14
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
15
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
16
- * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
18
- * subject to the following conditions:
19
- *
20
- * The above copyright notice and this permission notice shall be included in all copies or substantial
21
- * portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
24
- * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
27
29
  */
28
30
 
29
- // @ts-expect-error ignore
30
- window.__GRAPH_LAYOUT_DURATION_MULTIPLIER__ = 10;
31
+ var GRAPH_PACKAGE = "@react-fabric/graph";
32
+ var GRAPH_VERSION = "1.0.0";
31
33
 
32
- exports.SigmaGraph = Viewer.SigmaGraph;
33
34
  exports.Graph = index.Graph;
35
+ exports.GraphViewer = Graph.GraphViewer;
36
+ exports.GRAPH_PACKAGE = GRAPH_PACKAGE;
37
+ exports.GRAPH_VERSION = GRAPH_VERSION;
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ var types = require('sigma/types');
4
+
5
+ /**
6
+ * React Fabric
7
+ * @version 1.0.0
8
+ * @license MIT
9
+ * @copyright 2024 Adarsh Pastakia
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ * SOFTWARE.
28
+ */
29
+
30
+ function edgeReducer(_, edge, attrs) {
31
+ var _edge$size;
32
+ // @ts-expect-error ignore
33
+ if (attrs.path === "curved") edge.curvature = 0.3;
34
+ if (attrs.style === "dashed") {
35
+ // @ts-expect-error ignore
36
+ edge.dashSize = 4;
37
+ // @ts-expect-error ignore
38
+ edge.gapSize = 8;
39
+ }
40
+ // @ts-expect-error ignore
41
+ if (attrs.style === "dotted") edge.dashSize = edge.gapSize = (_edge$size = edge.size) !== null && _edge$size !== void 0 ? _edge$size : 2;
42
+ return edge;
43
+ }
44
+ function defaultEdgeStyles() {
45
+ var isDark = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
46
+ return [types.DEFAULT_STYLES.edges, {
47
+ size: {
48
+ attribute: "size",
49
+ defaultValue: 1
50
+ },
51
+ path: {
52
+ attribute: "path",
53
+ defaultValue: "straight"
54
+ },
55
+ color: {
56
+ attribute: "color",
57
+ defaultValue: isDark ? "#475569" : "#94a3b8"
58
+ },
59
+ head: {
60
+ attribute: "head"
61
+ },
62
+ tail: {
63
+ attribute: "tail"
64
+ },
65
+ gapSize: 0,
66
+ dashSize: 0,
67
+ parallelPath: "curved",
68
+ dashColor: isDark ? "#181818" : "#fff",
69
+ labelColor: isDark ? "#dedede" : "#545454",
70
+ labelVisibility: "auto",
71
+ labelPosition: "auto"
72
+ }];
73
+ }
74
+
75
+ exports.defaultEdgeStyles = defaultEdgeStyles;
76
+ exports.edgeReducer = edgeReducer;