Skip to content

Added option to disable inclusion of plotly js in offline html output. #126

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
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
46 changes: 25 additions & 21 deletions plotly/plotly_offline_aux/plotlyoffline.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@
% the current working directory. The file will be saved as:
% 'plotlyfig.PlotOptions.FileName'.html.

% grab the bundled dependencies
userhome = getuserdir();
plotly_config_folder = fullfile(userhome,'.plotly');
plotly_js_folder = fullfile(plotly_config_folder, 'plotlyjs');
bundle_name = 'plotly-matlab-offline-bundle.js';
bundle_file = fullfile(plotly_js_folder, bundle_name);

% check that the bundle exists
try
bundle = fileread(bundle_file);
catch
error(['Error reading: %s.\nPlease download the required ', ...
'dependencies using: >>getplotlyoffline \n', ...
'or contact support@plot.ly for assistance.'], ...
bundle_file);
% create dependency string unless not required
if plotlyfig.PlotOptions.IncludePlotlyjs
% grab the bundled dependencies
userhome = getuserdir();
plotly_config_folder = fullfile(userhome,'.plotly');
plotly_js_folder = fullfile(plotly_config_folder, 'plotlyjs');
bundle_name = 'plotly-matlab-offline-bundle.js';
bundle_file = fullfile(plotly_js_folder, bundle_name);

% check that the bundle exists
try
bundle = fileread(bundle_file);
% template dependencies
dep_script = sprintf('<script type="text/javascript">%s</script>\n', ...
bundle);
catch
error(['Error reading: %s.\nPlease download the required ', ...
'dependencies using: >>getplotlyoffline \n', ...
'or contact support@plot.ly for assistance.'], ...
bundle_file);
end
else
dep_script = '';
end

% handle plot div specs
Expand All @@ -35,15 +43,11 @@
jdata = m2json(plotlyfig.data);
jlayout = m2json(plotlyfig.layout);
clean_jdata = escapechars(jdata);
clean_jlayout = escapechars(jlayout);

% template dependencies
dep_script = sprintf('<script type="text/javascript">%s</script>', ...
bundle);
clean_jlayout = escapechars(jlayout);

% template environment vars
plotly_domain = plotlyfig.UserData.PlotlyDomain;
env_script = sprintf(['\n<script type="text/javascript">', ...
env_script = sprintf(['<script type="text/javascript">', ...
'window.PLOTLYENV=window.PLOTLYENV || {};', ...
'window.PLOTLYENV.BASE_URL="%s";', ...
'Plotly.LINKTEXT="%s";', ...
Expand Down
4 changes: 4 additions & 0 deletions plotly/plotlyfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
obj.PlotOptions.Offline = false;
obj.PlotOptions.ShowLinkText = true;
obj.PlotOptions.LinkText = obj.get_link_text;
obj.PlotOptions.IncludePlotlyjs = true;

%-PlotlyDefaults-%
obj.PlotlyDefaults.MinTitleMargin = 80;
Expand Down Expand Up @@ -177,6 +178,9 @@
if(strcmpi(varargin{a},'linktext'))
obj.PlotOptions.LinkText = varargin{a+1};
end
if(strcmpi(varargin{a},'include_plotlyjs'))
obj.PlotOptions.IncludePlotlyjs = varargin{a+1};
end
if(strcmpi(varargin{a},'layout'))
obj.layout= varargin{a+1};
end
Expand Down