1
+ function cleanFeedTitle(obj )
2
+ % cleanFeedTitle checks all annotations for a title. The first title found
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. 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
18
+ % annotation title (with its flexibilty over positioning).
19
+
20
+ if ~isempty(obj .State .Figure .NumTexts )
21
+
22
+ % grab the title of the first plot added to the figure.
23
+ first_title_index = find(arrayfun(@(x )(isequal(x .Title , 1 )), ...
24
+ obj .State .Text ), 1 , ' first' );
25
+
26
+ if ~isempty(first_title_index )
27
+
28
+ first_title_handle = obj .State .Text(first_title_index ).Handle;
29
+
30
+ % grab the string of the first title
31
+ annotation_index = obj .getAnnotationIndex(first_title_handle );
32
+ first_title = obj.layout.annotations{annotation_index }.text;
33
+
34
+ % use that as the filename
35
+ obj.layout.title = first_title ;
36
+
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
60
+ end
61
+ end
62
+ end
0 commit comments