Skip to content

add tiledlayout annotations when tiledlayout functionality is used #408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
38 changes: 23 additions & 15 deletions plotly/plotlyfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,14 @@ function validate(obj)
obj.State.Figure.NumLegends = 0;
obj.State.Figure.NumColorbars = 0;
obj.State.Figure.NumTexts = 0;

% check if there is tiledlayout
try
tiledLayoutStruct = get(obj.State.Figure.Handle.Children);
isTiledLayout = strcmp(tiledLayoutStruct.Type, 'tiledlayout');
catch
isTiledLayout = false;
end

% find axes of figure
ax = findobj(obj.State.Figure.Handle,'Type','axes','-and',{'Tag','','-or','Tag','PlotMatrixBigAx','-or','Tag','PlotMatrixScatterAx', '-or','Tag','PlotMatrixHistAx'});
Expand Down Expand Up @@ -616,6 +624,7 @@ function validate(obj)
ax = temp_ax;
%---------- checking the overlaping of the graphs ----------%

% update number of axes
obj.State.Figure.NumAxes = length(ax);

% update number of annotations (one title per axis)
Expand Down Expand Up @@ -712,7 +721,7 @@ function validate(obj)
obj.State.Figure.NumTexts = obj.State.Figure.NumTexts + length(texts);

end

% find legends of figure
if isHG2
legs = findobj(obj.State.Figure.Handle,'Type','Legend');
Expand Down Expand Up @@ -778,24 +787,13 @@ function validate(obj)
end
end
catch
% TODO to the future
% disp('catch at line 647 in plotlyfig.m file')
% TODO
end
end

% update plots
for n = 1:obj.State.Figure.NumPlots
updateData(obj,n);

try
if update_opac(length(ax)-n)
% obj.data{1, n}.opacity = 0.9;
end
catch
% TODO to the future
% disp('catch at line 664 in plotlyfig.m file')
end

end

% update annotations
Expand All @@ -804,20 +802,28 @@ function validate(obj)
if obj.PlotOptions.is_headmap_axis
updateHeatmapAnnotation(obj,n);
obj.PlotOptions.CleanFeedTitle = false;

elseif obj.PlotlyDefaults.isGeoaxis
% TODO
% TODO

else
if ~obj.PlotlyDefaults.isTernary
updateAnnotation(obj,n);

if obj.State.Figure.NumAxes == 1
obj.PlotOptions.CleanFeedTitle = false;
end
end
end
catch
% TODO to the future
% TODO
end
end

% update tiled layout annotations
if isTiledLayout
updateTiledLayoutAnnotation(obj, tiledLayoutStruct);
end

% update legends
if obj.State.Figure.NumLegends < 2
Expand All @@ -826,6 +832,7 @@ function validate(obj)
updateLegend(obj,n);
end
end

else
updateLegendMultipleAxes(obj,1);
end
Expand All @@ -834,6 +841,7 @@ function validate(obj)
for n = 1:obj.State.Figure.NumColorbars
if ~obj.PlotlyDefaults.isTernary
updateColorbar(obj,n);

else
updateTernaryColorbar(obj,n);
end
Expand Down
84 changes: 84 additions & 0 deletions plotly/plotlyfig_aux/core/updateTiledLayoutAnnotation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
function obj = updateTiledLayoutAnnotation(obj, tiledLayoutData)

%-------------------------------------------------------------------------%

%-INITIALIZATIONS-%
anIndex = obj.State.Figure.NumTexts + 1;
titleStruct = get(tiledLayoutData.Title);

obj.layout.annotations{anIndex}.showarrow = false;
obj.layout.annotations{anIndex}.xref = 'paper';
obj.layout.annotations{anIndex}.yref = 'paper';
obj.layout.annotations{anIndex}.align = titleStruct.HorizontalAlignment;

%-------------------------------------------------------------------------%

%-anchors-%
obj.layout.annotations{anIndex}.xanchor = titleStruct.HorizontalAlignment;

switch titleStruct.VerticalAlignment
case {'top', 'cap'}
obj.layout.annotations{anIndex}.yanchor = 'top';
case 'middle'
obj.layout.annotations{anIndex}.yanchor = 'middle';
case {'baseline','bottom'}
obj.layout.annotations{anIndex}.yanchor = 'bottom';
end

%-------------------------------------------------------------------------%

%-text-%
titleString = titleStruct.String;
titleInterpreter = titleStruct.Interpreter;

if isempty(titleString)
titleTex = titleString;
else
titleTex = parseString(titleString, titleInterpreter);
end

obj.layout.annotations{anIndex}.text = titleTex;

%-------------------------------------------------------------------------%

%-text location-%
obj.layout.annotations{anIndex}.x = 0.5;
obj.layout.annotations{anIndex}.y = 0.95;

%-------------------------------------------------------------------------%

%-font properties-%
titleColor = sprintf('rgb(%f,%f,%f)', 255*titleStruct.Color);
titleSize = titleStruct.FontSize;
titleFamily = matlab2plotlyfont(titleStruct.FontName);

obj.layout.annotations{anIndex}.font.color = titleColor;
obj.layout.annotations{anIndex}.font.size = 1.2*titleSize;
obj.layout.annotations{anIndex}.font.family = titleFamily;

switch titleStruct.FontWeight
case {'bold','demi'}
titleString = sprintf('<b>%s</b>', titleString);
obj.layout.annotations{anIndex}.text = titleString;
otherwise
end

%-------------------------------------------------------------------------%

%-title angle-%
textAngle = titleStruct.Rotation;

if textAngle > 180
textAngle = textAngle - 360;
end

obj.layout.annotations{anIndex}.textangle = textAngle;

%-------------------------------------------------------------------------%

%-hide text (a workaround)-%
if strcmp(titleStruct.Visible,'off')
obj.layout.annotations{anIndex}.text = ' ';
end

end