Skip to content

Commit 89519b4

Browse files
committed
Merged Fig <-> Nofig, now truely offline
1 parent b89336d commit 89519b4

File tree

4 files changed

+47
-1007
lines changed

4 files changed

+47
-1007
lines changed

plotly/plotly_aux/plotly.m

+6-18
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@
1111
% For full documentation and examples, see https://plot.ly/api
1212
origin = 'plot';
1313
offline_given = true;
14-
struct_provided = false;
1514

1615
if isstruct(varargin{end})
1716
structargs = varargin{end};
1817
f = lower(fieldnames(structargs));
1918

2019
if any(strcmp('offline', f))
21-
offline = getfield(structargs, 'offline');
20+
offline = structargs.offline;
2221
offline_given = offline;
2322
else
2423
offline = false;
2524
offline_given = offline;
2625
end
2726

28-
2927
if ~any(strcmp('filename',f))
3028
if offline
3129
structargs.filename = 'untitled';
@@ -36,33 +34,23 @@
3634
if ~any(strcmp('fileopt',f))
3735
structargs.fileopt = NaN;
3836
end
39-
40-
41-
struct_provided = true;
4237

4338
args = varargin(1:(end-1));
4439

4540
else
46-
4741
if offline_given
4842
structargs = struct('filename', 'untitled', 'fileopt', NaN);
4943
else
50-
structargs = struct('filename', NaN,'fileopt',NaN);
44+
structargs = struct('filename', NaN, 'fileopt', NaN);
5145
end
5246
args = varargin(1:end);
53-
struct_provided = false;
5447
end
5548

5649
if offline_given
57-
if (struct_provided)
58-
nofig_obj = plotlynofig(varargin{1:end-1}, structargs);
59-
else
60-
nofig_obj = plotlynofig(varargin{1:end}, structargs);
61-
end
62-
nofig_obj.layout.width = 840;
63-
nofig_obj.layout.height = 630;
64-
response = nofig_obj.plotly;
65-
50+
obj = plotlyfig(args, structargs);
51+
obj.layout.width = 840;
52+
obj.layout.height = 630;
53+
response = obj.plotly;
6654
else
6755
response = makecall(args, origin, structargs);
6856
end

plotly/plotly_offline_aux/plotlyoffline.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@
8585
plotly_offline_file = strrep(plotly_offline_file, ' ', '%20');
8686

8787
% return the local file url to be rendered in the browser
88-
response = ['file://' plotly_offline_file];
88+
response = ['file:///' plotly_offline_file];
8989

9090
end

plotly/plotlyfig.m

+40-23
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
%----CONSTRUCTOR---%
3333
function obj = plotlyfig(varargin)
34-
34+
3535
%-Core-%
3636
obj.data = {};
3737
obj.layout = struct();
@@ -73,7 +73,8 @@
7373
obj.UserData.ApiKey,...
7474
obj.UserData.PlotlyDomain] = signin;
7575
catch
76-
if obj.PlotOptions.Offline
76+
idx=find(cellfun(@(x) strcmpi(x,'offline'), varargin))+1;
77+
if (nargin>1 && ~isempty(idx) && varargin{idx}) || (obj.PlotOptions.Offline)
7778
obj.UserData.Username = 'offlineUser';
7879
obj.UserData.ApiKey = '';
7980
obj.UserData.PlotlyDomain = 'https://plot.ly';
@@ -127,6 +128,8 @@
127128
% initialize autoupdate key
128129
updatekey = false;
129130

131+
noFig = false;
132+
130133
% parse inputs
131134
switch nargin
132135

@@ -152,6 +155,16 @@
152155
updatekey = true;
153156
parseinit = 2;
154157
end
158+
elseif iscell(varargin{1}) && isstruct(varargin{2})
159+
obj.data = varargin{1}{:};
160+
structargs = varargin{2};
161+
ff=fieldnames(structargs);
162+
for i=1:length(ff)
163+
varargin{2*i-1}=ff{i};
164+
varargin{2*i}=structargs.(ff{i});
165+
end
166+
noFig=true;
167+
parseinit = 1;
155168
else
156169
parseinit = 1;
157170
end
@@ -163,7 +176,7 @@
163176
end
164177

165178
% parse property/values
166-
for a = parseinit:2:nargin
179+
for a = parseinit:2:length(varargin)
167180
if(strcmpi(varargin{a},'filename'))
168181
obj.PlotOptions.FileName = varargin{a+1};
169182
% overwrite if filename provided
@@ -235,32 +248,36 @@
235248
end
236249
end
237250

238-
% create figure/axes if empty
239-
if isempty(fig_han)
240-
fig_han = figure;
241-
axes;
251+
if ~noFig
252+
% create figure/axes if empty
253+
if isempty(fig_han)
254+
fig_han = figure;
255+
axes;
256+
end
257+
258+
% plotly figure default style
259+
set(fig_han,'Name',obj.PlotOptions.FileName,'Color',[1 1 1],'NumberTitle','off', 'Visible', obj.PlotOptions.Visible);
260+
261+
% figure state
262+
obj.State.Figure.Handle = fig_han;
242263
end
243264

244-
% plotly figure default style
245-
set(fig_han,'Name',obj.PlotOptions.FileName,'Color',[1 1 1],'NumberTitle','off', 'Visible', obj.PlotOptions.Visible);
246-
247-
% figure state
248-
obj.State.Figure.Handle = fig_han;
249-
250265
% update
251266
if updatekey
252267
obj.update;
253268
end
254269

255-
% add figure listeners
256-
addlistener(obj.State.Figure.Handle,'Visible','PostSet',@(src,event)updateFigureVisible(obj,src,event));
257-
addlistener(obj.State.Figure.Handle,'Name','PostSet',@(src,event)updateFigureName(obj,src,event));
258-
259-
% add plot options listeners
260-
addlistener(obj,'PlotOptions','PostSet',@(src,event)updatePlotOptions(obj,src,event));
261-
262-
% add user data listeners
263-
addlistener(obj,'UserData','PostSet',@(src,event)updateUserData(obj,src,event));
270+
if ~noFig
271+
% add figure listeners
272+
addlistener(obj.State.Figure.Handle,'Visible','PostSet',@(src,event)updateFigureVisible(obj,src,event));
273+
addlistener(obj.State.Figure.Handle,'Name','PostSet',@(src,event)updateFigureName(obj,src,event));
274+
275+
% add plot options listeners
276+
addlistener(obj,'PlotOptions','PostSet',@(src,event)updatePlotOptions(obj,src,event));
277+
278+
% add user data listeners
279+
addlistener(obj,'UserData','PostSet',@(src,event)updateUserData(obj,src,event));
280+
end
264281
end
265282

266283
%-------------------------USER METHODS----------------------------%
@@ -498,7 +515,7 @@ function validate(obj)
498515
%send to plotly
499516
if ~obj.PlotOptions.Offline
500517
response = plotly(obj.data, args);
501-
518+
502519
%update response
503520
obj.url = response.url;
504521
obj.error = response.error;

0 commit comments

Comments
 (0)