1
1
function cleanFeedTitle(obj )
2
2
% cleanFeedTitle checks all annotations for a title. The first title found
3
3
% 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
7
18
% annotation title (with its flexibilty over positioning).
8
19
9
20
if ~isempty(obj .State .Figure .NumTexts )
@@ -17,15 +28,35 @@ function cleanFeedTitle(obj)
17
28
first_title_handle = obj .State .Text(first_title_index ).Handle;
18
29
19
30
% 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;
23
33
24
34
% use that as the filename
25
- obj.layout.title = first_title_parsed ;
35
+ obj.layout.title = first_title ;
26
36
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
29
60
end
30
61
end
31
62
end
0 commit comments