Spaces:
Running
Running
Typed inputs/outputs.
Browse files- web/src/App.vue +23 -5
- web/src/style.css +4 -0
web/src/App.vue
CHANGED
@@ -17,12 +17,16 @@
|
|
17 |
|
18 |
<script setup lang="ts">
|
19 |
import { BaklavaEditor, useBaklava } from "@baklavajs/renderer-vue";
|
|
|
20 |
import * as BaklavaJS from "baklavajs";
|
21 |
import "@baklavajs/themes/dist/syrup-dark.css";
|
22 |
import { markRaw } from "vue";
|
23 |
import { NodeInterface } from "baklavajs";
|
24 |
import GraphViz from "./components/GraphViz.vue";
|
25 |
|
|
|
|
|
|
|
26 |
const ops = [
|
27 |
{ name: 'Create scale-free graph', type: 'Creation', inputs: [], outputs: ['graph'], params: ['Number of nodes'] },
|
28 |
{ name: 'Compute PageRank', type: 'Algorithms', inputs: ['graph'], outputs: ['graph'], params: ['Damping factor', 'Max iterations'] },
|
@@ -40,26 +44,40 @@ const ops = [
|
|
40 |
];
|
41 |
|
42 |
function makeParam(param: string): NodeInterface {
|
43 |
-
return new BaklavaJS.TextInputInterface(param).setPort(false);
|
44 |
}
|
45 |
|
46 |
function makeOutput(output: string): NodeInterface {
|
47 |
if (output === 'graph-viz') {
|
48 |
return new NodeInterface(output, 0).setComponent(markRaw(GraphViz)).setPort(false);
|
49 |
-
} else if (output === '
|
50 |
-
return new BaklavaJS.
|
|
|
|
|
51 |
} else {
|
52 |
return new BaklavaJS.NodeInterface(output, 0);
|
53 |
}
|
54 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
const baklava = useBaklava();
|
|
|
|
|
|
|
57 |
for (const op of ops) {
|
58 |
baklava.editor.registerNodeType(BaklavaJS.defineNode({
|
59 |
type: op.name,
|
60 |
inputs: {
|
61 |
-
...op.inputs.reduce((acc, input) => ({ ...acc, [input]: () =>
|
62 |
-
...op.params.reduce((acc, param) => ({ ...acc, [param]: () => makeParam(param)}), {}),
|
63 |
},
|
64 |
outputs: op.outputs.reduce((acc, output) => ({ ...acc, [output]: () => makeOutput(output) }), {}),
|
65 |
calculate: op.calculate,
|
|
|
17 |
|
18 |
<script setup lang="ts">
|
19 |
import { BaklavaEditor, useBaklava } from "@baklavajs/renderer-vue";
|
20 |
+
import { BaklavaInterfaceTypes, NodeInterfaceType, setType } from "@baklavajs/interface-types";
|
21 |
import * as BaklavaJS from "baklavajs";
|
22 |
import "@baklavajs/themes/dist/syrup-dark.css";
|
23 |
import { markRaw } from "vue";
|
24 |
import { NodeInterface } from "baklavajs";
|
25 |
import GraphViz from "./components/GraphViz.vue";
|
26 |
|
27 |
+
const graphType = new NodeInterfaceType<string>("graph");
|
28 |
+
const tableType = new NodeInterfaceType<string>("table");
|
29 |
+
|
30 |
const ops = [
|
31 |
{ name: 'Create scale-free graph', type: 'Creation', inputs: [], outputs: ['graph'], params: ['Number of nodes'] },
|
32 |
{ name: 'Compute PageRank', type: 'Algorithms', inputs: ['graph'], outputs: ['graph'], params: ['Damping factor', 'Max iterations'] },
|
|
|
44 |
];
|
45 |
|
46 |
function makeParam(param: string): NodeInterface {
|
47 |
+
return new BaklavaJS.TextInputInterface(param, "").setPort(false);
|
48 |
}
|
49 |
|
50 |
function makeOutput(output: string): NodeInterface {
|
51 |
if (output === 'graph-viz') {
|
52 |
return new NodeInterface(output, 0).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') {
|
56 |
+
return new BaklavaJS.NodeInterface(output, 0).use(setType, tableType);
|
57 |
} else {
|
58 |
return new BaklavaJS.NodeInterface(output, 0);
|
59 |
}
|
60 |
}
|
61 |
+
function makeInput(input: string): NodeInterface {
|
62 |
+
if (input === 'graph') {
|
63 |
+
return new BaklavaJS.NodeInterface(input, 0).use(setType, graphType);
|
64 |
+
} else if (input === 'table') {
|
65 |
+
return new BaklavaJS.NodeInterface(input, 0).use(setType, tableType);
|
66 |
+
} else {
|
67 |
+
return new BaklavaJS.NodeInterface(input, 0);
|
68 |
+
}
|
69 |
+
}
|
70 |
|
71 |
const baklava = useBaklava();
|
72 |
+
const nodeInterfaceTypes = new BaklavaInterfaceTypes(baklava.editor, { viewPlugin: baklava });
|
73 |
+
nodeInterfaceTypes.addTypes(graphType, tableType);
|
74 |
+
|
75 |
for (const op of ops) {
|
76 |
baklava.editor.registerNodeType(BaklavaJS.defineNode({
|
77 |
type: op.name,
|
78 |
inputs: {
|
79 |
+
...op.inputs.reduce((acc, input) => ({ ...acc, [input]: () => makeInput(input) }), {}),
|
80 |
+
...op.params.reduce((acc, param) => ({ ...acc, [param]: () => makeParam(param) }), {}),
|
81 |
},
|
82 |
outputs: op.outputs.reduce((acc, output) => ({ ...acc, [output]: () => makeOutput(output) }), {}),
|
83 |
calculate: op.calculate,
|
web/src/style.css
CHANGED
@@ -8,3 +8,7 @@ body {
|
|
8 |
background: white;
|
9 |
text-align: left;
|
10 |
}
|
|
|
|
|
|
|
|
|
|
8 |
background: white;
|
9 |
text-align: left;
|
10 |
}
|
11 |
+
|
12 |
+
.baklava-node-interface[data-interface-type="graph"] .__port {
|
13 |
+
background-color: #39bcf3;
|
14 |
+
}
|