Skip to content

Commit 78e0d75

Browse files
committed
Merge pull request #56 from plotly/title_in_feed_fix
Title in feed fix
2 parents 121baec + bcb9a23 commit 78e0d75

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## MATLAB PLOTLY API WRAPPER 2.1.8
1+
## MATLAB PLOTLY API WRAPPER 2.1.9
22

33
### NUTSHELL:
44

plotly/plotly_aux/plotly_version.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
function version = plotly_version()
2-
version = '2.1.8';
2+
version = '2.1.9';
33
end

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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)