@@ -2,8 +2,7 @@ function plotlysetup_offline(plotly_bundle_url, varargin)
22 % CALL: plotlysetup_offline(plotly_bundle_url);
33 % WHERE: plotly_bundle_url is the plotly bundle url, e.g. https://cdn.plot.ly/plotly-2.35.3.min.js
44 % If no argument is provided, the default https://cdn.plot.ly/plotly-2.35.3.min.js is used.
5- % [1] adds plotly api to matlabroot/toolboxes. If successful do [2]
6- % [2] adds plotly api to searchpath via startup.m of matlabroot and/or userpath
5+ % [1] adds plotly api to search path and saves it via savepath
76
87 % DEFAULT OUTPUT
98 exception.message = ' ' ;
@@ -41,94 +40,11 @@ function plotlysetup_offline(plotly_bundle_url, varargin)
4140 return
4241 end
4342
44- if ~is_octave
45- try
46- % embed the api to the matlabroot/toolbox dir.
47- fprintf(' \n Adding Plotly to MATLAB toolbox directory ... ' );
48-
49- % plotly folder in the matlab/toolbox dir.
50- plotlyToolboxPath = fullfile(matlabroot ,' toolbox' ,' plotly' );
51-
52- if exist(plotlyToolboxPath ,' dir' ) % check for overwrite...
53- fprintf([' \n\n [UPDATE]: \n\n Hey! We see that a copy of Plotly has previously been added to\n ' ...
54- ' your Matlab toolboxes. Would you like us to overwrite it with:\n ' plotlyFolderPath ' ? \n ' ...
55- ' Careful! You may lose data saved to this Plotly directory.\n\n ' ]);
56-
57- overwrite = input(' Overwrite (y/n) ? : ' ,' s' );
58-
59- if (strcmpi(overwrite ,' y' ));
60- fprintf(' \n [OVERWRITE]:\n\n Overwriting Plotly! ... Done \n ' );
61- else
62- fprintf(' \n [NO OVERWRITE]:\n\n Did not overwrite Plotly! ... Done \n ' );
63- end
64- else % toolbox Plotly not yet created
65- % worked (without interruption)...just a formatting thing!
66- fprintf(' Done\n ' );
67-
68- % make the plotlyToolboxPath dir.
69- status = mkdir(plotlyToolboxPath );
70-
71- % set status to overwrite
72- overwrite = ' y' ;
73-
74- % check that the folder was created
75- if (status == 0 )
76- error(' plotly:savePlotly' , permissionMessage(' save the Plotly folder' ));
77- end
78- end
79-
80- if strcmpi(overwrite ,' y' )
81- % move a copy of the Plotly api to matlab root directory
82- [status , msg , messid ] = copyfile(plotlyFolderPath ,plotlyToolboxPath );
83- % check that the plotly api was copied to the matlab root toolbox directory
84- if (status == 0 )
85- if (~strcmp(messid , ' MATLAB:COPYFILE:SourceAndDestinationSame' ))
86- error(' plotly:copyPlotly' ,permissionMessage(' copy the Plotly folder' ));
87- end
88- end
89- end
90-
91- % add it to the searchpath (startup.m will handle this next time!)
92- addpath(genpath(plotlyToolboxPath ),' -end' );
93-
94- % save plotly api searchpath to startup.m files (only do this if we actually were able to store the api in mtlroot/toolbox!)
95- fprintf(' Saving Plotly to MATLAB search path via startup.m ... ' );
96-
97- % check for a startup.m file in matlab rootpath (we want to add one here)
98- startupFile = [];
99- startupFileRootPath = fullfile(matlabroot ,' toolbox' ,' local' ,' startup.m' );
100- if ~exist(startupFileRootPath ,' file' )
101- startFileID = fopen(startupFileRootPath , ' w' );
102- % startup.m does not exist and startupFilePath is non-writable
103- if (startFileID == - 1 )
104- error(' plotly:rootStartupCreation' ,permissionMessage(' write the startup.m script' ));
105- end
106- startupFile = {startupFileRootPath }; % needed because MATLAB only looks for startup.m when first opened.
107- end
108-
109- % check for all startup.m file in searchpath
110- startupFile = [startupFile ; cell(which(' startup.m' ,' -all' ))];
111- % write the addpath - plotly api to the startup.m files
112- [warnings ] = addplotlystartup(startupFile );
113-
114- % worked!
115- fprintf(' Done\n ' );
116-
117- % print any addplotlydstatup warnings;
118- w = cellfun(@isempty ,warnings );
119- if find(~w )
120- % output warnings
121- exception.warnings = warnings ;
122- fprintf(warnings{find(~w )});
123- end
124-
125- catch exception % copying to toolbox/writing to startup.m permission problem catch...
126- fprintf([' \n\n ' exception .identifier exception .message ' \n\n ' ]);
127- end
128-
129- else % if octave
130- fprintf(' \n\n Octave users: Automatic Plotly API embedding coming soon!\n\n ' );
131- end % end check for matlab...
43+ % Save search path so Plotly remains available in future sessions
44+ try
45+ savepath ;
46+ catch
47+ end
13248
13349 % get offline bundle
13450 fprintf(' \n Now downloading the plotly offline bundle ...' );
@@ -137,13 +53,3 @@ function plotlysetup_offline(plotly_bundle_url, varargin)
13753 % greet the people!
13854 fprintf(' \n Welcome to Plotly! If you are new to Plotly please enter: >> plotlyhelp to get started!\n\n ' )
13955end
140-
141- % helper message function
142- function message = permissionMessage(spec )
143- message = [' \n\n Shoot! We tried to ' spec ' to the MATLAB toolbox \n ' ,...
144- ' directory, but were denied write permission. You'' ll have to add\n ' ,...
145- ' the Plotly folder to your MATLAB path manually by running: \n\n ' ,...
146- ' >> plotly_path = fullfile(pwd, '' plotly'' )\n ' ,...
147- ' >> addpath(genpath(plotly_path))\n\n ' ,...
148- ' Questions? Ask https://community.plotly.com/c/api/matlab/\n\n ' ];
149- end
0 commit comments