forked from plotly/plotly_matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetplotlyoffline.m
More file actions
38 lines (32 loc) · 1.37 KB
/
getplotlyoffline.m
File metadata and controls
38 lines (32 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function getplotlyoffline(plotly_bundle_url)
% download bundle
[plotly_bundle, extras] = urlread2(plotly_bundle_url, 'get');
% handle response
if ~extras.isGood
error(['Whoops! There was an error attempting to ', ...
'download the MATLAB offline Plotly ', ...
'bundle. Status: %s %s.'], ...
num2str(extras.status.value), extras.status.msg);
end
% create Plotly config folder
userhome = getuserdir();
plotly_config_folder = fullfile(userhome, '.plotly');
[status, mess, messid] = mkdir(plotly_config_folder);
validatedir(status, mess, messid, 'plotly');
% create plotlyjs folder
plotly_js_folder = fullfile(plotly_config_folder, 'plotlyjs');
[status, mess, messid] = mkdir(plotly_js_folder);
validatedir(status, mess, messid, 'plotlyjs');
% save bundle
bundle = escapechars(plotly_bundle);
bundle_name = 'plotly-matlab-offline-bundle.js';
bundle_file = fullfile(plotly_js_folder, bundle_name);
file_id = fopen(bundle_file, 'w');
fprintf(file_id, '%s', bundle);
fclose(file_id);
% success!
fprintf(['\nSuccess! You can generate your first offline ', ...
'graph\nusing the ''offline'' flag of fig2plotly as ', ...
'follows:\n\n>> plot(1:10); fig2plotly(gcf, ', ...
'''offline'', true);\n\n'])
end