diff --git a/src/Header/Headerdata.jsx b/src/Header/Headerdata.jsx
index a581ece..95687a4 100644
--- a/src/Header/Headerdata.jsx
+++ b/src/Header/Headerdata.jsx
@@ -7,7 +7,7 @@ class HeaderData extends React.Component{
Network Epidemic Playground
Continuous-time stochastic simulation of epidemic spreading on human-to-human contact networks
-
+
);
}
diff --git a/src/Simulation/Simulation.jsx b/src/Simulation/Simulation.jsx
index 4831dc6..bc7d7cb 100644
--- a/src/Simulation/Simulation.jsx
+++ b/src/Simulation/Simulation.jsx
@@ -31,17 +31,12 @@ class Simulation extends React.Component{
var states = selectedModel.getStates();
var initial_distribution = selectedModel.getDistribution();
- this.state = {rules: rules, states: states, initial_distribution: initial_distribution, graphData: graphData, horizon: 20.0, selectedNetwork: this.networkObject, selectedModel: this.modelObject, simulationData: undefined,};
+ //we have to run the simulation once in the beginning... sadly componentWillUnmount is deprecated
+ var newSimulationData = simulate(rules, states, initial_distribution, this.networkObject.getGraph(), 20.0);
+
+ this.state = {rules: rules, states: states, initial_distribution: initial_distribution, graphData: graphData, horizon: 20.0, selectedNetwork: this.networkObject, selectedModel: this.modelObject, simulationData: newSimulationData,};
}
- UNSAFE_componentWillMount() {
- this.recalculate();
- }
-
- //componentDidMount(){
- //this.recalculate();
- //}
-
horizonChange(e){
if(e.target.value > 200){
e.target.value = 200
diff --git a/src/Simulation/visualizations/Graph.jsx b/src/Simulation/visualizations/Graph.jsx
index bc1c499..e37c928 100644
--- a/src/Simulation/visualizations/Graph.jsx
+++ b/src/Simulation/visualizations/Graph.jsx
@@ -28,6 +28,7 @@ class Graph extends React.Component {
componentDidUpdate(prevProps, _) {
//only recalculate the layout if graph has changed
if (prevProps.graphData !== this.props.graphData) {
+ console.log("updated component => error");
this.layoutGraph();
this.setState({step: 0}, () => {
//first crop the animation
@@ -36,8 +37,10 @@ class Graph extends React.Component {
this.visualizeOneStep(false);
});
}
+ }
- //we could check here if the simulation should start displaying
+ componentWillUnmount() {
+ clearInterval(this.animationId);
}
//layouting algorithm
diff --git a/src/Simulation/visualizations/Visual.jsx b/src/Simulation/visualizations/Visual.jsx
index 01baeb5..492f2a9 100644
--- a/src/Simulation/visualizations/Visual.jsx
+++ b/src/Simulation/visualizations/Visual.jsx
@@ -9,12 +9,16 @@ class Visual extends React.Component {
this.cy = React.createRef();
this.stepTime = 0;
this.neverPlayed = true;
- this.state ={animationDuration: 4, step: 0, playing: false, animationLength: 100, newColors: null, currentView: "graph"};
+ this.state ={animationDuration: 4, step: 0, playing: false, animationLength: 100, cachedColors: this.props.colors, cachedSimulationData: this.props.simulationData, cachedGraphData: this.props.graphData, currentView: "graph"};
}
componentDidMount() {
this.cropAnimation();
- this.setState({newColors: this.props.colors});
+ this.setState({
+ cachedColors: this.props.colors,
+ cachedSimulationData: this.props.simulationData,
+ cachedGraphData: this.props.graphData
+ });
}
//remove steps where the animation does not change
@@ -43,8 +47,12 @@ class Visual extends React.Component {
this.props.recalculateFuntion().then(() => {
//now crop
this.cropAnimation();
- //update the colors for the chart
- this.setState({newColors: this.props.colors});
+ //we now update the cached data
+ this.setState({
+ cachedColors: this.props.colors,
+ cachedSimulationData: this.props.simulationData,
+ cachedGraphData: this.props.graphData
+ });
});
}
@@ -63,12 +71,12 @@ class Visual extends React.Component {
showGraphOrChart = () => {
if (this.state.currentView === "graph") {
return (
-
+
);
} else {
return (
-
+
);
}