Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions example_graphs/events.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"nodes": [
{
"id": "0",
"type": "constant",
"position": {
"x": 443.74999237060547,
"y": 132.24999809265137
},
"data": {
"label": "source",
"value": ""
},
"measured": {
"width": 205,
"height": 53
},
"selected": true
},
{
"id": "1",
"type": "integrator",
"position": {
"x": 688.7499923706055,
"y": 251.24999809265137
},
"data": {
"label": "integrator",
"initial_value": "",
"reset_times": ""
},
"measured": {
"width": 200,
"height": 48
},
"selected": false,
"dragging": false
},
{
"id": "2",
"type": "scope",
"position": {
"x": 1022.2499923706055,
"y": 252.24999809265137
},
"data": {
"label": "scope 2",
"labels": "",
"sampling_rate": "",
"t_wait": ""
},
"measured": {
"width": 120,
"height": 140
}
}
],
"edges": [
{
"id": "e0-1",
"source": "0",
"target": "1",
"sourceHandle": null,
"targetHandle": null,
"type": "smoothstep",
"data": {},
"style": {
"strokeWidth": 2,
"stroke": "#ECDFCC"
},
"markerEnd": {
"type": "arrowclosed",
"width": 20,
"height": 20,
"color": "#ECDFCC"
}
},
{
"id": "e0-2",
"source": "0",
"target": "2",
"sourceHandle": null,
"targetHandle": null,
"type": "smoothstep",
"data": {},
"style": {
"strokeWidth": 2,
"stroke": "#ECDFCC"
},
"markerEnd": {
"type": "arrowclosed",
"width": 20,
"height": 20,
"color": "#ECDFCC"
}
},
{
"id": "e1-2",
"source": "1",
"target": "2",
"sourceHandle": null,
"targetHandle": null,
"type": "smoothstep",
"data": {},
"style": {
"strokeWidth": 2,
"stroke": "#ECDFCC"
},
"markerEnd": {
"type": "arrowclosed",
"width": 20,
"height": 20,
"color": "#ECDFCC"
}
}
],
"nodeCounter": 3,
"solverParams": {
"dt": "0.01",
"dt_min": "1e-6",
"dt_max": "1.0",
"Solver": "SSPRK22",
"tolerance_fpi": "1e-6",
"iterations_max": "100",
"log": "true",
"simulation_duration": "50.0",
"extra_params": "{}"
},
"globalVariables": [],
"events": [
{
"name": "my_event",
"type": "ZeroCrossingDown",
"func_evt": "def func_evt(t):\n *_, x = integrator_1()\n return 10 - x",
"func_act": "def func_act(t):\n source_0.off()",
"tolerance": "1e-8",
"id": 1754342253698
}
]
}
34 changes: 29 additions & 5 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import NodeSidebar from './NodeSidebar';
import { DnDProvider, useDnD } from './DnDContext.jsx';
import ContextMenu from './ContextMenu.jsx';
import EventsTab from './EventsTab.jsx';
import { isValidPythonIdentifier } from './utils.js';
import { makeEdge } from './CustomEdge';
import { nodeTypes } from './nodeConfig.js';
Expand Down Expand Up @@ -57,7 +58,7 @@
}, []);

const onDragStart = (event, nodeType) => {
setType(nodeType);

Check failure on line 61 in src/App.jsx

View workflow job for this annotation

GitHub Actions / test (20.x, 3.10)

'setType' is not defined

Check failure on line 61 in src/App.jsx

View workflow job for this annotation

GitHub Actions / test (20.x, 3.11)

'setType' is not defined
event.dataTransfer.setData('text/plain', nodeType);
event.dataTransfer.effectAllowed = 'move';
};
Expand All @@ -78,6 +79,7 @@

// Global variables state
const [globalVariables, setGlobalVariables] = useState([]);
const [events, setEvents] = useState([]);
const [defaultValues, setDefaultValues] = useState({});
const [isEditingLabel, setIsEditingLabel] = useState(false);
const [tempLabel, setTempLabel] = useState('');
Expand Down Expand Up @@ -209,7 +211,7 @@
setNodes((nds) => [...nds, newNode]);
setNodeCounter((count) => count + 1);
},
[screenToFlowPosition, type, nodeCounter, fetchDefaultValues, setDefaultValues, setNodes, setNodeCounter],

Check warning on line 214 in src/App.jsx

View workflow job for this annotation

GitHub Actions / test (20.x, 3.10)

React Hook useCallback has an unnecessary dependency: 'setDefaultValues'. Either exclude it or remove the dependency array

Check warning on line 214 in src/App.jsx

View workflow job for this annotation

GitHub Actions / test (20.x, 3.11)

React Hook useCallback has an unnecessary dependency: 'setDefaultValues'. Either exclude it or remove the dependency array
);

// Function to save a graph to computer with "Save As" dialog
Expand All @@ -219,7 +221,8 @@
edges,
nodeCounter,
solverParams,
globalVariables
globalVariables,
events
};

// Check if File System Access API is supported
Expand Down Expand Up @@ -299,7 +302,7 @@
}

// Load the graph data
const { nodes: loadedNodes, edges: loadedEdges, nodeCounter: loadedNodeCounter, solverParams: loadedSolverParams, globalVariables: loadedGlobalVariables } = graphData;
const { nodes: loadedNodes, edges: loadedEdges, nodeCounter: loadedNodeCounter, solverParams: loadedSolverParams, globalVariables: loadedGlobalVariables, events: loadedEvents } = graphData;
setNodes(loadedNodes || []);
setEdges(loadedEdges || []);
setSelectedNode(null);
Expand All @@ -316,6 +319,7 @@
extra_params: '{}'
});
setGlobalVariables(loadedGlobalVariables ?? []);
setEvents(loadedEvents ?? []);

alert('Graph loaded successfully!');
} catch (error) {
Expand Down Expand Up @@ -350,7 +354,7 @@
return;
}

const { nodes: loadedNodes, edges: loadedEdges, nodeCounter: loadedNodeCounter, solverParams: loadedSolverParams, globalVariables: loadedGlobalVariables } = graphData;
const { nodes: loadedNodes, edges: loadedEdges, nodeCounter: loadedNodeCounter, solverParams: loadedSolverParams, globalVariables: loadedGlobalVariables, events: loadedEvents } = graphData;
setNodes(loadedNodes || []);
setEdges(loadedEdges || []);
setSelectedNode(null);
Expand All @@ -367,6 +371,7 @@
extra_params: '{}'
});
setGlobalVariables(loadedGlobalVariables ?? []);
setEvents(loadedEvents ?? []);

alert('Graph loaded successfully!');
} catch (error) {
Expand Down Expand Up @@ -463,7 +468,8 @@
edges,
nodeCounter,
solverParams,
globalVariables
globalVariables,
events
};

const response = await fetch(getApiEndpoint('/convert-to-python'), {
Expand Down Expand Up @@ -533,7 +539,8 @@
nodes,
edges,
solverParams,
globalVariables
globalVariables,
events
};

const response = await fetch(getApiEndpoint('/run-pathsim'), {
Expand Down Expand Up @@ -896,7 +903,7 @@
return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, [selectedEdge, selectedNode, copiedNode, duplicateNode, setCopyFeedback]);

Check warning on line 906 in src/App.jsx

View workflow job for this annotation

GitHub Actions / test (20.x, 3.10)

React Hook useEffect has missing dependencies: 'deleteSelectedEdge' and 'deleteSelectedNode'. Either include them or remove the dependency array

Check warning on line 906 in src/App.jsx

View workflow job for this annotation

GitHub Actions / test (20.x, 3.11)

React Hook useEffect has missing dependencies: 'deleteSelectedEdge' and 'deleteSelectedNode'. Either include them or remove the dependency array

return (
<div style={{ width: '100vw', height: '100vh', display: 'flex', flexDirection: 'column' }}>
Expand All @@ -923,6 +930,20 @@
>
Graph Editor
</button>
<button
style={{
padding: '10px 20px',
margin: '5px',
backgroundColor: activeTab === 'events' ? '#78A083' : '#444',
color: 'white',
border: 'none',
borderRadius: 5,
cursor: 'pointer',
}}
onClick={() => setActiveTab('events')}
>
Events
</button>
<button
style={{
padding: '10px 20px',
Expand Down Expand Up @@ -1272,6 +1293,9 @@
</div>
)}

{/* Events tab */}
{activeTab === 'events' && <EventsTab events={events} setEvents={setEvents} />}

{/* Solver Parameters Tab */}
{activeTab === 'solver' && (
<div style={{
Expand Down
Loading
Loading