|
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 | | - jframes = m2json(plotlyfig.frames); |
46 | | - clean_jdata = escapechars(jdata); |
47 | | - clean_jlayout = escapechars(jlayout); |
48 | | - clean_jframes = escapechars(jframes); |
| 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); |
49 | 49 |
|
50 | 50 | % template environment vars |
51 | | - plotly_domain = plotlyfig.UserData.PlotlyDomain; |
52 | | - env_script = sprintf(['<script type="text/javascript">', ... |
| 51 | + plotlyDomain = plotlyfig.UserData.PlotlyDomain; |
| 52 | + envScript = sprintf(['<script type="text/javascript">', ... |
53 | 53 | 'window.PLOTLYENV=window.PLOTLYENV || {};', ... |
54 | 54 | 'window.PLOTLYENV.BASE_URL="%s";', ... |
55 | 55 | 'Plotly.LINKTEXT="%s";', ... |
56 | | - '</script>'], plotly_domain, link_text); |
| 56 | + '</script>'], plotlyDomain, linkText); |
57 | 57 |
|
58 | 58 | % template Plotly.plot |
59 | 59 | script = sprintf(['\n Plotly.plot("%s", {\n"data": %s,\n"layout": %s,\n"frames": %s\n}).then(function(){'... |
60 | 60 | '\n $(".%s.loading").remove();' ... |
61 | 61 | '\n $(".link--embedview").text("%s");'... |
62 | | - '\n });'], id, clean_jdata, clean_jlayout, clean_jframes,... |
63 | | - id, link_text); |
| 62 | + '\n });'], id, clean_jData, clean_jLayout, clean_jFrames,... |
| 63 | + id, linkText); |
64 | 64 |
|
65 | | - plotly_script = sprintf(['\n<div id="%s" style="height: %s;',... |
| 65 | + plotlyScript = sprintf(['\n<div id="%s" style="height: %s;',... |
66 | 66 | 'width: %s;" class="plotly-graph-div">' ... |
67 | 67 | '</div> \n<script type="text/javascript">' ... |
68 | 68 | '%s \n</script>'], id, height, width, ... |
69 | 69 | script); |
70 | 70 |
|
71 | 71 | % template entire script |
72 | | - offline_script = [dep_script env_script plotly_script]; |
| 72 | + offlineScript = [depScript envScript plotlyScript]; |
73 | 73 | filename = plotlyfig.PlotOptions.FileName; |
74 | 74 | if iscellstr(filename), filename = sprintf('%s ', filename{:}); end |
75 | 75 |
|
76 | 76 | % remove the whitespace from the filename |
77 | | - clean_filename = filename(filename~=' '); |
78 | | - html_filename = [clean_filename '.html']; |
| 77 | + cleanFilename = filename(filename~=' '); |
| 78 | + htmlFilename = [cleanFilename '.html']; |
79 | 79 |
|
80 | 80 | % save the html file in the working directory |
81 | | - plotly_offline_file = fullfile(plotlyfig.PlotOptions.SaveFolder, html_filename); |
82 | | - file_id = fopen(plotly_offline_file, 'w'); |
83 | | - fprintf(file_id, offline_script); |
84 | | - fclose(file_id); |
| 81 | + plotlyOfflineFile = fullfile(plotlyfig.PlotOptions.SaveFolder, htmlFilename); |
| 82 | + fileID = fopen(plotlyOfflineFile, 'w'); |
| 83 | + fprintf(fileID, offlineScript); |
| 84 | + fclose(fileID); |
85 | 85 |
|
86 | | - % remove any whitespace from the plotly_offline_file path |
87 | | - plotly_offline_file = strrep(plotly_offline_file, ' ', '%20'); |
| 86 | + % remove any whitespace from the plotlyOfflineFile path |
| 87 | + plotlyOfflineFile = strrep(plotlyOfflineFile, ' ', '%20'); |
88 | 88 |
|
89 | 89 | % return the local file url to be rendered in the browser |
90 | | - response = ['file:///' plotly_offline_file]; |
| 90 | + response = ['file:///' plotlyOfflineFile]; |
91 | 91 |
|
92 | 92 | end |
0 commit comments