Skip to content

Title in feed fix #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## MATLAB PLOTLY API WRAPPER 2.1.8
## MATLAB PLOTLY API WRAPPER 2.1.9

### NUTSHELL:

Expand Down
2 changes: 1 addition & 1 deletion plotly/plotly_aux/plotly_version.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function version = plotly_version()
version = '2.1.8';
version = '2.1.9';
end
8 changes: 7 additions & 1 deletion plotly/plotlyfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
obj.UserData.Verbose = true;

%-PlotOptions-%
obj.PlotOptions.CleanFeedTitle = true;
obj.PlotOptions.FileName = '';
obj.PlotOptions.FileOpt = 'new';
obj.PlotOptions.WorldReadable = true;
Expand Down Expand Up @@ -360,9 +361,14 @@ function validate(obj)
% validate keys
validate(obj);

% handle title
% handle filename
handleFileName(obj);

% handle title (for feed)
if obj.PlotOptions.CleanFeedTitle
cleanFeedTitle(obj);
end

%args
args.filename = obj.PlotOptions.FileName;
args.fileopt = obj.PlotOptions.FileOpt;
Expand Down
62 changes: 62 additions & 0 deletions plotly/plotlyfig_aux/helpers/cleanFeedTitle.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function cleanFeedTitle(obj)
% cleanFeedTitle checks all annotations for a title. The first title found
% is used as the layout.title (Plotly title). This should correspond to the
% title of the first plot added to the MATLAB figure. cleanFeedTitle should
% be called after the style keys have been stripped --> it must override
% certain style keys as a workaround.

% -- Single plot figure -- %

% If only a single plot is present, the title will be set as the Plotly
% title.

% -- Multiple plot figure -- %

% If multiple plots are present, only the text of the title is used so
% that the title appears in the feed. The text color is set so that the
% Plotly title is hidden from the graph, favouring the
% annotation title (with its flexibilty over positioning).

if ~isempty(obj.State.Figure.NumTexts)

% grab the title of the first plot added to the figure.
first_title_index = find(arrayfun(@(x)(isequal(x.Title, 1)), ...
obj.State.Text), 1, 'first');

if ~isempty(first_title_index)

first_title_handle = obj.State.Text(first_title_index).Handle;

% grab the string of the first title
annotation_index = obj.getAnnotationIndex(first_title_handle);
first_title = obj.layout.annotations{annotation_index}.text;

% use that as the filename
obj.layout.title = first_title;

% check for a single plot
if (obj.State.Figure.NumPlots == 1)

% grab the font style if not stripped
if ~obj.PlotOptions.Strip
obj.layout.titlefont = ...
obj.layout.annotations{annotation_index}.font;
end

% remove the annotation
obj.layout.annotations(annotation_index) = [];
obj.State.Figure.NumTexts = obj.State.Figure.NumTexts - 1;
obj.State.Text(first_title_index) = [];

% adjust the top margin for the title
obj.layout.margin.t = max(...
obj.PlotlyDefaults.MinTitleMargin,...
obj.layout.margin.t);
else

% multiple plots ---> make the title invisible
obj.layout.titlefont.color = 'rgba(0,0,0,0)';
end
end
end
end