Skip to content

Commit 274e18d

Browse files
Merge pull request #408 from plotly/add_tiledlayout_annotations_when_tiledlayout_functionality_is_used
add tiledlayout annotations when tiledlayout functionality is used
2 parents 5318b66 + 77db851 commit 274e18d

File tree

2 files changed

+107
-15
lines changed

2 files changed

+107
-15
lines changed

plotly/plotlyfig.m

+23-15
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,14 @@ function validate(obj)
579579
obj.State.Figure.NumLegends = 0;
580580
obj.State.Figure.NumColorbars = 0;
581581
obj.State.Figure.NumTexts = 0;
582+
583+
% check if there is tiledlayout
584+
try
585+
tiledLayoutStruct = get(obj.State.Figure.Handle.Children);
586+
isTiledLayout = strcmp(tiledLayoutStruct.Type, 'tiledlayout');
587+
catch
588+
isTiledLayout = false;
589+
end
582590

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

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

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

714723
end
715-
724+
716725
% find legends of figure
717726
if isHG2
718727
legs = findobj(obj.State.Figure.Handle,'Type','Legend');
@@ -778,24 +787,13 @@ function validate(obj)
778787
end
779788
end
780789
catch
781-
% TODO to the future
782-
% disp('catch at line 647 in plotlyfig.m file')
790+
% TODO
783791
end
784792
end
785793

786794
% update plots
787795
for n = 1:obj.State.Figure.NumPlots
788796
updateData(obj,n);
789-
790-
try
791-
if update_opac(length(ax)-n)
792-
% obj.data{1, n}.opacity = 0.9;
793-
end
794-
catch
795-
% TODO to the future
796-
% disp('catch at line 664 in plotlyfig.m file')
797-
end
798-
799797
end
800798

801799
% update annotations
@@ -804,20 +802,28 @@ function validate(obj)
804802
if obj.PlotOptions.is_headmap_axis
805803
updateHeatmapAnnotation(obj,n);
806804
obj.PlotOptions.CleanFeedTitle = false;
805+
807806
elseif obj.PlotlyDefaults.isGeoaxis
808-
% TODO
807+
% TODO
808+
809809
else
810810
if ~obj.PlotlyDefaults.isTernary
811811
updateAnnotation(obj,n);
812+
812813
if obj.State.Figure.NumAxes == 1
813814
obj.PlotOptions.CleanFeedTitle = false;
814815
end
815816
end
816817
end
817818
catch
818-
% TODO to the future
819+
% TODO
819820
end
820821
end
822+
823+
% update tiled layout annotations
824+
if isTiledLayout
825+
updateTiledLayoutAnnotation(obj, tiledLayoutStruct);
826+
end
821827

822828
% update legends
823829
if obj.State.Figure.NumLegends < 2
@@ -826,6 +832,7 @@ function validate(obj)
826832
updateLegend(obj,n);
827833
end
828834
end
835+
829836
else
830837
updateLegendMultipleAxes(obj,1);
831838
end
@@ -834,6 +841,7 @@ function validate(obj)
834841
for n = 1:obj.State.Figure.NumColorbars
835842
if ~obj.PlotlyDefaults.isTernary
836843
updateColorbar(obj,n);
844+
837845
else
838846
updateTernaryColorbar(obj,n);
839847
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
function obj = updateTiledLayoutAnnotation(obj, tiledLayoutData)
2+
3+
%-------------------------------------------------------------------------%
4+
5+
%-INITIALIZATIONS-%
6+
anIndex = obj.State.Figure.NumTexts + 1;
7+
titleStruct = get(tiledLayoutData.Title);
8+
9+
obj.layout.annotations{anIndex}.showarrow = false;
10+
obj.layout.annotations{anIndex}.xref = 'paper';
11+
obj.layout.annotations{anIndex}.yref = 'paper';
12+
obj.layout.annotations{anIndex}.align = titleStruct.HorizontalAlignment;
13+
14+
%-------------------------------------------------------------------------%
15+
16+
%-anchors-%
17+
obj.layout.annotations{anIndex}.xanchor = titleStruct.HorizontalAlignment;
18+
19+
switch titleStruct.VerticalAlignment
20+
case {'top', 'cap'}
21+
obj.layout.annotations{anIndex}.yanchor = 'top';
22+
case 'middle'
23+
obj.layout.annotations{anIndex}.yanchor = 'middle';
24+
case {'baseline','bottom'}
25+
obj.layout.annotations{anIndex}.yanchor = 'bottom';
26+
end
27+
28+
%-------------------------------------------------------------------------%
29+
30+
%-text-%
31+
titleString = titleStruct.String;
32+
titleInterpreter = titleStruct.Interpreter;
33+
34+
if isempty(titleString)
35+
titleTex = titleString;
36+
else
37+
titleTex = parseString(titleString, titleInterpreter);
38+
end
39+
40+
obj.layout.annotations{anIndex}.text = titleTex;
41+
42+
%-------------------------------------------------------------------------%
43+
44+
%-text location-%
45+
obj.layout.annotations{anIndex}.x = 0.5;
46+
obj.layout.annotations{anIndex}.y = 0.95;
47+
48+
%-------------------------------------------------------------------------%
49+
50+
%-font properties-%
51+
titleColor = sprintf('rgb(%f,%f,%f)', 255*titleStruct.Color);
52+
titleSize = titleStruct.FontSize;
53+
titleFamily = matlab2plotlyfont(titleStruct.FontName);
54+
55+
obj.layout.annotations{anIndex}.font.color = titleColor;
56+
obj.layout.annotations{anIndex}.font.size = 1.2*titleSize;
57+
obj.layout.annotations{anIndex}.font.family = titleFamily;
58+
59+
switch titleStruct.FontWeight
60+
case {'bold','demi'}
61+
titleString = sprintf('<b>%s</b>', titleString);
62+
obj.layout.annotations{anIndex}.text = titleString;
63+
otherwise
64+
end
65+
66+
%-------------------------------------------------------------------------%
67+
68+
%-title angle-%
69+
textAngle = titleStruct.Rotation;
70+
71+
if textAngle > 180
72+
textAngle = textAngle - 360;
73+
end
74+
75+
obj.layout.annotations{anIndex}.textangle = textAngle;
76+
77+
%-------------------------------------------------------------------------%
78+
79+
%-hide text (a workaround)-%
80+
if strcmp(titleStruct.Visible,'off')
81+
obj.layout.annotations{anIndex}.text = ' ';
82+
end
83+
84+
end

0 commit comments

Comments
 (0)