|
31 | 31 |
|
32 | 32 | %----CONSTRUCTOR---% |
33 | 33 | function obj = plotlyfig(varargin) |
34 | | - |
| 34 | + |
35 | 35 | %-Core-% |
36 | 36 | obj.data = {}; |
37 | 37 | obj.layout = struct(); |
|
73 | 73 | obj.UserData.ApiKey,... |
74 | 74 | obj.UserData.PlotlyDomain] = signin; |
75 | 75 | 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) |
77 | 78 | obj.UserData.Username = 'offlineUser'; |
78 | 79 | obj.UserData.ApiKey = ''; |
79 | 80 | obj.UserData.PlotlyDomain = 'https://plot.ly'; |
|
127 | 128 | % initialize autoupdate key |
128 | 129 | updatekey = false; |
129 | 130 |
|
| 131 | + noFig = false; |
| 132 | + |
130 | 133 | % parse inputs |
131 | 134 | switch nargin |
132 | 135 |
|
|
152 | 155 | updatekey = true; |
153 | 156 | parseinit = 2; |
154 | 157 | 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; |
155 | 168 | else |
156 | 169 | parseinit = 1; |
157 | 170 | end |
|
163 | 176 | end |
164 | 177 |
|
165 | 178 | % parse property/values |
166 | | - for a = parseinit:2:nargin |
| 179 | + for a = parseinit:2:length(varargin) |
167 | 180 | if(strcmpi(varargin{a},'filename')) |
168 | 181 | obj.PlotOptions.FileName = varargin{a+1}; |
169 | 182 | % overwrite if filename provided |
|
235 | 248 | end |
236 | 249 | end |
237 | 250 |
|
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; |
242 | 263 | end |
243 | 264 |
|
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 | | - |
250 | 265 | % update |
251 | 266 | if updatekey |
252 | 267 | obj.update; |
253 | 268 | end |
254 | 269 |
|
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 |
264 | 281 | end |
265 | 282 |
|
266 | 283 | %-------------------------USER METHODS----------------------------% |
@@ -498,7 +515,7 @@ function validate(obj) |
498 | 515 | %send to plotly |
499 | 516 | if ~obj.PlotOptions.Offline |
500 | 517 | response = plotly(obj.data, args); |
501 | | - |
| 518 | + |
502 | 519 | %update response |
503 | 520 | obj.url = response.url; |
504 | 521 | obj.error = response.error; |
|
0 commit comments