@receptron/graphai_vue_cytoscape 0.0.6 → 0.0.8

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.
@@ -7,4 +7,7 @@ export declare const useCytoscape: (selectedGraph: ComputedRef<GraphData> | Ref<
7
7
  cytoscapeRef: Ref<any, any>;
8
8
  updateCytoscape: (nodeId: string, state: NodeState) => Promise<void>;
9
9
  resetCytoscape: () => void;
10
+ layoutCytoscape: (key: string) => void;
11
+ loadLayout: (key: string) => void;
12
+ zoomingEnabled: Ref<boolean, boolean>;
10
13
  };
package/lib/cytoscape.js CHANGED
@@ -114,7 +114,6 @@ var colorMap = (_a = {},
114
114
  _a);
115
115
  var parseInput = function (input) {
116
116
  // WARNING: Assuming the first character is always ":"
117
- console.log(input);
118
117
  var ids = input.slice(1).split(".");
119
118
  var source = ids.shift() || "";
120
119
  var label = ids.length ? ids.join(".") : undefined;
@@ -158,14 +157,16 @@ var cytoscapeFromGraph = function (graph_data) {
158
157
  if ("inputs" in node) {
159
158
  // computed node
160
159
  (0, exports.inputs2dataSources)(node.inputs).forEach(function (input) {
161
- var _a = parseInput(input), source = _a.source, label = _a.label;
162
- tmp.edges.push({
163
- data: {
164
- source: source,
165
- target: nodeId,
166
- label: label,
167
- },
168
- });
160
+ if (input[0] === ":") {
161
+ var _a = parseInput(input), source = _a.source, label = _a.label;
162
+ tmp.edges.push({
163
+ data: {
164
+ source: source,
165
+ target: nodeId,
166
+ label: label,
167
+ },
168
+ });
169
+ }
169
170
  });
170
171
  }
171
172
  if ("update" in node && node.update) {
@@ -189,6 +190,7 @@ var useCytoscape = function (selectedGraph) {
189
190
  var cy = null;
190
191
  var cytoscapeData = (0, vue_1.ref)(cytoscapeFromGraph((_a = selectedGraph.value) !== null && _a !== void 0 ? _a : { nodes: {} }));
191
192
  var cytoscapeRef = (0, vue_1.ref)();
193
+ var zoomingEnabled = (0, vue_1.ref)(true);
192
194
  var updateCytoscape = function (nodeId, state) { return __awaiter(void 0, void 0, void 0, function () {
193
195
  var elements, graph, nodeData;
194
196
  var _a, _b, _c;
@@ -307,10 +309,44 @@ var useCytoscape = function (selectedGraph) {
307
309
  createCytoscape();
308
310
  updateGraphData();
309
311
  });
312
+ var layoutCytoscape = function (key) {
313
+ if (cy) {
314
+ var positions = cy.nodes().map(function (node) {
315
+ return {
316
+ id: node.id(),
317
+ position: node.position(),
318
+ };
319
+ });
320
+ console.log(JSON.stringify(positions));
321
+ localStorage.setItem("layoutData-" + key, JSON.stringify(positions));
322
+ }
323
+ };
324
+ var loadLayout = function (key) {
325
+ var savedLayoutData = localStorage.getItem("layoutData-" + key);
326
+ if (savedLayoutData) {
327
+ var positions = JSON.parse(savedLayoutData);
328
+ positions.forEach(function (data) {
329
+ if (cy) {
330
+ var node = cy.getElementById(data.id);
331
+ if (node) {
332
+ node.position(data.position);
333
+ }
334
+ }
335
+ });
336
+ }
337
+ };
338
+ (0, vue_1.watch)(zoomingEnabled, function (value) {
339
+ if (cy) {
340
+ cy.zoomingEnabled(value);
341
+ }
342
+ });
310
343
  return {
311
344
  cytoscapeRef: cytoscapeRef,
312
345
  updateCytoscape: updateCytoscape,
313
346
  resetCytoscape: resetCytoscape,
347
+ layoutCytoscape: layoutCytoscape,
348
+ loadLayout: loadLayout,
349
+ zoomingEnabled: zoomingEnabled,
314
350
  };
315
351
  };
316
352
  exports.useCytoscape = useCytoscape;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@receptron/graphai_vue_cytoscape",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "main": "lib/cytoscape.js",
5
5
  "files": [
6
6
  "./lib"