|
6 | 6 | % create dependency string unless not required
|
7 | 7 | if plotlyfig.PlotOptions.IncludePlotlyjs
|
8 | 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); |
| 9 | + userHome = getuserdir(); |
| 10 | + plotlyConfigFolder = fullfile(userHome,'.plotly'); |
| 11 | + plotlyJSFolder = fullfile(plotlyConfigFolder, 'plotlyjs'); |
| 12 | + bundleName = 'plotly-matlab-offline-bundle.js'; |
| 13 | + bundleFile = fullfile(plotlyJSFolder, bundleName); |
14 | 14 |
|
15 | 15 | % check that the bundle exists
|
16 | 16 | try
|
17 |
| - bundle = fileread(bundle_file); |
| 17 | + bundle = fileread(bundleFile); |
18 | 18 | % template dependencies
|
19 |
| - dep_script = sprintf('<script type="text/javascript">%s</script>\n', ... |
| 19 | + depScript = sprintf('<script type="text/javascript">%s</script>\n', ... |
20 | 20 | bundle);
|
21 | 21 | catch
|
22 | 22 | error(['Error reading: %s.\nPlease download the required ', ...
|
23 | 23 | 'dependencies using: >>getplotlyoffline \n', ...
|
24 | 24 | 'or contact support@plot.ly for assistance.'], ...
|
25 |
| - bundle_file); |
| 25 | + bundleFile); |
26 | 26 | end
|
27 | 27 | else
|
28 |
| - dep_script = ''; |
| 28 | + depScript = ''; |
29 | 29 | end
|
30 | 30 |
|
31 | 31 | % handle plot div specs
|
|
34 | 34 | height = [num2str(plotlyfig.layout.height) 'px'];
|
35 | 35 |
|
36 | 36 | if plotlyfig.PlotOptions.ShowLinkText
|
37 |
| - link_text = plotlyfig.PlotOptions.LinkText; |
| 37 | + linkText = plotlyfig.PlotOptions.LinkText; |
38 | 38 | else
|
39 |
| - link_text = ''; |
| 39 | + linkText = ''; |
40 | 40 | end
|
41 | 41 |
|
42 | 42 | % format the data and layout
|
43 |
| - jdata = m2json(plotlyfig.data); |
44 |
| - jlayout = m2json(plotlyfig.layout); |
45 |
| - clean_jdata = escapechars(jdata); |
46 |
| - clean_jlayout = escapechars(jlayout); |
| 43 | + jData = m2json(plotlyfig.data); |
| 44 | + jLayout = m2json(plotlyfig.layout); |
| 45 | + jFrames = m2json(plotlyfig.frames); |
| 46 | + clean_jData = escapechars(jData); |
| 47 | + clean_jLayout = escapechars(jLayout); |
| 48 | + clean_jFrames = escapechars(jFrames); |
47 | 49 |
|
48 | 50 | % template environment vars
|
49 |
| - plotly_domain = plotlyfig.UserData.PlotlyDomain; |
50 |
| - env_script = sprintf(['<script type="text/javascript">', ... |
| 51 | + plotlyDomain = plotlyfig.UserData.PlotlyDomain; |
| 52 | + envScript = sprintf(['<script type="text/javascript">', ... |
51 | 53 | 'window.PLOTLYENV=window.PLOTLYENV || {};', ...
|
52 | 54 | 'window.PLOTLYENV.BASE_URL="%s";', ...
|
53 | 55 | 'Plotly.LINKTEXT="%s";', ...
|
54 |
| - '</script>'], plotly_domain, link_text); |
55 |
| - |
| 56 | + '</script>'], plotlyDomain, linkText); |
| 57 | + |
56 | 58 | % template Plotly.plot
|
57 |
| - script = sprintf(['\n Plotly.plot("%s", %s, %s).then(function(){'... |
| 59 | + script = sprintf(['\n Plotly.plot("%s", {\n"data": %s,\n"layout": %s,\n"frames": %s\n}).then(function(){'... |
58 | 60 | '\n $(".%s.loading").remove();' ...
|
59 | 61 | '\n $(".link--embedview").text("%s");'...
|
60 |
| - '\n });'], id, clean_jdata, clean_jlayout, ... |
61 |
| - id, link_text); |
62 |
| - |
63 |
| - plotly_script = sprintf(['\n<div id="%s" style="height: %s;',... |
| 62 | + '\n });'], id, clean_jData, clean_jLayout, clean_jFrames,... |
| 63 | + id, linkText); |
| 64 | + |
| 65 | + plotlyScript = sprintf(['\n<div id="%s" style="height: %s;',... |
64 | 66 | 'width: %s;" class="plotly-graph-div">' ...
|
65 | 67 | '</div> \n<script type="text/javascript">' ...
|
66 | 68 | '%s \n</script>'], id, height, width, ...
|
67 | 69 | script);
|
68 | 70 |
|
69 | 71 | % template entire script
|
70 |
| - offline_script = [dep_script env_script plotly_script]; |
| 72 | + offlineScript = [depScript envScript plotlyScript]; |
71 | 73 | filename = plotlyfig.PlotOptions.FileName;
|
72 | 74 | if iscellstr(filename), filename = sprintf('%s ', filename{:}); end
|
73 | 75 |
|
74 | 76 | % remove the whitespace from the filename
|
75 |
| - clean_filename = filename(filename~=' '); |
76 |
| - html_filename = [clean_filename '.html']; |
| 77 | + cleanFilename = filename(filename~=' '); |
| 78 | + htmlFilename = [cleanFilename '.html']; |
77 | 79 |
|
78 | 80 | % save the html file in the working directory
|
79 |
| - plotly_offline_file = fullfile(plotlyfig.PlotOptions.SaveFolder, html_filename); |
80 |
| - file_id = fopen(plotly_offline_file, 'w'); |
81 |
| - fprintf(file_id, offline_script); |
82 |
| - fclose(file_id); |
| 81 | + plotlyOfflineFile = fullfile(plotlyfig.PlotOptions.SaveFolder, htmlFilename); |
| 82 | + fileID = fopen(plotlyOfflineFile, 'w'); |
| 83 | + fprintf(fileID, offlineScript); |
| 84 | + fclose(fileID); |
83 | 85 |
|
84 |
| - % remove any whitespace from the plotly_offline_file path |
85 |
| - plotly_offline_file = strrep(plotly_offline_file, ' ', '%20'); |
| 86 | + % remove any whitespace from the plotlyOfflineFile path |
| 87 | + plotlyOfflineFile = strrep(plotlyOfflineFile, ' ', '%20'); |
86 | 88 |
|
87 | 89 | % return the local file url to be rendered in the browser
|
88 |
| - response = ['file:///' plotly_offline_file]; |
| 90 | + response = ['file:///' plotlyOfflineFile]; |
89 | 91 |
|
90 | 92 | end
|
0 commit comments