Skip to content

Commit 72b9dcc

Browse files
author
Lucas Rebscher
committed
#215 Enable plot widgets depending on availability
1 parent 1b06749 commit 72b9dcc

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

webapp/constants.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export const PLOT_WIDGETS = {
118118
hideOnClose: true,
119119
enableRename: false,
120120
initialized: false,
121+
disabled: true,
121122
method: {
122123
plotKey: 'plotTraces',
123124
plotMethod: 'iplotTraces',
@@ -135,6 +136,7 @@ export const PLOT_WIDGETS = {
135136
enableRename: false,
136137
hideOnClose: true,
137138
initialized: false,
139+
disabled: true,
138140
method: {
139141
plotKey: 'plotRaster',
140142
plotMethod: 'iplotRaster',
@@ -152,6 +154,7 @@ export const PLOT_WIDGETS = {
152154
enableRename: false,
153155
hideOnClose: true,
154156
initialized: false,
157+
disabled: true,
155158
method: {
156159
plotKey: 'plotSpikeHist',
157160
plotMethod: 'iplotSpikeHist',
@@ -169,6 +172,7 @@ export const PLOT_WIDGETS = {
169172
hideOnClose: true,
170173
enableRename: false,
171174
initialized: false,
175+
disabled: true,
172176
method: {
173177
key: 'plotSpikeStats',
174178
plotMethod: 'iplotSpikeStats',
@@ -186,6 +190,7 @@ export const PLOT_WIDGETS = {
186190
enableRename: false,
187191
hideOnClose: true,
188192
initialized: false,
193+
disabled: true,
189194
method: {
190195
key: 'plotRatePSD',
191196
plotMethod: 'iplotRatePSD',
@@ -203,6 +208,7 @@ export const PLOT_WIDGETS = {
203208
enableRename: false,
204209
hideOnClose: true,
205210
initialized: false,
211+
disabled: true,
206212
method: {
207213
plotKey: 'plotLFP',
208214
plotMethod: 'iplotLFP',
@@ -220,6 +226,7 @@ export const PLOT_WIDGETS = {
220226
hideOnClose: true,
221227
enableRename: false,
222228
initialized: false,
229+
disabled: true,
223230
method: {
224231
plotKey: 'plotLFP',
225232
plotMethod: 'iplotLFP',
@@ -237,6 +244,7 @@ export const PLOT_WIDGETS = {
237244
enableRename: false,
238245
hideOnClose: true,
239246
initialized: false,
247+
disabled: true,
240248
method: {
241249
plotKey: 'plotLFP',
242250
plotMethod: 'iplotLFP',
@@ -254,6 +262,7 @@ export const PLOT_WIDGETS = {
254262
defaultPanel: 'plotPanel',
255263
enableRename: false,
256264
initialized: false,
265+
disabled: true,
257266
method: {
258267
plotKey: 'granger',
259268
plotMethod: 'granger',
@@ -271,6 +280,7 @@ export const PLOT_WIDGETS = {
271280
hideOnClose: true,
272281
enableRename: false,
273282
initialized: false,
283+
disabled: true,
274284
method: {
275285
plotKey: 'plotRxDConcentration',
276286
plotMethod: 'iplotRxDConcentration',

webapp/redux/middleware/plotMiddleware.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
// and ensured that plot data doesn't lead to performance issues due to possible deep-copy in reducers.
1717
window.plotCache = {};
1818

19+
const isDisabled = (widget, plots) => !plots[widget.method.plotKey] ?? true;
20+
1921
export default (store) => (next) => (action) => {
2022
async function setWidget (widget) {
2123
const {
@@ -28,11 +30,9 @@ export default (store) => (next) => (action) => {
2830
widget.initialized = true;
2931
if (data) {
3032
console.debug('Plot retrieved:', widget.id);
31-
widget.disabled = false;
3233
return widget;
3334
}
3435
console.warn('Plot not retrieved:', widget.id);
35-
widget.disabled = true;
3636
return widget;
3737
});
3838
}
@@ -54,37 +54,37 @@ export default (store) => (next) => (action) => {
5454
case SET_WIDGETS: {
5555
// This is triggered once when we change the layout from Edit > Explore.
5656
// We add the widgets (back) to the sidebar but without fetching any data.
57-
for (const widget of Object.values(action.data)) {
58-
if (widget.id in PLOT_WIDGETS) {
59-
next(addWidget(widget));
60-
}
61-
}
57+
Object.values(action.data)
58+
.filter((widget) => widget.id in PLOT_WIDGETS)
59+
.forEach((widget) => next(addWidget(widget)));
6260
next(action);
6361
break;
6462
}
6563
case CREATE_NETWORK: {
66-
// Reset network plots
67-
for (const widget of Object.values(NETWORK_PLOT_WIDGETS)) {
68-
delete window.plotCache[widget.id];
69-
widget.initialized = false;
70-
next(addWidget(widget));
71-
}
64+
Utils.evalPythonMessage(NETPYNE_COMMANDS.checkAvailablePlots, [])
65+
.then((plots) => {
66+
// Only reset network plots
67+
Object.values(NETWORK_PLOT_WIDGETS)
68+
.forEach((widget) => {
69+
delete window.plotCache[widget.id];
70+
widget.initialized = false;
71+
widget.disabled = isDisabled(widget, plots);
72+
next(addWidget(widget));
73+
});
74+
});
75+
7276
next(action);
7377
break;
7478
}
7579
case SIMULATE_NETWORK:
7680
case CREATE_SIMULATE_NETWORK: {
77-
window.plotCache = {};
78-
7981
Utils.evalPythonMessage(NETPYNE_COMMANDS.checkAvailablePlots, [])
8082
.then((plots) => {
83+
window.plotCache = {};
8184
Object.values(PLOT_WIDGETS)
8285
.forEach((widget) => {
8386
widget.initialized = false;
84-
widget.disabled = true;
85-
if (widget.method.plotKey in plots) {
86-
widget.disabled = !plots[widget.method.plotKey];
87-
}
87+
widget.disabled = isDisabled(widget, plots);
8888
next(addWidget(widget));
8989
});
9090
});

0 commit comments

Comments
 (0)