diff --git a/src/components/widget-plot-table.js b/src/components/widget-plot-table.js
index cbdee75..65de31e 100644
--- a/src/components/widget-plot-table.js
+++ b/src/components/widget-plot-table.js
@@ -58,22 +58,27 @@ class WidgetPlotTable extends Component {
return (model.simulator === simulator);
});
- // Create checkboxes using the signal indices from simulation model
- const preselectedSignals = simulationModel.mapping.reduce(
- // Loop through simulation model signals
- (accum, model_signal, signal_index) => {
- // Append them if they belong to the current selected type
- if (nextProps.widget.preselectedSignals.indexOf(signal_index) > -1) {
- accum.push(
- {
- index: signal_index,
- name: model_signal.name
- }
- )
- }
- return accum;
- }, []);
- this.setState({ preselectedSignals: preselectedSignals });
+ let preselectedSignals = [];
+ // Proceed if a simulation model is available
+ if (simulationModel) {
+ // Create checkboxes using the signal indices from simulation model
+ preselectedSignals = simulationModel.mapping.reduce(
+ // Loop through simulation model signals
+ (accum, model_signal, signal_index) => {
+ // Append them if they belong to the current selected type
+ if (nextProps.widget.preselectedSignals.indexOf(signal_index) > -1) {
+ accum.push(
+ {
+ index: signal_index,
+ name: model_signal.name
+ }
+ )
+ }
+ return accum;
+ }, []);
+ }
+
+ this.setState({ preselectedSignals: preselectedSignals });
}
updateSignalSelection(signal_index, checked) {
diff --git a/src/components/widget-plot.js b/src/components/widget-plot.js
index df901c9..e0c2662 100644
--- a/src/components/widget-plot.js
+++ b/src/components/widget-plot.js
@@ -15,25 +15,29 @@ import PlotLegend from './widget-plot/plot-legend';
class WidgetPlot extends Component {
render() {
- if (this.props.simulation == null) {
- return (
Empty
);
+
+ const simulator = this.props.widget.simulator;
+ const simulation = this.props.simulation;
+ let legendSignals = [];
+ let simulatorData = [];
+
+ // Proceed if a simulation with models and a simulator are available
+ if (simulator && simulation && simulation.models.length > 0) {
+
+ const model = simulation.models.find( (model) => model.simulator === simulator );
+ const chosenSignals = this.props.widget.signals;
+
+ simulatorData = this.props.data[simulator];
+
+ // Query the signals that will be displayed in the legend
+ legendSignals = model.mapping.reduce( (accum, model_signal, signal_index) => {
+ if (chosenSignals.includes(signal_index)) {
+ accum.push({ index: signal_index, name: model_signal.name });
+ }
+ return accum;
+ }, []);
}
- let simulator = this.props.widget.simulator;
- let simulation = this.props.simulation;
- let model = simulation.models.find( (model) => model.simulator === simulator );
- let chosenSignals = this.props.widget.signals;
-
- let simulatorData = this.props.data[simulator];
-
- // Query the signals that will be displayed in the legend
- let legendSignals = model.mapping.reduce( (accum, model_signal, signal_index) => {
- if (chosenSignals.includes(signal_index)) {
- accum.push({ index: signal_index, name: model_signal.name });
- }
- return accum;
- }, []);
-
return (
{this.props.widget.name}
diff --git a/src/containers/visualization.js b/src/containers/visualization.js
index 6085b06..c82d56d 100644
--- a/src/containers/visualization.js
+++ b/src/containers/visualization.js
@@ -22,6 +22,8 @@ import ProjectStore from '../stores/project-store';
import SimulationStore from '../stores/simulation-store';
import FileStore from '../stores/file-store';
import AppDispatcher from '../app-dispatcher';
+import NotificationsDataManager from '../data-managers/notifications-data-manager';
+import NotificationsFactory from '../data-managers/notifications-factory';
import WidgetSlider from '../components/widget-slider';
@@ -138,16 +140,24 @@ class Visualization extends Component {
z: 0
};
+ let defaultSimulator = null;
+
+ if (this.state.simulation.models && this.state.simulation.models.length === 0) {
+ NotificationsDataManager.addNotification(NotificationsFactory.NO_SIM_MODEL_AVAILABLE);
+ } else {
+ defaultSimulator = this.state.simulation.models[0].simulator;
+ }
+
// set type specific properties
if (item.name === 'Value') {
- widget.simulator = this.state.simulation.models[0].simulator;
+ widget.simulator = defaultSimulator;
widget.signal = 0;
widget.minWidth = 70;
widget.minHeight = 20;
widget.width = 120;
widget.height = 70;
} else if (item.name === 'Plot') {
- widget.simulator = this.state.simulation.models[0].simulator;
+ widget.simulator = defaultSimulator;
widget.signals = [ 0 ];
widget.time = 60;
widget.minWidth = 400;
@@ -155,7 +165,7 @@ class Visualization extends Component {
widget.width = 400;
widget.height = 200;
} else if (item.name === 'Table') {
- widget.simulator = this.state.simulation.models[0].simulator;
+ widget.simulator = defaultSimulator;
widget.minWidth = 300;
widget.minHeight = 200;
widget.width = 400;
@@ -164,7 +174,7 @@ class Visualization extends Component {
widget.minWidth = 70;
widget.minHeight = 20;
} else if (item.name === 'PlotTable') {
- widget.simulator = this.state.simulation.models[0].simulator;
+ widget.simulator = defaultSimulator;
widget.preselectedSignals = [];
widget.signals = []; // initialize selected signals
widget.minWidth = 400;
@@ -194,7 +204,7 @@ class Visualization extends Component {
widget.height = 50;
widget.orientation = WidgetSlider.OrientationTypes.HORIZONTAL.value; // Assign default orientation
} else if (item.name === 'Gauge') {
- widget.simulator = this.state.simulation.models[0].simulator;
+ widget.simulator = defaultSimulator;
widget.signal = 0;
widget.minWidth = 200;
widget.minHeight = 150;
diff --git a/src/data-managers/notifications-factory.js b/src/data-managers/notifications-factory.js
new file mode 100644
index 0000000..56c095c
--- /dev/null
+++ b/src/data-managers/notifications-factory.js
@@ -0,0 +1,24 @@
+/**
+ * File: notifications-factory.js
+ * Description: An unique source of pre-defined notifications that are displayed
+ * throughout the application.
+ * Author: Ricardo Hernandez-Montoya
+ * Date: 13.04.2017
+ * Copyright: 2017, Institute for Automation of Complex Power Systems, EONERC
+ * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential.
+ * Unauthorized copying of this file, via any medium is strictly prohibited.
+ **********************************************************************************/
+
+class NotificationsFactory {
+
+ static get NO_SIM_MODEL_AVAILABLE() {
+ return {
+ title: 'No simulation model available',
+ message: 'Consider defining a simulation model in the simulators section.',
+ level: 'warning'
+ };
+ }
+
+}
+
+export default NotificationsFactory;
\ No newline at end of file