Skip to content
Snippets Groups Projects

Add PinToAxis option

Merged Lemmer, Jan requested to merge 83-positionierung-der-id-an-legende into development
3 files
+ 36
10
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 27
5
@@ -24,6 +24,7 @@ arguments
options.Position (1,2) {mustBeVector} = [1,0.4] % default for east
options.Rotation (1,1) {mustBeReal} = NaN
options.ConfigFileName (1,:) {mustBeText} = 'config.json'
options.PinToLegend (1,1) {mustBeNumericOrLogical} = false % Pins ID on Legend
options.QRcode (1,1) {mustBeNumericOrLogical} = false %experimental
options.QRsize (1,1) {mustBeNonnegative} = 0.15 % size of the QRCode
end
@@ -36,7 +37,7 @@ end
switch options.Location
case 'north'
y = 1 - options.DistanceToAxis
y = 1 - options.DistanceToAxis;
options.Position = [0.4,y];
Rotation = 0;
case 'east'
@@ -76,16 +77,35 @@ for n = 1:numel(figs)
IDs{n} = PlotID.CreateID; % Create ID
IDs{n} = [options.ProjectID,'-',IDs{n}]; % add options.ProjectID
pltAxes = get(figs(n),'CurrentAxes'); % Axes object for text annotation
% Limits for relative Positioning
% Limits for relative positioning
ylim =get(pltAxes,'YLim');
xlim =get(pltAxes,'XLim');
%ID
position = [options.Position(1), options.Position(2)];
xlim =get(pltAxes,'XLim');
if options.PinToLegend
if options.QRcode
warning(['PinToLegend and QRCode can not be used at the same time',...
newline, 'QRcode is deactivated.']);
options.QRcode = false;
end
lobj = findobj(figs(n), 'Type', 'Legend');
if isempty(lobj)
set(0, 'CurrentFigure', figs(n))
lobj = legend();
end
% new position based on legend
posVec = get(lobj,'Position');
options.Position(1) = posVec(1)+.04;
options.Position(2) = posVec(2);
end
% add text label
position = [options.Position(1), options.Position(2)];
t=text(pltAxes,position(1),position(2), IDs{n},'Fontsize',options.Fontsize,...
'Rotation',Rotation, 'VerticalAlignment','bottom','Color',...
options.Color,'BackgroundColor','w', 'Units', 'normalized');
set(figs(n),'Tag', IDs{n});
if options.QRcode
% this should be seen and use as a proof of concept
qrCode = PlotID.plotQR(IDs{n});
@@ -94,6 +114,8 @@ for n = 1:numel(figs)
imshow(qrCode);
t.Visible = 'off';
end
end
if numel(figs) == 1
Loading