diff --git a/functions/utilities/exportFigureGUI.m b/functions/utilities/exportFigureGUI.m index 2c68d55aef190c357381d5a7e51f0e69280730c4..44d69730882ffbbcccbeae0208f3ec5dae3b3dd7 100644 --- a/functions/utilities/exportFigureGUI.m +++ b/functions/utilities/exportFigureGUI.m @@ -113,7 +113,7 @@ figSelectionDropDown = uidropdown(fig, ... 'ValueChangedFcn', @(src, event) updatePreview()); % Automatically update preview if only one figure exists -if length(figHandles) == 1 +if isscalar(figHandles) updatePreview(); end @@ -142,7 +142,7 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ... figSelectionDropDown.Items = figNames; % Automatically update preview if only one valid figure exists - if length(figHandles) == 1 + if isscalar(figHandles) updatePreview(); end end @@ -166,7 +166,7 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ... end end - if isempty(selectedFig) && length(figHandles) == 1 + if isempty(selectedFig) && isscalar(figHandles) selectedFig = figHandles(1); end @@ -181,9 +181,41 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ... delete(findall(uiPanel, 'Type', 'axes')); % Copy the axes into the UI Panel - newAx = copyobj(obj.Children, uiPanel); + check = size(obj.Children); + if check(1) == 1 + newAx = copyobj(obj.Children, uiPanel); + hold(newAx, 'on'); + end + if check(1) == 2 % geoplots or 3d plots or tabfigures + if isa(obj.Children(1), 'matlab.ui.container.TabGroup') + numTabs = numel(obj.Children(1).Children); % Get number of tabs + originalFigNum = obj.Number; % Get the original figure number + + for i = 1:numTabs + newFigName = sprintf('Figure %d - Tab %d', originalFigNum, i); + newFig = figure('Name', newFigName, 'NumberTitle', 'off'); + + newAx = copyobj(obj.Children(1).Children(i).Children, newFig); + + set(newAx, 'Position', get(gca, 'Position')); + hold(newAx, 'on'); + end + else + newAx = copyobj(obj.Children(2), uiPanel); + hold(newAx, 'on'); + end + end + if check(1) > 2 + if isa(obj.Children(1), 'matlab.graphics.illustration.Legend') + newAx = copyobj(obj.Children(2:end), uiPanel); + hold(newAx(1:check(1)-1), 'on'); + else + newAx = copyobj(obj.Children, uiPanel); + hold(newAx, 'on'); + end + end %set(newAx, 'Position', [0.1, 0.1, 0.8, 0.8]); % Adjust position in panel - hold(newAx, 'on'); + %hold(newAx, 'on'); % Apply user settings linesInPlot = findall(newAx, 'Type', 'line'); @@ -222,7 +254,7 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ... satelliteMapColorsBox.ValueChangedFcn = @(src, event) updatePreview(); legendLocationDropDown.ValueChangedFcn = @(src, event) updatePreview(); legendOrientationDropDown.ValueChangedFcn = @(src, event) updatePreview(); - + hold(newAx, 'off'); end @@ -294,35 +326,39 @@ previewButton = uibutton(fig, 'Text', 'Update preview', ... overwriteFigure = overwriteFigureBox.Value; selectedIdx = figSelectionDropDown.Value; - figToExp = figHandles(strcmp(figSelectionDropDown.Items, selectedIdx)); - previewStandardizedFigure(figToExp, percTextwidth, ... - 'addMarkers', addMarkers, ... - 'forcedMarkers', forcedMarkers, ... - 'changeColors', changeColors, ... - 'changeLineStyle', changeLineStyle, ... - 'grid', gridOption, ... - 'legendLocation', legendLocation, ... - 'legendOrientation', legendOrientation, ... - 'exportPDF', exportPDF, ... - 'exportFIG', exportFIG, ... - 'satelliteMapColors', satelliteMapColors, ... - 'WHratio', WHratio, ... - 'overwriteFigure', overwriteFigure); + figToExp = figHandles(strcmp(figSelectionDropDown.Items, selectedIdx)); + previewStandardizedFigure(figToExp, percTextwidth, ... + 'addMarkers', addMarkers, ... + 'forcedMarkers', forcedMarkers, ... + 'changeColors', changeColors, ... + 'changeLineStyle', changeLineStyle, ... + 'grid', gridOption, ... + 'legendLocation', legendLocation, ... + 'legendOrientation', legendOrientation, ... + 'exportPDF', exportPDF, ... + 'exportFIG', exportFIG, ... + 'satelliteMapColors', satelliteMapColors, ... + 'WHratio', WHratio, ... + 'overwriteFigure', overwriteFigure); end -end +end - function figHandles = findFigures(fig) - figHandles = findall(0, 'Type', 'figure'); - figHandles(figHandles == fig) = []; % Exclude GUI figure - end +function figHandles = findFigures(fig) +figHandles = findall(0, 'Type', 'figure'); +figHandles(figHandles == fig) = []; % Exclude GUI figure +end - function figNames = getFigureNames(figHandles) - if isempty(figHandles) - figNames = {'No figures open'}; - else - figNames = arrayfun(@(f) sprintf('Figure %d', f.Number), figHandles, 'UniformOutput', false); - end +function figNames = getFigureNames(figHandles) + if isempty(figHandles) + figNames = {'No figures open'}; + else + figNames = arrayfun(@(f) sprintf('%s', f.Name), figHandles, 'UniformOutput', false); + % Replace empty names with "Figure #" + emptyNames = cellfun(@isempty, figNames); + figNames(emptyNames) = arrayfun(@(f) ... + sprintf('Figure %d', f.Number), figHandles(emptyNames), 'UniformOutput', false); end +end %% Further developments % File Path Input