Skip to content

Commit

Permalink
check nodes and edges before building graph in viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
mgonzs13 committed Nov 1, 2024
1 parent 91a50d6 commit 198e7e7
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"files": {
"main.css": "/static/css/main.073c9b0a.css",
"main.js": "/static/js/main.e97a8e28.js",
"main.js": "/static/js/main.3fc81ef6.js",
"static/js/787.d1eb2cfc.chunk.js": "/static/js/787.d1eb2cfc.chunk.js",
"index.html": "/index.html",
"main.073c9b0a.css.map": "/static/css/main.073c9b0a.css.map",
"main.e97a8e28.js.map": "/static/js/main.e97a8e28.js.map",
"main.3fc81ef6.js.map": "/static/js/main.3fc81ef6.js.map",
"787.d1eb2cfc.chunk.js.map": "/static/js/787.d1eb2cfc.chunk.js.map"
},
"entrypoints": [
"static/css/main.073c9b0a.css",
"static/js/main.e97a8e28.js"
"static/js/main.3fc81ef6.js"
]
}
2 changes: 1 addition & 1 deletion yasmin_viewer/yasmin_viewer_web_client/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>YASMIN Viewer</title><script defer="defer" src="/static/js/main.e97a8e28.js"></script><link href="/static/css/main.073c9b0a.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>YASMIN Viewer</title><script defer="defer" src="/static/js/main.3fc81ef6.js"></script><link href="/static/css/main.073c9b0a.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

112 changes: 81 additions & 31 deletions yasmin_viewer/yasmin_viewer_web_client/src/components/FSM.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Copyright (C) 2023 Miguel Ángel González Santamarta

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import React, { useEffect, useMemo, useRef } from "react";
import CytoscapeComponent from "react-cytoscapejs";
import cytoscape from "cytoscape";
Expand Down Expand Up @@ -242,45 +257,80 @@ const FSM = React.memo(({ fsm_data, alone, hide_nested_fsm }) => {
}
}

// Check nodes and edges
let node_names = nodes.map((n) => n.data.id);

for (const e of edges) {
if (
!node_names.includes(e.data.source) ||
!node_names.includes(e.data.target)
) {
return { nodes: undefined, edges: undefined };
}
}

return { nodes, edges };
};

return prepare_graph(fsm_data, hide_nested_fsm);
}, [fsm_data, hide_nested_fsm]);

return (
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<Grid container spacing={1}>
<Grid item xs={12}>
<Typography variant="h4" component="h4" gutterBottom align="center">
{fsm_data && fsm_data[0]?.name}
</Typography>
</Grid>
// If nodes are undefined, return an empty div
if (!nodes || !edges) {
return (
<Box
display="flex"
border={5}
justifyContent="center"
alignItems="center"
style={{ width: "100%", height: height }}
>
<Typography
variant="h4"
component="h4"
gutterBottom
align="center"
style={{ color: "red" }}
>
State machine {fsm_data[0].name} malformed
</Typography>
</Box>
);
} else {
return (
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<Grid container spacing={1}>
<Grid item xs={12}>
<Typography variant="h4" component="h4" gutterBottom align="center">
{fsm_data && fsm_data[0]?.name}
</Typography>
</Grid>

<Grid item xs={12}>
<Box
display="flex"
border={5}
justifyContent="center"
style={{ width: "100%", height: "100%" }}
>
<Graph
nodes={nodes}
edges={edges}
layout={layout}
height={height}
/>
</Box>
<Grid item xs={12}>
<Box
display="flex"
border={5}
justifyContent="center"
style={{ width: "100%", height: "100%" }}
>
<Graph
nodes={nodes}
edges={edges}
layout={layout}
height={height}
/>
</Box>
</Grid>
</Grid>
</Grid>
</div>
);
</div>
);
}
});

export default FSM;
15 changes: 15 additions & 0 deletions yasmin_viewer/yasmin_viewer_web_client/src/components/TopAppBar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Copyright (C) 2023 Miguel Ángel González Santamarta

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import * as React from "react";
import AppBar from "@mui/material/AppBar";
import Box from "@mui/material/Box";
Expand Down
15 changes: 15 additions & 0 deletions yasmin_viewer/yasmin_viewer_web_client/src/components/Viewer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Copyright (C) 2023 Miguel Ángel González Santamarta

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import React from "react";
import Grid from "@mui/material/Grid";
import FSM from "./FSM";
Expand Down

0 comments on commit 198e7e7

Please sign in to comment.