Skip to content

Commit a94a5ed

Browse files
Merge branch 'master' into fixing_issue_197
2 parents be4e5a1 + a460022 commit a94a5ed

File tree

5 files changed

+404
-23
lines changed

5 files changed

+404
-23
lines changed

plotly/plotly_offline_aux/getplotlyoffline.m

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ function getplotlyoffline(plotly_bundle_url)
3131
fclose(file_id);
3232

3333
% success!
34-
fprintf(['\nSuccess! You can generate your first offline ', ...
35-
'graph\nusing the ''offline'' flag of fig2plotly as ', ...
34+
fprintf(['\nSuccess! You can now generate offline ', ...
35+
'graphs.\nTo generate online graphs, run plotlysetup_online(username, api_key) ', ...
36+
'\nand use the ''offline'' flag of fig2plotly as ', ...
3637
'follows:\n\n>> plot(1:10); fig2plotly(gcf, ', ...
37-
'''offline'', true);\n\n'])
38+
'''offline'', false);\n\n'])
3839
end

plotly/plotlyfig.m

+9-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
obj.PlotOptions.TriangulatePatch = false;
6262

6363
% offline options
64-
obj.PlotOptions.Offline = false;
64+
obj.PlotOptions.Offline = true;
6565
obj.PlotOptions.ShowLinkText = true;
6666
obj.PlotOptions.LinkText = obj.get_link_text;
6767
obj.PlotOptions.IncludePlotlyjs = true;
@@ -267,7 +267,10 @@
267267

268268
% strip the style keys from data
269269
for d = 1:length(obj.data)
270-
if strcmpi(obj.data{d}.type, 'scatter') || strcmpi(obj.data{d}.type, 'histogram')
270+
if ( ...
271+
strcmpi(obj.data{d}.type, 'scatter') || ...
272+
strcmpi(obj.data{d}.type, 'bar') ...
273+
)
271274
return
272275
end
273276
obj.data{d} = obj.stripkeys(obj.data{d}, obj.data{d}.type, 'style');
@@ -892,7 +895,10 @@ function delete(obj)
892895
catch exception
893896
if obj.UserData.Verbose
894897
% catch 3D output until integrated into graphref
895-
if ~(strcmpi(fieldname,'surface') || strcmpi(fieldname,'scatter3d') || strcmpi(fieldname,'mesh3d'))
898+
if ~( ...
899+
strcmpi(fieldname,'surface') || strcmpi(fieldname,'scatter3d') ...
900+
|| strcmpi(fieldname,'mesh3d') || strcmpi(fieldname,'bar') ...
901+
)
896902
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']);
897903
end
898904
end

plotly/plotlyfig_aux/handlegraphics/updateHistogram.m

+6-17
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,8 @@
7373

7474
%-------------------------------------------------------------------------%
7575

76-
%-hist type-%
77-
obj.data{histIndex}.type = 'histogram';
78-
79-
%-------------------------------------------------------------------------%
80-
81-
%-HIST XAXIS-%
82-
obj.data{histIndex}.histfunc= 'count';
76+
%-bar type-%
77+
obj.data{histIndex}.type = 'bar';
8378

8479
%-------------------------------------------------------------------------%
8580

@@ -93,19 +88,13 @@
9388

9489
switch orientation
9590
case {'vertical', 'horizontal'}
96-
% histogram()
97-
98-
obj.data{histIndex}.x = sort(hist_data.Data.');
99-
obj.data{histIndex}.autobinx = false;
100-
101-
obj.data{histIndex}.xbins.start = hist_data.BinEdges(1);
102-
obj.data{histIndex}.xbins.end = hist_data.BinEdges(end);
103-
obj.data{histIndex}.xbins.size = mean(hist_data.BinEdges(2:end)-hist_data.BinEdges(1:end-1));
10491

10592
%-------------------------------------------------------------------------%
93+
%-hist y data-%
10694

107-
%-layout bargap-%
108-
obj.layout.bargap = 0;
95+
obj.data{histIndex}.x = hist_data.BinEdges(1:end-1) + 0.5*diff(hist_data.BinEdges);
96+
obj.data{histIndex}.width = diff(hist_data.BinEdges);%[hist_data.BinEdges(2:end), hist_data.Data(end)];
97+
obj.data{histIndex}.y = double(hist_data.BinCounts);
10998

11099
%-------------------------------------------------------------------------%
111100

plotlysetup_offline.m

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
function plotlysetup_offline(plotly_bundle_url, varargin)
2+
3+
% CALL: plotlysetup_offline(plotly_bundle_url);
4+
% WHERE: plotly_bundle_url is the plotly bundle url, e.g. http://cdn.plot.ly/plotly-latest.min.js
5+
% If no argument is provided, the default http://cdn.plot.ly/plotly-latest.min.js is used.
6+
% [1] adds plotly api to matlabroot/toolboxes. If successful do [2]
7+
% [2] adds plotly api to searchpath via startup.m of matlabroot and/or userpath
8+
9+
%DEFAULT OUTPUT
10+
exception.message = '';
11+
exception.identifier = '';
12+
13+
try %check number of inputs
14+
if(nargin == 0)
15+
plotly_bundle_url = 'http://cdn.plot.ly/plotly-latest.min.js';
16+
elseif (nargin>1)
17+
error('plotly:wrongInput',....
18+
['\n\nWhoops! Wrong number of inputs. Please run >> help plotlysetup_offline \n',...
19+
'for more information regarding the setup your Plotly API MATLAB \n',...
20+
'Library. Please contact [email protected] for more information.']);
21+
end
22+
catch exception %plotlysetup input problem catch...
23+
fprintf(['\n\n' exception.identifier exception.message '\n\n']);
24+
return
25+
end
26+
27+
try
28+
%check to see if plotly is in the searchpath
29+
plotlysetupPath = which('plotlysetup');
30+
plotlyFolderPath = fullfile(fileparts(plotlysetupPath),'plotly');
31+
%if it was not found
32+
if (strcmp(genpath(plotlyFolderPath),''))
33+
error('plotly:notFound',...
34+
['\n\nShoot! It looks like MATLAB is having trouble finding the current version ' ...
35+
'\nof Plotly. Please make sure that the Plotly API folder is in the same ' ...
36+
'\ndirectory as plotlysetup.m. Questions? [email protected]\n\n']);
37+
end
38+
%add Plotly API MATLAB Library to search path
39+
addpath(genpath(plotlyFolderPath));
40+
catch exception %plotly file not found problem catch
41+
fprintf(['\n\n' exception.identifier exception.message '\n']);
42+
return
43+
end
44+
45+
if(~is_octave)
46+
47+
try
48+
%embed the api to the matlabroot/toolbox dir.
49+
fprintf('\nAdding Plotly to MATLAB toolbox directory ... ');
50+
51+
%plotly folder in the matlab/toolbox dir.
52+
plotlyToolboxPath = fullfile(matlabroot,'toolbox','plotly');
53+
54+
if(exist(plotlyToolboxPath,'dir')) %check for overwrite...
55+
fprintf(['\n\n[UPDATE]: \n\nHey! We see that a copy of Plotly has previously been added to\n' ...
56+
'your Matlab toolboxes. Would you like us to overwrite it with:\n' plotlyFolderPath ' ? \n'...
57+
'Careful! You may lose data saved to this Plotly directory.\n\n']);
58+
59+
overwrite = input('Overwrite (y/n) ? : ','s');
60+
61+
if(strcmpi(overwrite,'y'));
62+
fprintf('\n[OVERWRITE]:\n\nOverwriting Plotly! ... Done \n');
63+
else
64+
fprintf('\n[NO OVERWRITE]:\n\nDid not overwrite Plotly! ... Done \n');
65+
end
66+
else %toolbox Plotly not yet created
67+
68+
%worked (without interuption)...just a formatting thing!
69+
fprintf('Done\n');
70+
71+
%make the plotlyToolboxPath dir.
72+
status = mkdir(plotlyToolboxPath);
73+
74+
%set status to overwrite
75+
overwrite = 'y';
76+
77+
%check that the folder was created
78+
if (status == 0)
79+
error('plotly:savePlotly', permissionMessage('save the Plotly folder'));
80+
end
81+
end
82+
83+
if(strcmpi(overwrite,'y'))
84+
85+
%move a copy of the Plotly api to matlab root directory
86+
[status, msg, messid] = copyfile(plotlyFolderPath,plotlyToolboxPath);
87+
%check that the plotly api was copied to the matlab root toolbox directory
88+
if (status == 0)
89+
if(~strcmp(messid, 'MATLAB:COPYFILE:SourceAndDestinationSame'))
90+
error('plotly:copyPlotly',permissionMessage('copy the Plotly folder'));
91+
end
92+
end
93+
94+
end
95+
96+
%add it to the searchpath (startup.m will handle this next time!)
97+
addpath(genpath(plotlyToolboxPath),'-end');
98+
99+
%save plotly api searchpath to startup.m files (only do this if we actually were able to store the api in mtlroot/toolbox!)
100+
fprintf('Saving Plotly to MATLAB search path via startup.m ... ');
101+
102+
%check for a startup.m file in matlab rootpath (we want to add one here)
103+
startupFile = [];
104+
startupFileRootPath = fullfile(matlabroot,'toolbox','local','startup.m');
105+
if(~exist(startupFileRootPath,'file'))
106+
startFileID = fopen(startupFileRootPath, 'w');
107+
%startup.m does not exist and startupFilePath is non-writable
108+
if(startFileID == -1)
109+
error('plotly:rootStartupCreation',permissionMessage('write the startup.m script'));
110+
end
111+
startupFile = {startupFileRootPath}; %needed because MATLAB only looks for startup.m when first opened.
112+
end
113+
114+
%check for all startup.m file in searchpath
115+
startupFile = [startupFile; cell(which('startup.m','-all'))];
116+
%write the addpath - plotly api to the startup.m files
117+
[warnings] = addplotlystartup(startupFile);
118+
119+
%worked!
120+
fprintf(' Done\n');
121+
122+
%print any addplotlydstatup warnings;
123+
w = cellfun(@isempty,warnings);
124+
if(find(~w))
125+
%output warnings
126+
exception.warnings = warnings;
127+
fprintf(warnings{find(~w)});
128+
end
129+
130+
catch exception %copying to toolbox/writing to startup.m permission problem catch...
131+
fprintf(['\n\n' exception.identifier exception.message '\n\n']);
132+
end
133+
134+
else %if octave
135+
fprintf('\n\nOctave users: Automatic Plotly API embedding coming soon!\n\n');
136+
end %end check for matlab...
137+
138+
%get offline bundle
139+
fprintf('\nNow downloading the plotly offline bundle ...');
140+
getplotlyoffline(plotly_bundle_url);
141+
142+
%greet the people!
143+
fprintf('\nWelcome to Plotly! If you are new to Plotly please enter: >> plotlyhelp to get started!\n\n')
144+
145+
end
146+
147+
%helper message function
148+
function message = permissionMessage(spec)
149+
message = ['\n\nShoot! We tried to ' spec ' to the MATLAB toolbox \n',...
150+
'directory, but were denied write permission. You''ll have to add\n',...
151+
'the Plotly folder to your MATLAB path manually by running: \n\n',...
152+
'>> plotly_path = fullfile(pwd, ''plotly'')\n',...
153+
'>> addpath(genpath(plotly_path))\n\n',...
154+
'Questions? Chuck@plotly\n\n'];
155+
end
156+
157+

0 commit comments

Comments
 (0)