Skip to content

Commit d01f1a7

Browse files
committed
add check to handle single vs multiple plots differently
1 parent 34a2cd5 commit d01f1a7

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed
Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
function cleanFeedTitle(obj)
22
% cleanFeedTitle checks all annotations for a title. The first title found
33
% is used as the layout.title (Plotly title). This should correspond to the
4-
% title of the first plot added to the MATLAB figure. As a workaround, only
5-
% the text is used so that the title appears in the feed. The text color is
6-
% set so that the Plotly title is hidden from the graph, favouring the
4+
% title of the first plot added to the MATLAB figure. cleanFeedTitle should
5+
% be called after the style keys have been stripped --> it must override
6+
% certain style keys as a workaround.
7+
8+
% -- Single plot figure -- %
9+
10+
% If only a single plot is present, the title will be set as the Plotly
11+
% title.
12+
13+
% -- Multiple plot figure -- %
14+
15+
% If multiple plots are present, only the text of the title is used so
16+
% that the title appears in the feed. The text color is set so that the
17+
% Plotly title is hidden from the graph, favouring the
718
% annotation title (with its flexibilty over positioning).
819

920
if ~isempty(obj.State.Figure.NumTexts)
@@ -17,15 +28,35 @@ function cleanFeedTitle(obj)
1728
first_title_handle = obj.State.Text(first_title_index).Handle;
1829

1930
% grab the string of the first title
20-
first_title = get(first_title_handle, 'String');
21-
interp = get(first_title_handle, 'Interpreter');
22-
first_title_parsed = parseString(first_title, interp);
31+
annotation_index = obj.getAnnotationIndex(first_title_handle);
32+
first_title = obj.layout.annotations{annotation_index}.text;
2333

2434
% use that as the filename
25-
obj.layout.title = first_title_parsed;
35+
obj.layout.title = first_title;
2636

27-
% make the title invisible
28-
obj.layout.titlefont.color = 'rgba(0,0,0,0)';
37+
% check for a single plot
38+
if (obj.State.Figure.NumPlots == 1)
39+
40+
% grab the font style if not stripped
41+
if ~obj.PlotOptions.Strip
42+
obj.layout.titlefont = ...
43+
obj.layout.annotations{annotation_index}.font;
44+
end
45+
46+
% remove the annotation
47+
obj.layout.annotations(annotation_index) = [];
48+
obj.State.Figure.NumTexts = obj.State.Figure.NumTexts - 1;
49+
obj.State.Text(first_title_index) = [];
50+
51+
% adjust the top margin for the title
52+
obj.layout.margin.t = max(...
53+
obj.PlotlyDefaults.MinTitleMargin,...
54+
obj.layout.margin.t);
55+
else
56+
57+
% multiple plots ---> make the title invisible
58+
obj.layout.titlefont.color = 'rgba(0,0,0,0)';
59+
end
2960
end
3061
end
3162
end

0 commit comments

Comments
 (0)