Skip to content

Commit 34a2cd5

Browse files
committed
add cleanFeedTitle flag + helper function
1 parent 121baec commit 34a2cd5

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

plotly/plotlyfig.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
obj.UserData.Verbose = true;
5151

5252
%-PlotOptions-%
53+
obj.PlotOptions.CleanFeedTitle = true;
5354
obj.PlotOptions.FileName = '';
5455
obj.PlotOptions.FileOpt = 'new';
5556
obj.PlotOptions.WorldReadable = true;
@@ -360,9 +361,14 @@ function validate(obj)
360361
% validate keys
361362
validate(obj);
362363

363-
% handle title
364+
% handle filename
364365
handleFileName(obj);
365366

367+
% handle title (for feed)
368+
if obj.PlotOptions.CleanFeedTitle
369+
cleanFeedTitle(obj);
370+
end
371+
366372
%args
367373
args.filename = obj.PlotOptions.FileName;
368374
args.fileopt = obj.PlotOptions.FileOpt;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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. 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
7+
% annotation title (with its flexibilty over positioning).
8+
9+
if ~isempty(obj.State.Figure.NumTexts)
10+
11+
% grab the title of the first plot added to the figure.
12+
first_title_index = find(arrayfun(@(x)(isequal(x.Title, 1)), ...
13+
obj.State.Text), 1, 'first');
14+
15+
if ~isempty(first_title_index)
16+
17+
first_title_handle = obj.State.Text(first_title_index).Handle;
18+
19+
% 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);
23+
24+
% use that as the filename
25+
obj.layout.title = first_title_parsed;
26+
27+
% make the title invisible
28+
obj.layout.titlefont.color = 'rgba(0,0,0,0)';
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)