@receptron/graphai_vue_cytoscape 0.0.1 → 0.0.2
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/lib/cytoscape.d.ts +7 -0
- package/lib/{cytoscope.js → cytoscape.js} +23 -23
- package/package.json +1 -1
- package/lib/cytoscope.d.ts +0 -7
|
@@ -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.
|
|
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"));
|
|
@@ -162,11 +162,11 @@ var cytoscapeFromGraph = function (graph_data) {
|
|
|
162
162
|
}, { nodes: [], edges: [], map: {} });
|
|
163
163
|
return { elements: elements };
|
|
164
164
|
};
|
|
165
|
-
var
|
|
165
|
+
var useCytoscape = function (selectedGraph) {
|
|
166
166
|
var cy = null;
|
|
167
|
-
var
|
|
168
|
-
var
|
|
169
|
-
var
|
|
167
|
+
var cytoscapeData = (0, vue_1.ref)(cytoscapeFromGraph(selectedGraph.value));
|
|
168
|
+
var cytoscapeRef = (0, vue_1.ref)();
|
|
169
|
+
var updateCytoscape = function (nodeId, state) { return __awaiter(void 0, void 0, void 0, function () {
|
|
170
170
|
var elements, graph, nodeData;
|
|
171
171
|
var _a;
|
|
172
172
|
return __generator(this, function (_b) {
|
|
@@ -178,7 +178,7 @@ var useCytoscope = function (selectedGraph) {
|
|
|
178
178
|
_b.sent();
|
|
179
179
|
_b.label = 2;
|
|
180
180
|
case 2:
|
|
181
|
-
elements =
|
|
181
|
+
elements = cytoscapeData.value.elements;
|
|
182
182
|
elements.map[nodeId].data.color = colorMap[state];
|
|
183
183
|
graph = selectedGraph.value;
|
|
184
184
|
nodeData = graph.nodes[nodeId];
|
|
@@ -192,22 +192,22 @@ var useCytoscope = function (selectedGraph) {
|
|
|
192
192
|
elements.map[nodeId].data.color = colorStatic;
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
-
|
|
195
|
+
cytoscapeData.value = { elements: elements };
|
|
196
196
|
if (!(state === graphai_1.NodeState.Injected)) return [3 /*break*/, 4];
|
|
197
197
|
return [4 /*yield*/, (0, graphai_1.sleep)(100)];
|
|
198
198
|
case 3:
|
|
199
199
|
_b.sent();
|
|
200
200
|
elements.map[nodeId].data.color = colorStatic;
|
|
201
|
-
|
|
201
|
+
cytoscapeData.value = { elements: elements };
|
|
202
202
|
_b.label = 4;
|
|
203
203
|
case 4: return [2 /*return*/];
|
|
204
204
|
}
|
|
205
205
|
});
|
|
206
206
|
}); };
|
|
207
|
-
var
|
|
207
|
+
var createCytoscape = function () {
|
|
208
208
|
try {
|
|
209
209
|
cy = (0, cytoscape_1.default)({
|
|
210
|
-
container:
|
|
210
|
+
container: cytoscapeRef.value,
|
|
211
211
|
style: cyStyle,
|
|
212
212
|
layout: {
|
|
213
213
|
name: layout,
|
|
@@ -235,8 +235,8 @@ var useCytoscope = function (selectedGraph) {
|
|
|
235
235
|
case 0:
|
|
236
236
|
if (!cy) return [3 /*break*/, 2];
|
|
237
237
|
cy.elements().remove();
|
|
238
|
-
cy.add(
|
|
239
|
-
name_1 =
|
|
238
|
+
cy.add(cytoscapeData.value.elements);
|
|
239
|
+
name_1 = cytoscapeData.value.elements.nodes.reduce(function (prevName, node) {
|
|
240
240
|
if (node.position) {
|
|
241
241
|
return "preset";
|
|
242
242
|
}
|
|
@@ -261,35 +261,35 @@ var useCytoscope = function (selectedGraph) {
|
|
|
261
261
|
cy.nodes().forEach(function (cynode) {
|
|
262
262
|
var id = cynode.id();
|
|
263
263
|
var pos = cynode.position();
|
|
264
|
-
var node =
|
|
264
|
+
var node = cytoscapeData.value.elements.map[id];
|
|
265
265
|
node.position = pos;
|
|
266
266
|
});
|
|
267
267
|
}
|
|
268
268
|
};
|
|
269
|
-
var
|
|
270
|
-
var elements =
|
|
269
|
+
var resetCytoscape = function () {
|
|
270
|
+
var elements = cytoscapeData.value.elements;
|
|
271
271
|
Object.keys(elements.map).forEach(function (nodeId) {
|
|
272
272
|
var graph = selectedGraph.value;
|
|
273
273
|
var nodeData = graph.nodes[nodeId];
|
|
274
274
|
elements.map[nodeId].data.color = "value" in nodeData ? colorStatic : colorMap[graphai_1.NodeState.Waiting];
|
|
275
275
|
});
|
|
276
|
-
|
|
276
|
+
cytoscapeData.value = { elements: elements };
|
|
277
277
|
};
|
|
278
|
-
(0, vue_1.watch)(
|
|
278
|
+
(0, vue_1.watch)(cytoscapeData, function () {
|
|
279
279
|
console.log("updated");
|
|
280
280
|
updateGraphData();
|
|
281
281
|
});
|
|
282
282
|
(0, vue_1.watch)(selectedGraph, function () {
|
|
283
|
-
|
|
283
|
+
cytoscapeData.value = cytoscapeFromGraph(selectedGraph.value);
|
|
284
284
|
});
|
|
285
285
|
(0, vue_1.onMounted)(function () {
|
|
286
|
-
|
|
286
|
+
createCytoscape();
|
|
287
287
|
updateGraphData();
|
|
288
288
|
});
|
|
289
289
|
return {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
290
|
+
cytoscapeRef: cytoscapeRef,
|
|
291
|
+
updateCytoscape: updateCytoscape,
|
|
292
|
+
resetCytoscape: resetCytoscape,
|
|
293
293
|
};
|
|
294
294
|
};
|
|
295
|
-
exports.
|
|
295
|
+
exports.useCytoscape = useCytoscape;
|
package/package.json
CHANGED
package/lib/cytoscope.d.ts
DELETED
|
@@ -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
|
-
};
|