@receptron/graphai_vue_cytoscape 0.0.1 → 0.0.3

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.
package/README.md CHANGED
@@ -0,0 +1,39 @@
1
+
2
+ ## Composable to show GraphAI state to Vue using cytoscape
3
+
4
+ ### install
5
+
6
+ ```sh
7
+ yarn add @receptron/graphai_vue_cytoscape
8
+ ```
9
+
10
+ ### Usage
11
+
12
+
13
+ ```typescript
14
+ import { defineComponent, ref } from "vue";
15
+
16
+ import { GraphAI } from "graphai";
17
+ import { useCytoscape } from "@receptron/graphai_vue_cytoscape";
18
+
19
+ export default defineComponent({
20
+ setup() {
21
+ const selectdGraph = ref(graphData)
22
+ const { updateCytoscape, cytoscapeRef, resetCytoscape } = useCytoscape(selectdGraph);
23
+
24
+ const run = async () => {
25
+ const graphai = new GraphAI(selectdGraph.value, agents);
26
+ graphai.onLogCallback = async ({ nodeId, state }) => {
27
+ updateCytoscape(nodeId, state);
28
+ };
29
+ await graphai.run();
30
+ }
31
+ run();
32
+
33
+ return {
34
+ cytoscapeRef
35
+ };
36
+ }
37
+ });
38
+ ```
39
+
@@ -0,0 +1,7 @@
1
+ import { Ref, ComputedRef } from "vue";
2
+ import { GraphData, NodeState } from "graphai";
3
+ export declare const useCytoscape: (selectedGraph: ComputedRef<GraphData> | Ref<GraphData>) => {
4
+ cytoscapeRef: Ref<any>;
5
+ updateCytoscape: (nodeId: string, state: NodeState) => Promise<void>;
6
+ resetCytoscape: () => void;
7
+ };
@@ -40,7 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
40
40
  };
41
41
  var _a;
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.useCytoscope = void 0;
43
+ exports.useCytoscape = void 0;
44
44
  var vue_1 = require("vue");
45
45
  var graphai_1 = require("graphai");
46
46
  var cytoscape_1 = __importDefault(require("cytoscape"));
@@ -120,7 +120,7 @@ var parseInput = function (input) {
120
120
  return { source: source, label: label };
121
121
  };
122
122
  var cytoscapeFromGraph = function (graph_data) {
123
- var elements = Object.keys(graph_data.nodes).reduce(function (tmp, nodeId) {
123
+ var elements = Object.keys(graph_data.nodes || {}).reduce(function (tmp, nodeId) {
124
124
  var node = graph_data.nodes[nodeId];
125
125
  var isStatic = "value" in node;
126
126
  var cyNode = {
@@ -162,27 +162,28 @@ var cytoscapeFromGraph = function (graph_data) {
162
162
  }, { nodes: [], edges: [], map: {} });
163
163
  return { elements: elements };
164
164
  };
165
- var useCytoscope = function (selectedGraph) {
165
+ var useCytoscape = function (selectedGraph) {
166
+ var _a;
166
167
  var cy = null;
167
- var cytoscopeData = (0, vue_1.ref)(cytoscapeFromGraph(selectedGraph.value));
168
- var cytoscopeRef = (0, vue_1.ref)();
169
- var updateCytoscope = function (nodeId, state) { return __awaiter(void 0, void 0, void 0, function () {
168
+ var cytoscapeData = (0, vue_1.ref)(cytoscapeFromGraph((_a = selectedGraph.value) !== null && _a !== void 0 ? _a : { nodes: {} }));
169
+ var cytoscapeRef = (0, vue_1.ref)();
170
+ var updateCytoscape = function (nodeId, state) { return __awaiter(void 0, void 0, void 0, function () {
170
171
  var elements, graph, nodeData;
171
- var _a;
172
- return __generator(this, function (_b) {
173
- switch (_b.label) {
172
+ var _a, _b, _c;
173
+ return __generator(this, function (_d) {
174
+ switch (_d.label) {
174
175
  case 0:
175
176
  if (!(state === graphai_1.NodeState.Completed || state === graphai_1.NodeState.Waiting)) return [3 /*break*/, 2];
176
177
  return [4 /*yield*/, (0, graphai_1.sleep)(100)];
177
178
  case 1:
178
- _b.sent();
179
- _b.label = 2;
179
+ _d.sent();
180
+ _d.label = 2;
180
181
  case 2:
181
- elements = cytoscopeData.value.elements;
182
+ elements = cytoscapeData.value.elements;
182
183
  elements.map[nodeId].data.color = colorMap[state];
183
184
  graph = selectedGraph.value;
184
- nodeData = graph.nodes[nodeId];
185
- if ("agent" in nodeData && state === graphai_1.NodeState.Queued && ((_a = nodeData.priority) !== null && _a !== void 0 ? _a : 0) > 0) {
185
+ nodeData = (_b = ((_a = graph === null || graph === void 0 ? void 0 : graph.nodes) !== null && _a !== void 0 ? _a : {})[nodeId]) !== null && _b !== void 0 ? _b : [];
186
+ if ("agent" in nodeData && state === graphai_1.NodeState.Queued && ((_c = nodeData.priority) !== null && _c !== void 0 ? _c : 0) > 0) {
186
187
  // computed node
187
188
  elements.map[nodeId].data.color = colorPriority;
188
189
  }
@@ -192,22 +193,22 @@ var useCytoscope = function (selectedGraph) {
192
193
  elements.map[nodeId].data.color = colorStatic;
193
194
  }
194
195
  }
195
- cytoscopeData.value = { elements: elements };
196
+ cytoscapeData.value = { elements: elements };
196
197
  if (!(state === graphai_1.NodeState.Injected)) return [3 /*break*/, 4];
197
198
  return [4 /*yield*/, (0, graphai_1.sleep)(100)];
198
199
  case 3:
199
- _b.sent();
200
+ _d.sent();
200
201
  elements.map[nodeId].data.color = colorStatic;
201
- cytoscopeData.value = { elements: elements };
202
- _b.label = 4;
202
+ cytoscapeData.value = { elements: elements };
203
+ _d.label = 4;
203
204
  case 4: return [2 /*return*/];
204
205
  }
205
206
  });
206
207
  }); };
207
- var createCytoscope = function () {
208
+ var createCytoscape = function () {
208
209
  try {
209
210
  cy = (0, cytoscape_1.default)({
210
- container: cytoscopeRef.value,
211
+ container: cytoscapeRef.value,
211
212
  style: cyStyle,
212
213
  layout: {
213
214
  name: layout,
@@ -235,8 +236,8 @@ var useCytoscope = function (selectedGraph) {
235
236
  case 0:
236
237
  if (!cy) return [3 /*break*/, 2];
237
238
  cy.elements().remove();
238
- cy.add(cytoscopeData.value.elements);
239
- name_1 = cytoscopeData.value.elements.nodes.reduce(function (prevName, node) {
239
+ cy.add(cytoscapeData.value.elements);
240
+ name_1 = cytoscapeData.value.elements.nodes.reduce(function (prevName, node) {
240
241
  if (node.position) {
241
242
  return "preset";
242
243
  }
@@ -261,35 +262,35 @@ var useCytoscope = function (selectedGraph) {
261
262
  cy.nodes().forEach(function (cynode) {
262
263
  var id = cynode.id();
263
264
  var pos = cynode.position();
264
- var node = cytoscopeData.value.elements.map[id];
265
+ var node = cytoscapeData.value.elements.map[id];
265
266
  node.position = pos;
266
267
  });
267
268
  }
268
269
  };
269
- var resetCytoscope = function () {
270
- var elements = cytoscopeData.value.elements;
270
+ var resetCytoscape = function () {
271
+ var elements = cytoscapeData.value.elements;
271
272
  Object.keys(elements.map).forEach(function (nodeId) {
272
273
  var graph = selectedGraph.value;
273
274
  var nodeData = graph.nodes[nodeId];
274
275
  elements.map[nodeId].data.color = "value" in nodeData ? colorStatic : colorMap[graphai_1.NodeState.Waiting];
275
276
  });
276
- cytoscopeData.value = { elements: elements };
277
+ cytoscapeData.value = { elements: elements };
277
278
  };
278
- (0, vue_1.watch)(cytoscopeData, function () {
279
+ (0, vue_1.watch)(cytoscapeData, function () {
279
280
  console.log("updated");
280
281
  updateGraphData();
281
282
  });
282
283
  (0, vue_1.watch)(selectedGraph, function () {
283
- cytoscopeData.value = cytoscapeFromGraph(selectedGraph.value);
284
+ cytoscapeData.value = cytoscapeFromGraph(selectedGraph.value);
284
285
  });
285
286
  (0, vue_1.onMounted)(function () {
286
- createCytoscope();
287
+ createCytoscape();
287
288
  updateGraphData();
288
289
  });
289
290
  return {
290
- cytoscopeRef: cytoscopeRef,
291
- updateCytoscope: updateCytoscope,
292
- resetCytoscope: resetCytoscope,
291
+ cytoscapeRef: cytoscapeRef,
292
+ updateCytoscape: updateCytoscape,
293
+ resetCytoscape: resetCytoscape,
293
294
  };
294
295
  };
295
- exports.useCytoscope = useCytoscope;
296
+ exports.useCytoscape = useCytoscape;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@receptron/graphai_vue_cytoscape",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "main": "lib/cytoscape.js",
5
5
  "files": [
6
6
  "./lib"
@@ -15,6 +15,16 @@
15
15
  "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
16
16
  "format": "prettier --write src/"
17
17
  },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/receptron/graphai_utils"
21
+ },
22
+ "author": "Receptron team",
23
+ "license": "MIT",
24
+ "bugs": {
25
+ "url": "https://github.com/receptron/graphai_utils/issues"
26
+ },
27
+ "homepage": "https://github.com/receptron/graphai_utils/tree/main/packages/vue-cytoscape#readme",
18
28
  "dependencies": {
19
29
  "cytoscape": "^3.29.2",
20
30
  "cytoscape-klay": "^3.1.4"
@@ -1,7 +0,0 @@
1
- import { Ref, ComputedRef } from "vue";
2
- import { GraphData, NodeState } from "graphai";
3
- export declare const useCytoscope: (selectedGraph: ComputedRef<GraphData> | Ref<GraphData>) => {
4
- cytoscopeRef: Ref<any>;
5
- updateCytoscope: (nodeId: string, state: NodeState) => Promise<void>;
6
- resetCytoscope: () => void;
7
- };