@receptron/graphai_vue_cytoscape 0.0.2 → 0.0.4
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 +39 -0
- package/lib/cytoscape.js +12 -11
- package/package.json +11 -1
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
|
+
|
package/lib/cytoscape.js
CHANGED
|
@@ -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 = {
|
|
@@ -163,26 +163,27 @@ var cytoscapeFromGraph = function (graph_data) {
|
|
|
163
163
|
return { elements: elements };
|
|
164
164
|
};
|
|
165
165
|
var useCytoscape = function (selectedGraph) {
|
|
166
|
+
var _a;
|
|
166
167
|
var cy = null;
|
|
167
|
-
var cytoscapeData = (0, vue_1.ref)(cytoscapeFromGraph(selectedGraph.value));
|
|
168
|
+
var cytoscapeData = (0, vue_1.ref)(cytoscapeFromGraph((_a = selectedGraph.value) !== null && _a !== void 0 ? _a : { nodes: {} }));
|
|
168
169
|
var cytoscapeRef = (0, vue_1.ref)();
|
|
169
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 (
|
|
173
|
-
switch (
|
|
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
|
-
|
|
179
|
-
|
|
179
|
+
_d.sent();
|
|
180
|
+
_d.label = 2;
|
|
180
181
|
case 2:
|
|
181
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 && ((
|
|
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
|
}
|
|
@@ -196,10 +197,10 @@ var useCytoscape = function (selectedGraph) {
|
|
|
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
|
-
|
|
200
|
+
_d.sent();
|
|
200
201
|
elements.map[nodeId].data.color = colorStatic;
|
|
201
202
|
cytoscapeData.value = { elements: elements };
|
|
202
|
-
|
|
203
|
+
_d.label = 4;
|
|
203
204
|
case 4: return [2 /*return*/];
|
|
204
205
|
}
|
|
205
206
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@receptron/graphai_vue_cytoscape",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
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"
|