Skip to content

Commit ba7c9b4

Browse files
committed
Merge branch 'title_in_feed_fix' of https://github.com/plotly/MATLAB-api into TESTING
2 parents f0edf9b + d01f1a7 commit ba7c9b4

File tree

11 files changed

+129
-29
lines changed

11 files changed

+129
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## MATLAB PLOTLY API WRAPPER 2.1.6
1+
## MATLAB PLOTLY API WRAPPER 2.1.8
22

33
### NUTSHELL:
44

plotly/fig2plotly.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
% [OUTPUT]:
2727

28-
% p - plotlyfigure object
28+
% p - plotlyfig object
2929

3030
% [ADDITIONAL RESOURCES]:
3131

@@ -50,4 +50,4 @@
5050

5151
%-------------------------------------------------------------------------%
5252

53-
end
53+
end

plotly/getplotlyfig.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
% [OUTPUT]:
1717

18-
% p - plotlyfigure object
18+
% p - plotlyfig object
1919

2020
% [EXAMPLE]:
2121

plotly/plotly_aux/plotly_version.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
function version = plotly_version()
2-
version = '2.1.6';
2+
version = '2.1.8';
33
end

plotly/plotly_user_aux/saveplotlyconfig.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ function saveplotlyconfig(plotly_domain,plotly_streaming_domain)
33
% Plotly config info are saved as JSON strings
44
% in ~/.plotly/.config
55

6+
% catch missing input arguments
7+
if nargin < 1
8+
error('plotly:saveconfig', ...
9+
['Incorrect number of inputs. Please save your configuration ', ...
10+
'as follows: >> saveplotlyconfig(plotly_domain,', ...
11+
'[optional]plotly_streaming_domain)']);
12+
end
13+
614
% if the config file exists, then load it up
715
try
816
config = loadplotlyconfig();
@@ -37,12 +45,16 @@ function saveplotlyconfig(plotly_domain,plotly_streaming_domain)
3745
'chris@plot.ly for support.']);
3846
end
3947

48+
% get user credenitals
49+
[username, api_key] = signin;
4050

4151
switch nargin
4252
case 1
4353
config.plotly_domain = plotly_domain;
54+
signin(username, api_key, plotly_domain);
4455
case 2
4556
config.plotly_domain = plotly_domain;
57+
signin(username, api_key, plotly_domain);
4658
config.plotly_streaming_domain= plotly_streaming_domain;
4759
otherwise %if neither endpoints are specified, no worries!
4860
end

plotly/plotly_user_aux/saveplotlycredentials.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ function saveplotlycredentials(username, api_key, stream_ids)
33
% Plotly credentials are saved as JSON strings
44
% in ~/.plotly/.credentials
55

6+
% catch missing input arguments
7+
if nargin < 2
8+
error('plotly:savecredentials', ...
9+
['Incorrect number of inputs. Please save your credentials ', ...
10+
'as follows: >> saveplotlycredentials(username, api_key,', ...
11+
'[optional]stream_ids)']);
12+
end
13+
614
% if the credentials file exists, then load it up
715
try
816
creds = loadplotlycredentials();
@@ -45,9 +53,6 @@ function saveplotlycredentials(username, api_key, stream_ids)
4553
creds.username = username;
4654
creds.api_key = api_key;
4755
creds.stream_ids = stream_ids;
48-
otherwise %need to specify both the username and api_key
49-
error('plotly:savecredentials',...
50-
'Please specify your username and api_key');
5156
end
5257

5358
creds_string = m2json(creds);
@@ -56,4 +61,7 @@ function saveplotlycredentials(username, api_key, stream_ids)
5661
fprintf(fileIDCred,'%s',creds_string);
5762
fclose(fileIDCred);
5863

64+
%signin using newly saved credentials
65+
signin(username, api_key);
66+
5967
end

plotly/plotlyfig.m

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@
4343
obj.UserData.ApiKey,...
4444
obj.UserData.PlotlyDomain] = signin;
4545
catch
46-
errkey = 'plotlyfigureConstructor:notSignedIn';
46+
errkey = 'plotlyfigConstructor:notSignedIn';
4747
error(errkey, plotlymsg(errkey));
4848
end
4949

5050
obj.UserData.Verbose = true;
5151

5252
%-PlotOptions-%
53+
obj.PlotOptions.CleanFeedTitle = true;
5354
obj.PlotOptions.FileName = '';
5455
obj.PlotOptions.FileOpt = 'new';
5556
obj.PlotOptions.WorldReadable = true;
@@ -112,7 +113,7 @@
112113
updatekey = true;
113114
end
114115
else
115-
errkey = 'plotlyfigureConstructor:invalidInputs';
116+
errkey = 'plotlyfigConstructor:invalidInputs';
116117
error(errkey , plotlymsg(errkey));
117118
end
118119

@@ -131,7 +132,7 @@
131132

132133
% check for proper property/value structure
133134
if mod(length(parseinit:nargin),2) ~= 0
134-
errkey = 'plotlyfigureConstructor:invalidInputs';
135+
errkey = 'plotlyfigConstructor:invalidInputs';
135136
error(errkey , plotlymsg(errkey));
136137
end
137138

@@ -360,9 +361,14 @@ function validate(obj)
360361
% validate keys
361362
validate(obj);
362363

363-
% handle title
364+
% handle filename
364365
handleFileName(obj);
365366

367+
% handle title (for feed)
368+
if obj.PlotOptions.CleanFeedTitle
369+
cleanFeedTitle(obj);
370+
end
371+
366372
%args
367373
args.filename = obj.PlotOptions.FileName;
368374
args.fileopt = obj.PlotOptions.FileOpt;
@@ -825,4 +831,4 @@ function delete(obj)
825831
end
826832
end
827833
end
828-
end
834+
end

plotly/plotlyfig_aux/core/updateColorbar.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@
285285
%-tick0-%
286286
colorbar.tick0 = str2double(colorbar_data.YTickLabel(1,:));
287287
%-dtick-%
288-
colorbar.dtick = str2double(colorbar_data.YTickLabel(2,:))- str2double(colorbar_data.YtickLabel(1,:));
288+
colorbar.dtick = str2double(colorbar_data.YTickLabel(2,:)) - str2double(colorbar_data.YTickLabel(1,:));
289289
end
290290
end
291291
end
@@ -318,7 +318,7 @@
318318
%-tick0-%
319319
colorbar.tick0 = str2double(colorbar_data.XTickLabel(1,:));
320320
%-dtick-%
321-
colorbar.dtick = str2double(colorbar_data.XTickLabel(2,:))- str2double(colorbar_data.XtickLabel(1,:));
321+
colorbar.dtick = str2double(colorbar_data.XTickLabel(2,:)) - str2double(colorbar_data.XTickLabel(1,:));
322322
end
323323
end
324324
end
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
function cleanFeedTitle(obj)
2+
% cleanFeedTitle checks all annotations for a title. The first title found
3+
% is used as the layout.title (Plotly title). This should correspond to the
4+
% title of the first plot added to the MATLAB figure. cleanFeedTitle should
5+
% be called after the style keys have been stripped --> it must override
6+
% certain style keys as a workaround.
7+
8+
% -- Single plot figure -- %
9+
10+
% If only a single plot is present, the title will be set as the Plotly
11+
% title.
12+
13+
% -- Multiple plot figure -- %
14+
15+
% If multiple plots are present, only the text of the title is used so
16+
% that the title appears in the feed. The text color is set so that the
17+
% Plotly title is hidden from the graph, favouring the
18+
% annotation title (with its flexibilty over positioning).
19+
20+
if ~isempty(obj.State.Figure.NumTexts)
21+
22+
% grab the title of the first plot added to the figure.
23+
first_title_index = find(arrayfun(@(x)(isequal(x.Title, 1)), ...
24+
obj.State.Text), 1, 'first');
25+
26+
if ~isempty(first_title_index)
27+
28+
first_title_handle = obj.State.Text(first_title_index).Handle;
29+
30+
% grab the string of the first title
31+
annotation_index = obj.getAnnotationIndex(first_title_handle);
32+
first_title = obj.layout.annotations{annotation_index}.text;
33+
34+
% use that as the filename
35+
obj.layout.title = first_title;
36+
37+
% check for a single plot
38+
if (obj.State.Figure.NumPlots == 1)
39+
40+
% grab the font style if not stripped
41+
if ~obj.PlotOptions.Strip
42+
obj.layout.titlefont = ...
43+
obj.layout.annotations{annotation_index}.font;
44+
end
45+
46+
% remove the annotation
47+
obj.layout.annotations(annotation_index) = [];
48+
obj.State.Figure.NumTexts = obj.State.Figure.NumTexts - 1;
49+
obj.State.Text(first_title_index) = [];
50+
51+
% adjust the top margin for the title
52+
obj.layout.margin.t = max(...
53+
obj.PlotlyDefaults.MinTitleMargin,...
54+
obj.layout.margin.t);
55+
else
56+
57+
% multiple plots ---> make the title invisible
58+
obj.layout.titlefont.color = 'rgba(0,0,0,0)';
59+
end
60+
end
61+
end
62+
end
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function errormsg = plotlymsg(key)
22
switch key
3-
%--plotlyfigure constructor--%
4-
case 'plotlyfigureConstructor:notSignedIn'
5-
errormsg = '\nOops! You must be signed in to initialize a plotlyfigure object.\n';
6-
case 'plotlyfigureConstructor:invalidInputs'
7-
errormsg = ['\nOops! It appears that you did not initialize the plotlyfigure object using the\n', ...
8-
'required: >> plotlyfigure(handle [optional],''property'',''value'',...) \n',...
3+
%--plotlyfig constructor--%
4+
case 'plotlyfigConstructor:notSignedIn'
5+
errormsg = '\nOops! You must be signed in to initialize a plotlyfig object.\n';
6+
case 'plotlyfigConstructor:invalidInputs'
7+
errormsg = ['\nOops! It appears that you did not initialize the plotlyfig object using the\n', ...
8+
'required: >> plotlyfig(handle [optional],''property'',''value'',...) \n',...
99
'input structure. Please try again or contact chuck@plot.ly for any additional help!\n\n'];
1010
%--saveplotlyfig invocation--%;
1111
case 'plotlySaveImage:invalidInputs'
@@ -15,4 +15,4 @@
1515
'Please try again or contact chuck@plot.ly for any additional help!\n\n'];
1616

1717
end
18-
end
18+
end

plotlysetup.m

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ function plotlysetup(username, api_key, varargin)
139139

140140
try %save user credentials
141141
fprintf('Saving username/api_key credentials ... ');
142-
saveplotlycredentials(username,api_key);
142+
143+
%update: as of v.2.1.7, This also signs in the user
144+
saveplotlycredentials(username, api_key);
145+
143146
%worked!
144147
fprintf('Done\n');
145148
catch exception %writing credentials file permission problem catch...
@@ -168,13 +171,19 @@ function plotlysetup(username, api_key, varargin)
168171

169172
if strcmp(varargin{n},'stream_ids')
170173
fprintf('Saving stream_ids credentials ... ');
171-
saveplotlycredentials(username,api_key,varargin{n+1});
174+
175+
%update: as of v.2.1.7, This also signs in the user
176+
saveplotlycredentials(username, api_key, varargin{n+1});
177+
172178
%worked!
173179
fprintf('Done\n');
174180
end
175181
if strcmp(varargin{n},'plotly_domain')
176182
fprintf('Saving plotly_domain configuration ... ');
183+
184+
%update: as of v.2.1.7, This also signs in the user
177185
saveplotlyconfig(varargin{n+1});
186+
178187
%worked!
179188
fprintf('Done\n');
180189
end
@@ -185,7 +194,10 @@ function plotlysetup(username, api_key, varargin)
185194
catch
186195
config.plotly_domain = '';
187196
end
197+
198+
%update: as of v.2.1.7, This also signs in the user
188199
saveplotlyconfig(config.plotly_domain,varargin{n+1});
200+
189201
%worked!
190202
fprintf('Done\n');
191203
end
@@ -195,9 +207,6 @@ function plotlysetup(username, api_key, varargin)
195207
fprintf(['\n\n' exception.identifier exception.message '\n\n']);
196208
end
197209

198-
%sign in the user
199-
signin(username,api_key);
200-
201210
%greet the people!
202211
fprintf('\nWelcome to Plotly! If you are new to Plotly please enter: >> plotlyhelp to get started!\n\n')
203212

@@ -210,7 +219,10 @@ function plotlysetup(username, api_key, varargin)
210219
'the Plotly folder to your MATLAB path manually by running: \n\n',...
211220
'>> plotly_path = fullfile(pwd, ''plotly'')\n',...
212221
'>> addpath(genpath(plotly_path))\n\n',...
213-
'Questions? Chuck@plotly'];
214-
222+
'You can save your credentials by running:\n\n', ...
223+
'>>saveplotlycredentials(''your_username'', ''your_api_key'')\n\n',...
224+
'You can save your domain configuration by running:\n\n',...
225+
'>>saveplotlyconfig(''your_base_domain'')\n\n',...
226+
'Questions? Chuck@plotly\n\n'];
215227
end
216228

0 commit comments

Comments
 (0)