Skip to content

Commit 6d05d1d

Browse files
DQ Table now with color heatmap option
We now have an option for a color heatmap in the Data Quality table. See: ![DQ_Table_with_COLOR](https://user-images.githubusercontent.com/5137405/89411723-ba000700-d6da-11ea-81a4-be56c5e705e7.png)
1 parent f4f461b commit 6d05d1d

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

GUIs/DQ_Table_GUI.fig

858 Bytes
Binary file not shown.

GUIs/DQ_Table_GUI.m

+90-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
% Edit the above text to modify the response to pushbutton_help DQ_Table_GUI
2424

25-
% Last Modified by GUIDE v2.5 15-Oct-2019 17:13:28
25+
% Last Modified by GUIDE v2.5 05-Aug-2020 04:05:17
2626

2727
% Begin initialization code - DO NOT EDIT
2828
gui_Singleton = 1;
@@ -112,6 +112,7 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
112112

113113
table_data = ERP.dataquality(selected_DQ_type).data(:,:,selected_bin);
114114
handles.dq_table.Data = table_data;
115+
handles.orig_data = table_data;
115116

116117
% electrode labels from ERPset, iff present and number matches
117118
if isfield(ERP.chanlocs,'labels') && numel(ERP.chanlocs) == n_elec
@@ -145,6 +146,7 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
145146
desired_fontsize = erpworkingmemory('fontsizeGUI');
146147
handles.dq_table.FontSize = desired_fontsize;
147148

149+
handles.heatmap_on = 0;
148150

149151
% Update handles structure
150152
handles.ERP = ERP;
@@ -204,6 +206,7 @@ function popupmenu_DQ_type_Callback(hObject, eventdata, handles)
204206

205207

206208
handles.dq_table.Data = table_data;
209+
handles.orig_data = table_data;
207210

208211
% Time-window labels
209212
clear tw_labels
@@ -223,6 +226,13 @@ function popupmenu_DQ_type_Callback(hObject, eventdata, handles)
223226
end
224227
handles.dq_table.ColumnName = tw_labels;
225228

229+
if handles.heatmap_on
230+
redraw_heatmap(hObject, eventdata, handles);
231+
end
232+
% Update handles structure
233+
guidata(hObject, handles);
234+
235+
226236

227237
% --- Executes during object creation, after setting all properties.
228238
function popupmenu_DQ_type_CreateFcn(hObject, eventdata, handles)
@@ -269,6 +279,14 @@ function popupmenu_bin_Callback(hObject, eventdata, handles)
269279

270280

271281
handles.dq_table.Data = table_data;
282+
handles.orig_data = table_data;
283+
284+
if handles.heatmap_on
285+
redraw_heatmap(hObject, eventdata, handles);
286+
end
287+
288+
% Update handles structure
289+
guidata(hObject, handles);
272290

273291

274292
% --- Executes during object creation, after setting all properties.
@@ -296,6 +314,7 @@ function checkbox_text_labels_Callback(hObject, eventdata, handles)
296314

297315
table_data = handles.ERP.dataquality(selected_DQ_type).data(:,:,selected_bin);
298316
handles.dq_table.Data = table_data;
317+
handles.orig_data = table_data;
299318

300319
% Time-window labels
301320
clear tw_labels
@@ -315,6 +334,14 @@ function checkbox_text_labels_Callback(hObject, eventdata, handles)
315334
end
316335
handles.dq_table.ColumnName = tw_labels;
317336

337+
if handles.heatmap_on
338+
redraw_heatmap(hObject, eventdata, handles);
339+
end
340+
341+
342+
% Update handles structure
343+
guidata(hObject, handles);
344+
318345

319346
% --- Executes on button press in pushbutton_xls.
320347
function pushbutton_xls_Callback(hObject, eventdata, handles)
@@ -326,6 +353,7 @@ function pushbutton_xls_Callback(hObject, eventdata, handles)
326353
save_data_quality(handles.ERP,empty_filename,'xls',selected_DQ_type)
327354

328355

356+
329357
% --- Executes on button press in pushbutton_mat.
330358
function pushbutton_mat_Callback(hObject, eventdata, handles)
331359
% hObject handle to pushbutton_mat (see GCBO)
@@ -361,3 +389,64 @@ function figure1_CloseRequestFcn(hObject, eventdata, handles)
361389

362390
% Hint: delete(hObject) closes the figure
363391
delete(hObject);
392+
393+
394+
% --- Executes on button press in checkbox_heatmap.
395+
function checkbox_heatmap_Callback(hObject, eventdata, handles)
396+
% hObject handle to checkbox_heatmap (see GCBO)
397+
% eventdata reserved - to be defined in a future version of MATLAB
398+
% handles structure with handles and user data (see GUIDATA)
399+
400+
% Hint: get(hObject,'Value') returns toggle state of checkbox_heatmap
401+
heatmap_on = get(hObject,'Value');
402+
403+
if heatmap_on == 1
404+
handles.heatmap_on = 1;
405+
redraw_heatmap(hObject, eventdata, handles);
406+
407+
else
408+
handles.heatmap_on = 0;
409+
clear_heatmap(hObject, eventdata, handles);
410+
411+
end
412+
% Update handles structure
413+
guidata(hObject, handles);
414+
415+
416+
function redraw_heatmap(hObject, eventdata, handles)
417+
418+
color_map = viridis;
419+
data = handles.dq_table.Data;
420+
421+
data_min = min(data(:));
422+
range_val = max(data(:)) - data_min;
423+
range_colormap = size(color_map,1); % as in, 256 shades?
424+
val_increase_per_shade = range_val / range_colormap;
425+
426+
% Use this @ anonymous function to make HTML tag in box in loop below
427+
colergen = @(color,text) ['<html><table border=0 width=400 bgcolor=',color,'><TR><TD>',text,'</TD></TR> </table>'];
428+
429+
430+
for cell = 1:numel(data)
431+
data_here = data(cell);
432+
shades_up_here = round((data_here - data_min) / val_increase_per_shade);
433+
if shades_up_here < 1
434+
shades_up_here = 1;
435+
end
436+
if shades_up_here > range_colormap
437+
shades_up_here = range_colormap;
438+
end
439+
RGB_here = color_map(shades_up_here,:);
440+
hex_color_here = ['#' dec2hex(round(255*RGB_here(1)),2) dec2hex(round(255*RGB_here(2)),2) dec2hex(round(255*RGB_here(3)),2)];
441+
data2{cell} = colergen(hex_color_here,num2str(data_here));
442+
end
443+
444+
data2 = reshape(data2,size(data));
445+
446+
handles.dq_table.Data = data2;
447+
448+
449+
450+
function clear_heatmap(hObject, eventdata, handles)
451+
handles.dq_table.Data = handles.orig_data;
452+

0 commit comments

Comments
 (0)