Spaces:
Running
Running
Pass graph from backend to visualization.
Browse files- main.py +3 -1
- web/src/App.vue +1 -1
- web/src/components/GraphViz.vue +7 -10
main.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from typing import Union
|
2 |
import fastapi
|
3 |
import pydantic
|
|
|
4 |
|
5 |
class Position(pydantic.BaseModel):
|
6 |
x: float
|
@@ -45,4 +46,5 @@ def read_item(item_id: int, q: Union[str, None] = None):
|
|
45 |
@app.post("/api/save")
|
46 |
def save(ws: Workspace):
|
47 |
print(ws)
|
48 |
-
|
|
|
|
1 |
from typing import Union
|
2 |
import fastapi
|
3 |
import pydantic
|
4 |
+
import networkx as nx
|
5 |
|
6 |
class Position(pydantic.BaseModel):
|
7 |
x: float
|
|
|
46 |
@app.post("/api/save")
|
47 |
def save(ws: Workspace):
|
48 |
print(ws)
|
49 |
+
G = nx.scale_free_graph(100)
|
50 |
+
return {"graph": list(nx.to_edgelist(G))}
|
web/src/App.vue
CHANGED
@@ -49,7 +49,7 @@ function makeParam(param: string): NodeInterface {
|
|
49 |
|
50 |
function makeOutput(output: string): NodeInterface {
|
51 |
if (output === 'graph-viz') {
|
52 |
-
return new NodeInterface(output,
|
53 |
} else if (output === 'graph') {
|
54 |
return new BaklavaJS.NodeInterface(output, 0).use(setType, graphType);
|
55 |
} else if (output === 'table') {
|
|
|
49 |
|
50 |
function makeOutput(output: string): NodeInterface {
|
51 |
if (output === 'graph-viz') {
|
52 |
+
return new NodeInterface(output, "asd").setComponent(markRaw(GraphViz)).setPort(false);
|
53 |
} else if (output === 'graph') {
|
54 |
return new BaklavaJS.NodeInterface(output, 0).use(setType, graphType);
|
55 |
} else if (output === 'table') {
|
web/src/components/GraphViz.vue
CHANGED
@@ -3,20 +3,17 @@
|
|
3 |
</template>
|
4 |
|
5 |
<script setup>
|
6 |
-
import { ref, onMounted } from 'vue'
|
7 |
-
import Sigma from 'sigma'
|
8 |
-
import * as graphology from 'graphology'
|
9 |
-
const container = ref(null)
|
10 |
onMounted(() => {
|
11 |
const sigmaInstance = new Sigma(graph, container.value);
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
const graph = new graphology.Graph();
|
16 |
graph.addNode("1", { label: "Node 1", x: 0, y: 0, size: 10, color: "blue" });
|
17 |
graph.addNode("2", { label: "Node 2", x: 1, y: 1, size: 20, color: "red" });
|
18 |
graph.addEdge("1", "2", { size: 5, color: "purple" });
|
19 |
-
|
20 |
-
// Instantiate sigma.js and render the graph
|
21 |
-
|
22 |
</script>
|
|
|
3 |
</template>
|
4 |
|
5 |
<script setup>
|
6 |
+
import { ref, onMounted } from 'vue';
|
7 |
+
import Sigma from 'sigma';
|
8 |
+
import * as graphology from 'graphology';
|
9 |
+
const container = ref(null);
|
10 |
onMounted(() => {
|
11 |
const sigmaInstance = new Sigma(graph, container.value);
|
12 |
+
console.log(props.modelValue);
|
13 |
+
});
|
14 |
+
const props = defineProps(['modelValue']);
|
15 |
const graph = new graphology.Graph();
|
16 |
graph.addNode("1", { label: "Node 1", x: 0, y: 0, size: 10, color: "blue" });
|
17 |
graph.addNode("2", { label: "Node 2", x: 1, y: 1, size: 20, color: "red" });
|
18 |
graph.addEdge("1", "2", { size: 5, color: "purple" });
|
|
|
|
|
|
|
19 |
</script>
|