Skip to content

Commit b93a56e

Browse files
authored
Merge pull request #126 from DavidUnzue/offline-optional-include-plotlyjs
Added option to disable inclusion of plotly js in offline html output.
2 parents 998df11 + aba14ec commit b93a56e

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

plotly/plotly_offline_aux/plotlyoffline.m

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@
33
% the current working directory. The file will be saved as:
44
% 'plotlyfig.PlotOptions.FileName'.html.
55

6-
% grab the bundled dependencies
7-
userhome = getuserdir();
8-
plotly_config_folder = fullfile(userhome,'.plotly');
9-
plotly_js_folder = fullfile(plotly_config_folder, 'plotlyjs');
10-
bundle_name = 'plotly-matlab-offline-bundle.js';
11-
bundle_file = fullfile(plotly_js_folder, bundle_name);
12-
13-
% check that the bundle exists
14-
try
15-
bundle = fileread(bundle_file);
16-
catch
17-
error(['Error reading: %s.\nPlease download the required ', ...
18-
'dependencies using: >>getplotlyoffline \n', ...
19-
'or contact support@plot.ly for assistance.'], ...
20-
bundle_file);
6+
% create dependency string unless not required
7+
if plotlyfig.PlotOptions.IncludePlotlyjs
8+
% grab the bundled dependencies
9+
userhome = getuserdir();
10+
plotly_config_folder = fullfile(userhome,'.plotly');
11+
plotly_js_folder = fullfile(plotly_config_folder, 'plotlyjs');
12+
bundle_name = 'plotly-matlab-offline-bundle.js';
13+
bundle_file = fullfile(plotly_js_folder, bundle_name);
14+
15+
% check that the bundle exists
16+
try
17+
bundle = fileread(bundle_file);
18+
% template dependencies
19+
dep_script = sprintf('<script type="text/javascript">%s</script>\n', ...
20+
bundle);
21+
catch
22+
error(['Error reading: %s.\nPlease download the required ', ...
23+
'dependencies using: >>getplotlyoffline \n', ...
24+
'or contact support@plot.ly for assistance.'], ...
25+
bundle_file);
26+
end
27+
else
28+
dep_script = '';
2129
end
2230

2331
% handle plot div specs
@@ -35,15 +43,11 @@
3543
jdata = m2json(plotlyfig.data);
3644
jlayout = m2json(plotlyfig.layout);
3745
clean_jdata = escapechars(jdata);
38-
clean_jlayout = escapechars(jlayout);
39-
40-
% template dependencies
41-
dep_script = sprintf('<script type="text/javascript">%s</script>', ...
42-
bundle);
46+
clean_jlayout = escapechars(jlayout);
4347

4448
% template environment vars
4549
plotly_domain = plotlyfig.UserData.PlotlyDomain;
46-
env_script = sprintf(['\n<script type="text/javascript">', ...
50+
env_script = sprintf(['<script type="text/javascript">', ...
4751
'window.PLOTLYENV=window.PLOTLYENV || {};', ...
4852
'window.PLOTLYENV.BASE_URL="%s";', ...
4953
'Plotly.LINKTEXT="%s";', ...

plotly/plotlyfig.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
obj.PlotOptions.Offline = false;
6464
obj.PlotOptions.ShowLinkText = true;
6565
obj.PlotOptions.LinkText = obj.get_link_text;
66+
obj.PlotOptions.IncludePlotlyjs = true;
6667

6768
%-PlotlyDefaults-%
6869
obj.PlotlyDefaults.MinTitleMargin = 80;
@@ -177,6 +178,9 @@
177178
if(strcmpi(varargin{a},'linktext'))
178179
obj.PlotOptions.LinkText = varargin{a+1};
179180
end
181+
if(strcmpi(varargin{a},'include_plotlyjs'))
182+
obj.PlotOptions.IncludePlotlyjs = varargin{a+1};
183+
end
180184
if(strcmpi(varargin{a},'layout'))
181185
obj.layout= varargin{a+1};
182186
end

0 commit comments

Comments
 (0)