Skip to content

Commit

Permalink
DQ Table now with color heatmap option
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
andrewxstewart committed Aug 5, 2020
1 parent f4f461b commit 6d05d1d
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
Binary file modified GUIs/DQ_Table_GUI.fig
Binary file not shown.
91 changes: 90 additions & 1 deletion GUIs/DQ_Table_GUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

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

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

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

table_data = ERP.dataquality(selected_DQ_type).data(:,:,selected_bin);
handles.dq_table.Data = table_data;
handles.orig_data = table_data;

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

handles.heatmap_on = 0;

% Update handles structure
handles.ERP = ERP;
Expand Down Expand Up @@ -204,6 +206,7 @@ function popupmenu_DQ_type_Callback(hObject, eventdata, handles)


handles.dq_table.Data = table_data;
handles.orig_data = table_data;

% Time-window labels
clear tw_labels
Expand All @@ -223,6 +226,13 @@ function popupmenu_DQ_type_Callback(hObject, eventdata, handles)
end
handles.dq_table.ColumnName = tw_labels;

if handles.heatmap_on
redraw_heatmap(hObject, eventdata, handles);
end
% Update handles structure
guidata(hObject, handles);



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


handles.dq_table.Data = table_data;
handles.orig_data = table_data;

if handles.heatmap_on
redraw_heatmap(hObject, eventdata, handles);
end

% Update handles structure
guidata(hObject, handles);


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

table_data = handles.ERP.dataquality(selected_DQ_type).data(:,:,selected_bin);
handles.dq_table.Data = table_data;
handles.orig_data = table_data;

% Time-window labels
clear tw_labels
Expand All @@ -315,6 +334,14 @@ function checkbox_text_labels_Callback(hObject, eventdata, handles)
end
handles.dq_table.ColumnName = tw_labels;

if handles.heatmap_on
redraw_heatmap(hObject, eventdata, handles);
end


% Update handles structure
guidata(hObject, handles);


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



% --- Executes on button press in pushbutton_mat.
function pushbutton_mat_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_mat (see GCBO)
Expand Down Expand Up @@ -361,3 +389,64 @@ function figure1_CloseRequestFcn(hObject, eventdata, handles)

% Hint: delete(hObject) closes the figure
delete(hObject);


% --- Executes on button press in checkbox_heatmap.
function checkbox_heatmap_Callback(hObject, eventdata, handles)
% hObject handle to checkbox_heatmap (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox_heatmap
heatmap_on = get(hObject,'Value');

if heatmap_on == 1
handles.heatmap_on = 1;
redraw_heatmap(hObject, eventdata, handles);

else
handles.heatmap_on = 0;
clear_heatmap(hObject, eventdata, handles);

end
% Update handles structure
guidata(hObject, handles);


function redraw_heatmap(hObject, eventdata, handles)

color_map = viridis;
data = handles.dq_table.Data;

data_min = min(data(:));
range_val = max(data(:)) - data_min;
range_colormap = size(color_map,1); % as in, 256 shades?
val_increase_per_shade = range_val / range_colormap;

% Use this @ anonymous function to make HTML tag in box in loop below
colergen = @(color,text) ['<html><table border=0 width=400 bgcolor=',color,'><TR><TD>',text,'</TD></TR> </table>'];


for cell = 1:numel(data)
data_here = data(cell);
shades_up_here = round((data_here - data_min) / val_increase_per_shade);
if shades_up_here < 1
shades_up_here = 1;
end
if shades_up_here > range_colormap
shades_up_here = range_colormap;
end
RGB_here = color_map(shades_up_here,:);
hex_color_here = ['#' dec2hex(round(255*RGB_here(1)),2) dec2hex(round(255*RGB_here(2)),2) dec2hex(round(255*RGB_here(3)),2)];
data2{cell} = colergen(hex_color_here,num2str(data_here));
end

data2 = reshape(data2,size(data));

handles.dq_table.Data = data2;



function clear_heatmap(hObject, eventdata, handles)
handles.dq_table.Data = handles.orig_data;

0 comments on commit 6d05d1d

Please sign in to comment.