Skip to content

Commit 554f627

Browse files
committed
update plotlyfig class to use plotlyoffline
1 parent 29263e6 commit 554f627

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

plotly/plotlyfig.m

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
obj.PlotOptions.Strip = true;
6060
obj.PlotOptions.Visible = 'on';
6161

62+
% offline options
63+
obj.PlotOptions.Offline = false;
64+
obj.PlotOptions.ShowLinkText = true;
65+
obj.PlotOptions.LinkText = obj.get_link_text;
66+
6267
%-PlotlyDefaults-%
6368
obj.PlotlyDefaults.MinTitleMargin = 80;
6469
obj.PlotlyDefaults.TitleHeight = 0.01;
@@ -163,6 +168,15 @@
163168
if(strcmpi(varargin{a},'visible'))
164169
obj.PlotOptions.Visible = varargin{a+1};
165170
end
171+
if(strcmpi(varargin{a},'offline'))
172+
obj.PlotOptions.Offline = varargin{a+1};
173+
end
174+
if(strcmpi(varargin{a},'showlink'))
175+
obj.PlotOptions.ShowLinkText = varargin{a+1};
176+
end
177+
if(strcmpi(varargin{a},'linktext'))
178+
obj.PlotOptions.LinkText = varargin{a+1};
179+
end
166180
if(strcmpi(varargin{a},'layout'))
167181
obj.layout= varargin{a+1};
168182
end
@@ -414,23 +428,24 @@ function validate(obj)
414428
args.layout = obj.layout;
415429

416430
%send to plotly
417-
response = plotly(obj.data,args);
418-
419-
%update response
420-
obj.url = response.url;
421-
obj.error = response.error;
422-
obj.warning = response.warning;
423-
obj.message = response.message;
424-
425-
%ouput url as hyperlink in command window if possible
426-
if obj.PlotOptions.ShowURL
427-
openurl(response.url);
428-
end
429-
430-
%open url in browser
431-
if obj.PlotOptions.OpenURL
432-
web(response.url, '-browser');
433-
end
431+
if ~obj.PlotOptions.Offline
432+
response = plotly(obj.data, args);
433+
434+
%update response
435+
obj.url = response.url;
436+
obj.error = response.error;
437+
obj.warning = response.warning;
438+
obj.message = response.message;
439+
440+
%open url in browser
441+
if obj.PlotOptions.OpenURL
442+
web(response.url, '-browser');
443+
end
444+
else
445+
obj.url = plotlyoffline(obj);
446+
web(obj.url, '-browser');
447+
end
448+
434449
end
435450

436451
%-----------------------FIGURE CONVERSION-------------------------%
@@ -866,5 +881,12 @@ function delete(obj)
866881
end
867882
end
868883
end
884+
885+
function link_text = get_link_text(obj)
886+
plotly_domain = obj.UserData.PlotlyDomain;
887+
link_domain = strrep(plotly_domain, 'https://', '');
888+
link_domain = strrep(link_domain, 'http://', '');
889+
link_text = ['Export to ' link_domain];
890+
end
869891
end
870892
end

0 commit comments

Comments
 (0)