Skip to content
Snippets Groups Projects
Commit bd3d59df authored by Lemmer, Jan's avatar Lemmer, Jan
Browse files

Fixes #21, Fixes Error when trying to export the same ID again

parent ae012aaf
Branches
Tags
3 merge requests!13PreRelease_V0.1,!12PreRelease_V0.1,!3Fixes #21, Fixes Error when trying to export the same ID again
......@@ -5,6 +5,12 @@ function [result] = default_test()
clear; clc; close all;
addpath('./fcn_core','./fcn_help');
% clean up, if previous run failed
try
delete CI_files/export/* CI_files/*.mat CI_files/*.h5
rmdir('CI_files/export','s');
end
ProjectID = 'Test01';
%% Data
% some random data
......
......@@ -55,33 +55,55 @@ a = example_fcn(a);
% Make sure to save each figure in a variable to pass to PlotID-functions.
fig(1) = figure;
plot(x,y,'-k');
box off
set(gca, 'TickDir', 'out', 'YLim', [0,4]);
hold on
%fig(2) = figure;
box off; hold on;
plot(x1,y1,'-r');
set(gca, 'TickDir', 'out', 'YLim', [0,4]);
%% Example 1: single plot based on two data-sets
%% Tag the plot
% PlotID Implementation starts here.
% TagPlot adds a visible ID to the figure and to the property fig.Tag
[figs, ID] = TagPlot(fig, ProjectID);
% TagPlot adds a visible ID to the figure(s) and to the figures property
% 'Tag'
[fig, ID] = TagPlot(fig, ProjectID);
%% Publishing
% Second part of plotID
% The functions needs the file location, the location of the data and the
% figure and can take several options.
% TODO add explanations for Options
path.script = mfilename('fullpath'); % filename of the m.script
% file name of the dataset
path.script = mfilename('fullpath'); % filename of the m.script
% file names of the datasets
path.rdata = {dataset1,dataset2} ; % don't forget the extension
Publish(path, ID, figs, 'Location', 'local','Method','centraliced')
Publish(path, ID, fig(1), 'Location', 'local','Method','centraliced')
%% Example 2 : multiple plots plot, all based on two data-set2
% for individual data-sets, use an appropriate array
fig(2) = figure;
plot(x,y,'-b');
box off; hold on;
plot(x1,y1,'--k');
set(gca, 'TickDir', 'out', 'YLim', [0,4]);
% tag both plots
[fig, IDs] = TagPlot(fig, ProjectID);
% data locations
path.script = mfilename('fullpath'); % filename of the m.script
% file names of the datasets
path.rdata = {dataset2} ; % don't forget the extension
% publsihing via for-loop
for i=1: numel(fig)
disp(string(i));
Publish(path, IDs{i}, fig(i), 'Location', 'local','Method','centraliced');
end
%% Second Plot with identical data to test centralized method
% ToDO Add better description
fig2 =figure;
plot(x,y,'-k');
......
function Publish(DataPaths, ID, figures, options)
function Publish(DataPaths, ID, figure, options)
%Publishes saves plot, data and measuring script
% Location sets the storage location. 'local' sets the storage location
% to the current folder (an export folder will be created), 'server' is a
......@@ -10,12 +10,21 @@ function Publish(DataPaths, ID, figures, options)
arguments
DataPaths
ID (1,:) {mustBeNonzeroLengthText} % ID must be provided
figures (1,:) {mustBeFigure} % Checks if Figures are figures
figure (1,:) {mustBeFigure} % Checks if figure is a figure object
options.Location {mustBeMember(options.Location ,['local','server','CI-Test'])} = 'local' % storage path
options.Method {mustBeMember(options.Method ,['individual','centraliced'])} = 'individual'
options.CopyUserFCN (1,1) {mustBeNumericOrLogical} = true
end
%catch multiple figures in fig
if numel(figure) > 1
figure = figure(1);
msg = ['Publish is designed for handeling one figure at once' newline,...
'- publishes uses only the first figure.' newline , ...
'Consider an external for loop for multi figure export as provided in example.m'];
warning(msg);
end
switch options.Location
case 'local'
storPath = fullfile(pwd,'export');
......@@ -28,7 +37,9 @@ folderName = char(ID);
%% Create Data-Directory
addpath(storPath);
if mkdir(fullfile(storPath,folderName))
if isfolder(fullfile(storPath,folderName))
error(['Folder ',folderName, ' exists - Plot was already published ']);
elseif mkdir(fullfile(storPath,folderName))
else
error('Directory could not be created - check remote path and permissions');
end
......@@ -79,20 +90,18 @@ switch options.Method
% Create a copy of the research data
createFileCopy(DataPaths.rdata,folderName,storPath,ID, 'data');
end
%% Export the Plots
try
for i=1:numel(figures)
fig = figures(i);
PlotName = [ID,'_plot',num2str(i)]; % Der Plotnamen
%% Export the Plot
%try
PlotName = [ID,'_plot']; % plotname
RemotePath = fullfile(storPath ,folderName, PlotName);
% Matlab figure
savefig(fig,RemotePath);
exportgraphics(fig,[RemotePath,'.png'],'Resolution',300);
disp([num2str(i),' of ',num2str(numel(figures)),' figures exported']);
end
catch
warning('Plot export was not successful')
end
savefig(figure,RemotePath);
% the png should only be a preview
exportgraphics(figure,[RemotePath,'.png'],'Resolution',300);
% end
% catch
% warning('Plot export was not successful')
% end
disp(['publishing of ', ID , ' done']);
......@@ -100,5 +109,5 @@ end %function
function tf = mustBeFigure(h)
%checks if input is a figure object
tf = strcmp(get(h, 'type'), 'figure') & isa(h, 'matlab.ui.Figure');
tf = strcmp(get(h, 'type'), 'figure') & isa(h, 'matlab.ui.Figure');
end
function [figs, ID] = TagPlot(figs, prefix, options)
function [figs, IDs] = TagPlot(figs, prefix, options)
%TagPlot adds IDs to figures
% The ID is placed visual on the figure window and as Tag (property of figure)
% TagPlot can tag multiple figures at once
% TagPlot can tag multiple figures at once.
% If a single Plot is taged IDs is a char, otherwise it is a cell array of
% chars
% prefix is the project number (string or char)
%
% The ID is placed on the 'east' per default, if you want it somwhere
......@@ -44,21 +46,27 @@ switch options.Location
warning([options.Location, ' is not a defined location, TagPlot uses location east instead']);
options.Location = 'east'; options.Position = [1,0.4];
end
IDs = cell(numel(figs),1);
for n = 1:numel(figs)
ID = CreateID; % Create ID
ID = [prefix,'-',ID]; % add Prefix
IDs{n} = CreateID; % Create ID
IDs{n} = [prefix,'-',IDs{n}]; % add Prefix
axes = get(figs(n),'CurrentAxes'); % Axes object for text annotation
% Limits for relative Positioning
ylim =get(axes,'YLim');
xlim =get(axes,'XLim');
%ID
position = [options.Position(1)*xlim(2), options.Position(2)*ylim(2)];
text(axes,position(1),position(2), ID,'Fontsize',options.Fontsize,...
text(axes,position(1),position(2), IDs{n},'Fontsize',options.Fontsize,...
'Rotation',options.Rotation, 'VerticalAlignment','bottom','Color',...
0.65*[1 1 1],'BackgroundColor','w');
set(figs(n),'Tag', ID);
set(figs(n),'Tag', IDs{n});
end
if numel(figs) == 1
% use char instead of a cell arry for a single ID
IDs = IDs{1};
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment