|
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();
|
|
47 | 47 | obj.PlotOptions.ShowURL = true;
|
48 | 48 | obj.PlotOptions.OpenURL = true;
|
49 | 49 | obj.PlotOptions.Strip = false;
|
| 50 | + obj.PlotOptions.WriteFile = true; |
50 | 51 | obj.PlotOptions.Visible = 'on';
|
51 | 52 | obj.PlotOptions.TriangulatePatch = false;
|
52 | 53 | obj.PlotOptions.StripMargins = false;
|
|
73 | 74 | obj.UserData.ApiKey,...
|
74 | 75 | obj.UserData.PlotlyDomain] = signin;
|
75 | 76 | catch
|
76 |
| - if obj.PlotOptions.Offline |
| 77 | + idx=find(cellfun(@(x) strcmpi(x,'offline'), varargin))+1; |
| 78 | + if (nargin>1 && ~isempty(idx) && varargin{idx}) || (obj.PlotOptions.Offline) |
77 | 79 | obj.UserData.Username = 'offlineUser';
|
78 | 80 | obj.UserData.ApiKey = '';
|
79 | 81 | obj.UserData.PlotlyDomain = 'https://plot.ly';
|
|
127 | 129 | % initialize autoupdate key
|
128 | 130 | updatekey = false;
|
129 | 131 |
|
| 132 | + noFig = false; |
| 133 | + |
130 | 134 | % parse inputs
|
131 | 135 | switch nargin
|
132 | 136 |
|
|
152 | 156 | updatekey = true;
|
153 | 157 | parseinit = 2;
|
154 | 158 | end
|
| 159 | + elseif iscell(varargin{1}) && isstruct(varargin{2}) |
| 160 | + obj.data = varargin{1}{:}; |
| 161 | + structargs = varargin{2}; |
| 162 | + ff=fieldnames(structargs); |
| 163 | + for i=1:length(ff) |
| 164 | + varargin{2*i-1}=ff{i}; |
| 165 | + varargin{2*i}=structargs.(ff{i}); |
| 166 | + end |
| 167 | + noFig=true; |
| 168 | + parseinit = 1; |
155 | 169 | else
|
156 | 170 | parseinit = 1;
|
157 | 171 | end
|
|
163 | 177 | end
|
164 | 178 |
|
165 | 179 | % parse property/values
|
166 |
| - for a = parseinit:2:nargin |
| 180 | + for a = parseinit:2:length(varargin) |
167 | 181 | if(strcmpi(varargin{a},'filename'))
|
168 | 182 | obj.PlotOptions.FileName = varargin{a+1};
|
169 | 183 | % overwrite if filename provided
|
|
187 | 201 | if(strcmpi(varargin{a},'strip'))
|
188 | 202 | obj.PlotOptions.Strip = varargin{a+1};
|
189 | 203 | end
|
| 204 | + if(strcmpi(varargin{a},'writeFile')) |
| 205 | + obj.PlotOptions.WriteFile = varargin{a+1}; |
| 206 | + end |
190 | 207 | if(strcmpi(varargin{a},'visible'))
|
191 | 208 | obj.PlotOptions.Visible = varargin{a+1};
|
192 | 209 | end
|
|
235 | 252 | end
|
236 | 253 | end
|
237 | 254 |
|
238 |
| - % create figure/axes if empty |
239 |
| - if isempty(fig_han) |
240 |
| - fig_han = figure; |
241 |
| - axes; |
| 255 | + if ~noFig |
| 256 | + % create figure/axes if empty |
| 257 | + if isempty(fig_han) |
| 258 | + fig_han = figure; |
| 259 | + axes; |
| 260 | + end |
| 261 | + |
| 262 | + % plotly figure default style |
| 263 | + set(fig_han,'Name',obj.PlotOptions.FileName,'Color',[1 1 1],'NumberTitle','off', 'Visible', obj.PlotOptions.Visible); |
| 264 | + |
| 265 | + % figure state |
| 266 | + obj.State.Figure.Handle = fig_han; |
242 | 267 | end
|
243 | 268 |
|
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 | 269 | % update
|
251 | 270 | if updatekey
|
252 | 271 | obj.update;
|
253 | 272 | end
|
254 | 273 |
|
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)); |
| 274 | + if ~noFig |
| 275 | + % add figure listeners |
| 276 | + addlistener(obj.State.Figure.Handle,'Visible','PostSet',@(src,event)updateFigureVisible(obj,src,event)); |
| 277 | + addlistener(obj.State.Figure.Handle,'Name','PostSet',@(src,event)updateFigureName(obj,src,event)); |
| 278 | + |
| 279 | + % add plot options listeners |
| 280 | + addlistener(obj,'PlotOptions','PostSet',@(src,event)updatePlotOptions(obj,src,event)); |
| 281 | + |
| 282 | + % add user data listeners |
| 283 | + addlistener(obj,'UserData','PostSet',@(src,event)updateUserData(obj,src,event)); |
| 284 | + end |
264 | 285 | end
|
265 | 286 |
|
266 | 287 | %-------------------------USER METHODS----------------------------%
|
@@ -495,27 +516,28 @@ function validate(obj)
|
495 | 516 | %layout
|
496 | 517 | args.layout = obj.layout;
|
497 | 518 |
|
498 |
| - %send to plotly |
499 |
| - if ~obj.PlotOptions.Offline |
500 |
| - response = plotly(obj.data, args); |
501 |
| - |
502 |
| - %update response |
503 |
| - obj.url = response.url; |
504 |
| - obj.error = response.error; |
505 |
| - obj.warning = response.warning; |
506 |
| - obj.message = response.message; |
507 |
| - |
508 |
| - %open url in browser |
509 |
| - if obj.PlotOptions.OpenURL |
510 |
| - web(response.url, '-browser'); |
511 |
| - end |
512 |
| - else |
513 |
| - obj.url = plotlyoffline(obj); |
514 |
| - if obj.PlotOptions.OpenURL |
515 |
| - web(obj.url, '-browser'); |
516 |
| - end |
517 |
| - end |
518 |
| - |
| 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 |
519 | 541 | end
|
520 | 542 |
|
521 | 543 | %-----------------------FIGURE CONVERSION-------------------------%
|
|
0 commit comments