Skip to content

Commit d4683dc

Browse files
committed
Added option WriteFile (default: true) to plotlyfig() and plotly()
1 parent 89519b4 commit d4683dc

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

plotly/plotly_aux/plotly.m

+18-8
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,37 @@
1111
% For full documentation and examples, see https://plot.ly/api
1212
origin = 'plot';
1313
offline_given = true;
14+
writeFile=true;
1415

1516
if isstruct(varargin{end})
1617
structargs = varargin{end};
17-
f = lower(fieldnames(structargs));
18-
19-
if any(strcmp('offline', f))
20-
offline = structargs.offline;
18+
f = fieldnames(structargs);
19+
20+
idx = cellfun(@(x) strcmpi(x,'offline'), f);
21+
if sum(idx)==1
22+
offline = structargs.(f{idx});
2123
offline_given = offline;
2224
else
2325
offline = false;
2426
offline_given = offline;
2527
end
2628

27-
if ~any(strcmp('filename',f))
29+
if ~any(strcmp('filename',lower(f)))
2830
if offline
2931
structargs.filename = 'untitled';
3032
else
3133
structargs.filename = NaN;
3234
end
3335
end
34-
if ~any(strcmp('fileopt',f))
36+
if ~any(strcmp('fileopt',lower(f)))
3537
structargs.fileopt = NaN;
3638
end
37-
39+
40+
idx = cellfun(@(x) strcmpi(x,'writefile'),f);
41+
if sum(idx)==1
42+
writeFile=structargs.(f{idx});
43+
end
44+
3845
args = varargin(1:(end-1));
3946

4047
else
@@ -46,6 +53,10 @@
4653
args = varargin(1:end);
4754
end
4855

56+
if ~writeFile
57+
offline_given = true;
58+
end
59+
4960
if offline_given
5061
obj = plotlyfig(args, structargs);
5162
obj.layout.width = 840;
@@ -55,5 +66,4 @@
5566
response = makecall(args, origin, structargs);
5667
end
5768

58-
5969
end

plotly/plotlyfig.m

+26-21
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
obj.PlotOptions.ShowURL = true;
4848
obj.PlotOptions.OpenURL = true;
4949
obj.PlotOptions.Strip = false;
50+
obj.PlotOptions.WriteFile = true;
5051
obj.PlotOptions.Visible = 'on';
5152
obj.PlotOptions.TriangulatePatch = false;
5253
obj.PlotOptions.StripMargins = false;
@@ -200,6 +201,9 @@
200201
if(strcmpi(varargin{a},'strip'))
201202
obj.PlotOptions.Strip = varargin{a+1};
202203
end
204+
if(strcmpi(varargin{a},'writeFile'))
205+
obj.PlotOptions.WriteFile = varargin{a+1};
206+
end
203207
if(strcmpi(varargin{a},'visible'))
204208
obj.PlotOptions.Visible = varargin{a+1};
205209
end
@@ -512,27 +516,28 @@ function validate(obj)
512516
%layout
513517
args.layout = obj.layout;
514518

515-
%send to plotly
516-
if ~obj.PlotOptions.Offline
517-
response = plotly(obj.data, args);
518-
519-
%update response
520-
obj.url = response.url;
521-
obj.error = response.error;
522-
obj.warning = response.warning;
523-
obj.message = response.message;
524-
525-
%open url in browser
526-
if obj.PlotOptions.OpenURL
527-
web(response.url, '-browser');
528-
end
529-
else
530-
obj.url = plotlyoffline(obj);
531-
if obj.PlotOptions.OpenURL
532-
web(obj.url, '-browser');
533-
end
534-
end
535-
519+
if obj.PlotOptions.WriteFile
520+
%send to plotly
521+
if ~obj.PlotOptions.Offline
522+
response = plotly(obj.data, args);
523+
524+
%update response
525+
obj.url = response.url;
526+
obj.error = response.error;
527+
obj.warning = response.warning;
528+
obj.message = response.message;
529+
530+
%open url in browser
531+
if obj.PlotOptions.OpenURL
532+
web(response.url, '-browser');
533+
end
534+
else
535+
obj.url = plotlyoffline(obj);
536+
if obj.PlotOptions.OpenURL
537+
web(obj.url, '-browser');
538+
end
539+
end
540+
end
536541
end
537542

538543
%-----------------------FIGURE CONVERSION-------------------------%

0 commit comments

Comments
 (0)