From aba14ec582233112cc5fc2faf69bcaecd64b9d27 Mon Sep 17 00:00:00 2001 From: David Unzue Date: Thu, 27 Apr 2017 11:06:54 +0200 Subject: [PATCH] Added option to disable inclusion of plotly js in offline html output. The argument 'include_plotlyjs' accepts a boolean value and enables the removal of the plotly.js dependency from the html output in offline mode. i.e.: fig2plotly(gcf, 'offline', true, 'include_plotlyjs', false, 'filename', 'sine wave'); --- plotly/plotly_offline_aux/plotlyoffline.m | 46 ++++++++++++----------- plotly/plotlyfig.m | 4 ++ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/plotly/plotly_offline_aux/plotlyoffline.m b/plotly/plotly_offline_aux/plotlyoffline.m index ca76c0ce..5acf0752 100644 --- a/plotly/plotly_offline_aux/plotlyoffline.m +++ b/plotly/plotly_offline_aux/plotlyoffline.m @@ -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('\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 @@ -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('', ... - bundle); + clean_jlayout = escapechars(jlayout); % template environment vars plotly_domain = plotlyfig.UserData.PlotlyDomain; - env_script = sprintf(['\n