Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion +nla/+edge/+result/Base.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function output(obj, net_atlas, flags, prob_label)

fig = nla.gfx.createFigure();
matrix_plot = nla.gfx.plots.MatrixPlot(fig, coeff_label, obj.coeff, net_atlas.nets, nla.gfx.FigSize.LARGE, 'lower_limit', obj.coeff_range(1),...
'upper_limit', obj.coeff_range(2));
'upper_limit', obj.coeff_range(2), 'app_plot', false);
matrix_plot.displayImage();
w = matrix_plot.image_dimensions("image_width");
h = matrix_plot.image_dimensions("image_height");
Expand Down
60 changes: 51 additions & 9 deletions +nla/+gfx/+plots/MatrixPlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
current_settings % the settings for the plot (upper, lower, scale)
display_legend
p_value_max
app_plot % Used when called for FC Avg
end

properties (Dependent)
Expand Down Expand Up @@ -112,12 +113,13 @@
addParameter(matrix_input_parser, 'y_position', 0, validNumberInput);
addParameter(matrix_input_parser, 'discrete_colorbar', false, @islogical);
addParameter(matrix_input_parser, 'plot_scale', nla.gfx.ProbPlotMethod.DEFAULT);
addParameter(matrix_input_parser, 'p_value_max', 0.05)
addParameter(matrix_input_parser, 'p_value_max', 0.05);
addParameter(matrix_input_parser, 'app_plot', true, @islogical)

parse(matrix_input_parser, figure, name, matrix, networks, figure_size, varargin{:});
properties = {'figure', 'name', 'matrix', 'networks', 'figure_size', 'network_clicked_callback',...
'marked_networks', 'figure_margins', 'draw_legend', 'draw_colorbar', 'color_map', 'lower_limit',...
'upper_limit', 'x_position', 'y_position', 'discrete_colorbar', 'plot_scale', 'p_value_max'};
'upper_limit', 'x_position', 'y_position', 'discrete_colorbar', 'plot_scale', 'p_value_max', 'app_plot'};
for property = properties
obj.(property{1}) = matrix_input_parser.Results.(property{1});
if property{1} == "marked_networks"
Expand Down Expand Up @@ -182,6 +184,18 @@ function displayImage(obj)
'HorizontalAlignment', 'center');
end

if isequal(obj.app_plot, false)
settings_menu = uimenu(obj.figure, 'Text', 'Settings');
change_scale_option = uimenu(settings_menu,'Text','Change Scale');
change_scale_option.MenuSelectedFcn = {...
@obj.adjustScale, [obj.lower_limit, obj.upper_limit], obj.figure,...
struct('lower_bound', obj.lower_limit, 'upper_bound', obj.upper_limit, 'p_value_plot_max', obj.p_value_max),...
false...
};
change_color_map = uimenu(settings_menu, 'Text', 'Change Color Map');
change_color_map.MenuSelectedFcn = {@obj.adjustColor, obj.figure, struct('color_map', obj.color_map, 'color_map_name', ""), false};
end

obj.fixRendering();
hold(obj.axes, 'off') % This may have been turned on. Does nothing if it wasn't.

Expand All @@ -196,7 +210,7 @@ function applyScale(obj, ~, ~, upper_limit_box, lower_limit_box, old_scale, new_
obj.color_bar.Ticks = [];

color_map = color_map_select;
if ~isstring(color_map_select) && ~ischar(color_map_select)
if ~isstring(color_map_select) && ~ischar(color_map_select) && ~isequal(color_map, false)
color_map = get(color_map_select, "Value");
color_map = obj.colormap_choices{color_map};
end
Expand All @@ -207,13 +221,20 @@ function applyScale(obj, ~, ~, upper_limit_box, lower_limit_box, old_scale, new_
if isnumeric(upper_limit_box)
obj.upper_limit = upper_limit_box;
else
obj.upper_limit = get(upper_limit_box, "String");
obj.upper_limit = get(upper_limit_box, 'String');
end

if isnumeric(lower_limit_box)
obj.lower_limit = lower_limit_box;
else
obj.lower_limit = get(lower_limit_box, "String");
obj.lower_limit = get(lower_limit_box, 'String');
end

if isstring(obj.upper_limit) || ischar(obj.upper_limit)
obj.upper_limit = str2double(obj.upper_limit);
end
if isstring(obj.lower_limit) || ischar(obj.lower_limit)
obj.lower_limit = str2double(obj.lower_limit);
end

if ~isstring(obj.plot_scale)
Expand All @@ -239,7 +260,11 @@ function applyScale(obj, ~, ~, upper_limit_box, lower_limit_box, old_scale, new_
discrete_colors = NetworkResultPlotParameter().default_discrete_colors;

if new_scale == "nla.gfx.ProbPlotMethod.DEFAULT"
new_color_map = NetworkResultPlotParameter.getColormap(discrete_colors, obj.upper_limit, color_map);
if ~isequal(color_map, false)
new_color_map = NetworkResultPlotParameter.getColormap(discrete_colors, obj.upper_limit, color_map);
else
new_color_map = obj.color_map;
end
obj.plot_scale = new_scale;
elseif new_scale == "nla.gfx.ProbPlotMethod.LOG"
new_color_map = NetworkResultPlotParameter.getLogColormap(discrete_colors, obj.matrix, obj.upper_limit, color_map);
Expand Down Expand Up @@ -337,7 +362,7 @@ function removeLegend(obj)
image_height = image_height + 20;
end

% colorbar margins
% colorbar marginsobj
if obj.draw_colorbar
image_width = image_width + obj.colorbar_width + obj.colorbar_offset + obj.colorbar_text_w;
end
Expand Down Expand Up @@ -435,10 +460,10 @@ function addCallback(obj, x)
initial_render = false;
upper_value = varargin{2};
lower_value = varargin{1};
if isstring(upper_value)
if isstring(upper_value) || ischar(upper_value) % why are strings not chars???
upper_value = str2double(upper_value);
end
if isstring(lower_value)
if isstring(lower_value) || ischar(lower_value)
lower_value = str2double(lower_value);
end
end
Expand Down Expand Up @@ -677,5 +702,22 @@ function applyColorToData(obj, position_x, position_y, chunk_height, chunk_width
obj.image_display.CData(position_y:position_y + chunk_height - 1, position_x + chunk_width, :) =...
repelem(chunk_color(1:size(chunk_color, 1), size(chunk_color, 2), :), obj.elementSize(), 1);
end

function adjustScale(obj, src, ~, bounds, plot_figure, parameters, ~)
nla.gfx.scaleSelector(src, bounds, plot_figure, parameters, false, @obj.applyScaleWrapper);
end

function adjustColor(obj, src, ~, plot_figure, parameters, ~)
nla.gfx.colorSelector(src, plot_figure, parameters, false, @obj.applyScaleWrapper, obj.colormap_choices);
end

function applyScaleWrapper(obj, ~, ~, upper_limit_box, lower_limit_box, color_map, ~, ~, ~)
% This is used for the edge trimatrix, fc avg which is why we keep the ProbPlotMethod to DEFAULT
if isequal(upper_limit_box, false)
upper_limit_box = obj.upper_limit;
lower_limit_box = obj.lower_limit;
end
obj.applyScale(false, false, upper_limit_box, lower_limit_box, "nla.gfx.ProbPlotMethod.DEFAULT", "nla.gfx.ProbPlotMethod.DEFAULT", color_map)
end
end
end
46 changes: 46 additions & 0 deletions +nla/+gfx/colorSelector.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function colorSelector(src, plot_figure, plot_parameters, chord_type, callback_function, color_choices)
original_figure = src.Parent.Parent;
modal = figure('WindowStyle', 'normal', 'Units', 'pixels', 'Position',...
[original_figure.Position(1), original_figure.Position(2), original_figure.Position(3) / 2, original_figure.Position(4) / 3]);

% Color Map selector
% Adapted from colormap-dropdown: https://www.mathworks.com/matlabcentral/fileexchange/43659-colormap-dropdown-menu

color_map_select = uicontrol('Style', 'popupmenu',...
'Position', [90, 130, 275, 30], "Units", "pixels",...
'FontName', 'Courier');
uicontrol("Style", "text", "string", "Colormaps", "Units", "pixels",...
"Position", [color_map_select.Position(1) - 80, color_map_select.Position(2) - 2, 80, color_map_select.Position(4)]);
initial_colors = 16;
colormap_html = {};
for colors = 1:numel(color_choices)
colormap_function = str2func(strcat(strcat("@(x) ",lower(color_choices{colors})), "(x)"));
CData = colormap_function(initial_colors);
new_html_start = '<HTML> ';
new_html = '';
for color_iterator = initial_colors:-1:1
hex_code = nla.gfx.rgb2hex([CData(color_iterator, 1), CData(color_iterator, 2),...
CData(color_iterator, 3)]);
new_html = [new_html '<FONT bgcolor="' hex_code ' "color="' hex_code '">__</FONT>'];
end
new_html_end = [new_html ' </HTML>'];
new_html = [new_html_start new_html_end];
colormap_html = [colormap_html; new_html];
end

if ~isfield(parameters, "color_map_name")
parameters.color_map_name = 1;
end
set(color_map_select, "Value", parameters.color_map_name, "String", colormap_html);

apply_button_position = [10, 10, 100, 30];
apply_button = uicontrol('String', 'Apply',...
"Callback", {callback_function, false, false, color_map_select, plot_figure, parameters, chord_type},...
"Units", "pixels",...
'Position', apply_button_position);

close_button_position = [apply_button.Position(1) + apply_button.Position(3) + 10,...
apply_button.Position(2), apply_button.Position(3), apply_button.Position(4)];
uicontrol('String', 'Close', 'Callback', @(~, ~)close(modal), "Units", "pixels", 'Position',...
close_button_position);
end
28 changes: 28 additions & 0 deletions +nla/+gfx/scaleSelector.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function scaleSelector(src, bounds, plot_figure, parameters, chord_type, callback_function)
original_figure = src.Parent.Parent;
modal = figure('WindowStyle', 'normal', 'Units', 'pixels', 'Position',...
[original_figure.Position(1), original_figure.Position(2), original_figure.Position(3) / 3, original_figure.Position(4) / 3]);

upper_limit_box = uicontrol('Style', 'edit', "Units", "pixels", 'Position', [90, 130, 100, 30], "String",...
bounds(2));
upper_limit_box.Position(4) = upper_limit_box.FontSize * 2;
lower_limit_box = uicontrol('Style', 'edit', "Units", "pixels", 'Position', [90, 100, 100, 30], "String",...
bounds(1));
lower_limit_box.Position(4) = lower_limit_box.FontSize * 2;

uicontrol('Style', 'text', 'String', 'Upper Limit', "Units", "pixels", 'Position',...
[upper_limit_box.Position(1) - 80, upper_limit_box.Position(2) - 2, 80, upper_limit_box.Position(4)]);
uicontrol('Style', 'text', 'String', 'Lower Limit', "Units", "pixels", 'Position',...
[lower_limit_box.Position(1) - 80, lower_limit_box.Position(2) - 2, 80, lower_limit_box.Position(4)]);

apply_button_position = [10, 10, 100, 30];
apply_button = uicontrol('String', 'Apply',...
"Callback", {callback_function, upper_limit_box, lower_limit_box, false, plot_figure, parameters, chord_type},...
"Units", "pixels",...
'Position', apply_button_position);

close_button_position = [apply_button.Position(1) + apply_button.Position(3) + 10,...
apply_button.Position(2), apply_button.Position(3), apply_button.Position(4)];
uicontrol('String', 'Close', 'Callback', @(~, ~)close(modal), "Units", "pixels", 'Position',...
close_button_position);
end
3 changes: 2 additions & 1 deletion +nla/+inputField/NetworkAtlasFuncConn.m
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,9 @@ function buttonViewFCAvgClickedCallback(obj)
fc_avg = copy(obj.func_conn);
fc_avg.v = mean(fc_avg.v, 2);
fig_l = nla.gfx.createFigure();

matrix_plot = nla.gfx.plots.MatrixPlot(fig_l, 'FC Average (Fisher Z(R))', fc_avg, obj.net_atlas.nets,...
nla.gfx.FigSize.LARGE);
nla.gfx.FigSize.LARGE, "app_plot", false);
fig_l.Position(3) = matrix_plot.image_dimensions("image_width");
fig_l.Position(4) = matrix_plot.image_dimensions("image_height");
matrix_plot.displayImage();
Expand Down
Loading
Loading