Skip to content

Commit b7b19ef

Browse files
Tom ClarkTom Clark
Tom Clark
authored and
Tom Clark
committed
Added -norender flag option to plotlyfig
1 parent 652c35f commit b7b19ef

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

plotly/plotly_offline_aux/plotlyoffline.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
'window.PLOTLYENV.BASE_URL="%s";', ...
5656
'Plotly.LINKTEXT="%s";', ...
5757
'</script>'], plotly_domain, link_text);
58-
58+
5959
% template Plotly.plot
6060
script = sprintf(['\n Plotly.plot("%s", %s, %s).then(function(){'...
6161
'\n $(".%s.loading").remove();' ...

plotly/plotlyfig.m

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
properties (SetObservable)
1515
UserData;% credentials/configuration/verbose
1616
PlotOptions; % filename,fileopt,world_readable
17+
RenderFig = true; % uses matlab figure rendering to allow use of the matlab API instead of direct creation using plotly native
1718
end
1819

1920
properties (Hidden = true)
@@ -110,6 +111,9 @@
110111
% initialize autoupdate key
111112
updatekey = false;
112113

114+
% initialize render_fig flag
115+
obj.RenderFig = true;
116+
113117
% parse inputs
114118
switch nargin
115119

@@ -121,6 +125,10 @@
121125
fig_han = varargin{1};
122126
updatekey = true;
123127
end
128+
elseif ischar(varargin{1}) && strcmp(varargin{1},'-norender')
129+
obj.RenderFig = false;
130+
updatekey = false;
131+
parseinit = 2;
124132
else
125133
errkey = 'plotlyfigConstructor:invalidInputs';
126134
error(errkey , plotlymsg(errkey));
@@ -135,6 +143,10 @@
135143
updatekey = true;
136144
parseinit = 2;
137145
end
146+
elseif ischar(varargin{1}) && strcmp(varargin{1},'-norender')
147+
obj.RenderFig = false;
148+
updatekey = false;
149+
parseinit = 2;
138150
else
139151
parseinit = 1;
140152
end
@@ -191,32 +203,35 @@
191203
end
192204
end
193205

194-
% create figure/axes if empty
195-
if isempty(fig_han)
196-
fig_han = figure;
197-
axes;
198-
end
199-
200-
% plotly figure default style
201-
set(fig_han,'Name',obj.PlotOptions.FileName,'Color',[1 1 1],'NumberTitle','off', 'Visible', obj.PlotOptions.Visible);
202-
203-
% figure state
204-
obj.State.Figure.Handle = fig_han;
205-
206-
% update
207-
if updatekey
208-
obj.update;
206+
% Only init the figure renderer if the -norender flag is not passed
207+
if obj.RenderFig
208+
% create figure/axes if empty
209+
if isempty(fig_han)
210+
fig_han = figure;
211+
axes;
212+
end
213+
214+
% plotly figure default style
215+
set(fig_han,'Name',obj.PlotOptions.FileName,'Color',[1 1 1],'NumberTitle','off', 'Visible', obj.PlotOptions.Visible);
216+
217+
% figure state
218+
obj.State.Figure.Handle = fig_han;
219+
220+
% update
221+
if updatekey
222+
obj.update;
223+
end
224+
225+
% add figure listeners
226+
addlistener(obj.State.Figure.Handle,'Visible','PostSet',@(src,event)updateFigureVisible(obj,src,event));
227+
addlistener(obj.State.Figure.Handle,'Name','PostSet',@(src,event)updateFigureName(obj,src,event));
228+
229+
% add plot options listeners
230+
addlistener(obj,'PlotOptions','PostSet',@(src,event)updatePlotOptions(obj,src,event));
231+
232+
% add user data listeners
233+
addlistener(obj,'UserData','PostSet',@(src,event)updateUserData(obj,src,event));
209234
end
210-
211-
% add figure listeners
212-
addlistener(obj.State.Figure.Handle,'Visible','PostSet',@(src,event)updateFigureVisible(obj,src,event));
213-
addlistener(obj.State.Figure.Handle,'Name','PostSet',@(src,event)updateFigureName(obj,src,event));
214-
215-
% add plot options listeners
216-
addlistener(obj,'PlotOptions','PostSet',@(src,event)updatePlotOptions(obj,src,event));
217-
218-
% add user data listeners
219-
addlistener(obj,'UserData','PostSet',@(src,event)updateUserData(obj,src,event));
220235
end
221236

222237
%-------------------------USER METHODS----------------------------%

0 commit comments

Comments
 (0)