Skip to content

introduce caption helper method #59

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 1 commit into from
Jun 12, 2015
Merged
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
introduce caption helper method
  • Loading branch information
BRONSOLO committed Jun 11, 2015
commit 21992c20eeaf0dce4a0236f47193d5e27bc0acfd
36 changes: 36 additions & 0 deletions plotly/plotlyfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
obj.PlotlyDefaults.ErrorbarWidth = 6;
obj.PlotlyDefaults.ShowBaselineLegend = false;
obj.PlotlyDefaults.Bargap = 0;
obj.PlotlyDefaults.CaptionMarginIncreaseFactor = 1.2;
obj.PlotlyDefaults.MinCaptionMargin = 80;

%-State-%
obj.State.Figure = [];
Expand Down Expand Up @@ -347,6 +349,40 @@ function validate(obj)
end
end

%----ADD A CUSTOM CAPTION-----%
function obj = add_caption(obj, caption_string, varargin)

caption.text = caption_string;

% defaults
caption.xref = 'paper';
caption.yref = 'paper';
caption.xanchor = 'left';
caption.yanchor = 'top';
caption.x = 0.1;
caption.y = -0.05;
caption.showarrow = false;

% inject any custom annotation specs
for n = 1:2:length(varargin)
caption = setfield(caption, varargin{n}, varargin{n+1});
end

% adjust the bottom margin
obj.layout.margin.b = max(obj.layout.margin.b, ...
obj.PlotlyDefaults.MinCaptionMargin);

% add the new caption to the figure
obj.State.Figure.NumTexts = obj.State.Figure.NumTexts + 1;
obj.layout.annotations{obj.State.Figure.NumTexts} = caption;

% update the figure state
obj.State.Text(obj.State.Figure.NumTexts).Handle = NaN;
obj.State.Text(obj.State.Figure.NumTexts).AssociatedAxis = gca;
obj.State.Text(obj.State.Figure.NumTexts).Title = false;

end


%------------------------REST API CALL----------------------------%

Expand Down