Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d28f50

Browse files
author
Harsh Purwar
committed
Fix warnings
1 parent a8af8bf commit 7d28f50

File tree

13 files changed

+210
-89
lines changed

13 files changed

+210
-89
lines changed

plotly/plotly_aux/expandStruct.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function strP = expandStruct(S,strP)
2+
3+
if nargin < 2
4+
strP="pr(1)";
5+
end
6+
7+
% fprintf('%s\n',strP(end));
8+
9+
strIn = strP(end);
10+
if isstruct(S)
11+
for j=1:numel(S)
12+
fn=fieldnames(S(j));
13+
for i = 1:numel(fn)
14+
strP = [strP; join([strIn,fn{i}],'.')];
15+
if isstruct(S(j).(fn{i}))
16+
strP = expandStruct(S(j).(fn{i}), strP);
17+
end
18+
end
19+
end
20+
end

plotly/plotly_aux/searchDoc.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function ss = searchDoc(varargin)
2+
%SEARCHDOC Searches plotly JSON documentation for keywords
3+
if nargin==0
4+
return;
5+
end
6+
7+
if ~isstruct(varargin{1})
8+
pr = load('plotly_reference.mat').pr;
9+
else
10+
pr = varargin{1};
11+
varargin=varargin(2:end);
12+
end
13+
14+
ss = expandStruct(pr,"pr(1)");
15+
if ~isempty(varargin{1})
16+
for i = 1:numel(varargin)
17+
idx = cellfun(@(x) ~isempty(x), regexp(ss,['(\.',varargin{i},')$|(\.',varargin{i},'\.)']));
18+
ss = ss(idx);
19+
end
20+
end

plotly/plotly_help_aux/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
plot-schema.json
2+
plotly_reference_old.mat
1.03 MB
Binary file not shown.

plotly/plotly_help_aux/updateplotlyhelp.m

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,67 @@
22
function updateplotlyhelp
33

44
% remote Plotly Graph Reference url
5-
remote = ['https://raw.githubusercontent.com/plotly/',...
6-
'graph_reference/master/graph_objs/matlab/graph_objs_keymeta.json'];
75

86
% download the remote content
7+
8+
% !!! old remote !!!
9+
% remote = ['https://raw.githubusercontent.com/plotly/',...
10+
% 'graph_reference/master/graph_objs/matlab/graph_objs_keymeta.json'];
11+
12+
% !!! new remote -- not recommended !!!
13+
% remote = 'https://api.plot.ly/v2/plot-schema?format=json&sha1=';
14+
15+
% !!! new remote -- Recommended !!!
16+
remote = 'https://github.com/plotly/plotly.js/raw/master/dist/plot-schema.json';
17+
18+
fprintf('Downloading plotly-schema.json from remote...\n%s\n',remote);
19+
newFile=false;
920
try
10-
prContent = urlread(remote);
21+
prContent = webread(remote);
22+
pr = jsondecode(prContent);
23+
newFile=true;
1124
catch
1225
fprintf(['\nAn error occurred while trying to read the latest\n',...
1326
'Plotly MATLAB API graph reference from:\n',...
14-
'https://github.com/plotly/graph_reference.\n']);
15-
return
27+
'https://github.com/plotly/plotly.js/blob/master/dist/plot-schema.json.\n']);
28+
try
29+
pr = loadjson('plot-schema.json');
30+
catch
31+
fprintf('Failed to load the local file... Quiting!\n');
32+
return;
33+
end
1634
end
1735

18-
% load the json into a struct
19-
pr = loadjson(prContent);
36+
if newFile
37+
f=fopen('plot-schema.json','w');
38+
fwrite(f,prContent);
39+
fclose(f);
40+
end
2041

2142
%------------------------MATLAB SPECIFIC TWEAKS---------------------------%
2243

44+
%-Dump non-relevant info & simplify the content-%
45+
% fields=fieldnames(pr.traces);
46+
% for i = 1:numel(fields)
47+
% field = fields{i};
48+
% try
49+
% prN.(field) = pr.traces.(field);
50+
% catch
51+
% fprintf('No attributes for: %s | Adding entire field.\n',field);
52+
% prN.(field) = pr.traces.(field);
53+
% end
54+
% end
55+
% prN.layout = pr.layout.layoutAttributes;
56+
57+
% prN.annotation = pr.layout.layoutAttributes.annotations.items.annotation;
58+
% prN.line = pr.line;
59+
2360
%-key_type changes-%
24-
pr.annotation.xref.key_type = 'plot_info';
25-
pr.annotation.yref.key_type = 'plot_info';
26-
pr.line.shape.key_type = 'plot_info';
61+
% prN.annotation.xref.key_type = 'plot_info';
62+
% prN.annotation.yref.key_type = 'plot_info';
63+
% prN.line.shape.key_type = 'plot_info';
64+
65+
% pr=prN;
2766

2867
%-------------------------------------------------------------------------%
2968

@@ -34,6 +73,6 @@
3473
prname = fullfile(helpdir);
3574

3675
%----save----%
37-
save(prname,'pr');
76+
save(prname,'pr');
3877

3978
end

plotly/plotlyfig.m

Lines changed: 70 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -269,17 +269,21 @@
269269

270270
% strip the style keys from data
271271
for d = 1:length(obj.data)
272-
if ( ...
273-
strcmpi(obj.data{d}.type, 'scatter') || ...
274-
strcmpi(obj.data{d}.type, 'bar') ...
275-
)
272+
if strcmpi(obj.data{d}.type, 'scatter')
276273
return
277274
end
278-
obj.data{d} = obj.stripkeys(obj.data{d}, obj.data{d}.type, 'style');
275+
obj.data{d} = obj.stripkeys(obj.data{d},'style', 'traces',obj.data{d}.type,'attributes');
279276
end
280277

281278
% strip the style keys from layout
282-
obj.layout = obj.stripkeys(obj.layout, 'layout', 'style');
279+
try
280+
fields = fieldnames(obj.PlotlyReference.traces.(obj.data{d}.type).layoutAttributes);
281+
for i = 1:numel(fields)
282+
field = fields{i};
283+
obj.PlotlyReference.layout.layoutAttributes.(field) = obj.PlotlyReference.traces.(obj.data{d}.type).layoutAttributes.(field);
284+
end
285+
end
286+
obj.layout = obj.stripkeys(obj.layout,'style', 'layout','layoutAttributes');
283287

284288
end
285289

@@ -294,7 +298,7 @@
294298

295299
% remove style / plot_info types in data
296300
for d = 1:length(obj.data)
297-
data{d} = obj.stripkeys(obj.data{d}, obj.data{d}.type, {'style','plot_info'});
301+
data{d} = obj.stripkeys(obj.data{d}, {'style','plot_info'}, 'traces', obj.data{d}.type, 'attributes');
298302
end
299303

300304
end
@@ -307,11 +311,18 @@ function validate(obj)
307311

308312
% validate data fields
309313
for d = 1:length(obj.data)
310-
obj.stripkeys(obj.data{d}, obj.data{d}.type, {'style','plot_info'});
314+
obj.stripkeys(obj.data{d}, {'style','plot_info'}, 'traces', obj.data{d}.type, 'attributes');
311315
end
312316

313317
% validate layout fields
314-
obj.stripkeys(obj.layout, 'layout', 'style');
318+
try
319+
fields = fieldnames(obj.PlotlyReference.traces.(obj.data{d}.type).layoutAttributes);
320+
for i = 1:numel(fields)
321+
field = fields{i};
322+
obj.PlotlyReference.layout.layoutAttributes.(field) = obj.PlotlyReference.traces.(obj.data{d}.type).layoutAttributes.(field);
323+
end
324+
end
325+
obj.stripkeys(obj.layout, 'style', 'layout', 'layoutAttributes');
315326

316327
end
317328

@@ -871,14 +882,15 @@ function delete(obj)
871882

872883
methods (Access=private)
873884
%----STRIP THE FIELDS OF A SPECIFIED KEY-----%
874-
function stripped = stripkeys(obj, fields, fieldname, key)
875-
876-
%plorlt reference
877-
pr = obj.PlotlyReference;
885+
function stripped = stripkeys(obj,stripped,key,pr,varargin)
886+
if ~isstruct(pr)
887+
varargin=[pr,varargin];
888+
pr = obj.PlotlyReference;
889+
end
878890

879891
% initialize output
880892
% fields
881-
stripped = fields;
893+
882894

883895
% get fieldnames
884896
fn = fieldnames(stripped);
@@ -892,28 +904,58 @@ function delete(obj)
892904
fnmod{d} = fn{d}(1:length('_axis'));
893905
end
894906

895-
% keys:(object, style, plot_info, data)
896-
keytype = getfield(pr,fieldname,fnmod{d},'key_type');
907+
if ~strcmp(fnmod{d},'type')
908+
% keys:(object, style, plot_info, data)
909+
txt = 'keytype = getfield(pr';
910+
for i = 1:numel(varargin)
911+
txt=[txt,',''',varargin{i},''''];
912+
end
913+
txt=[txt,',''',fnmod{d},''',''role'');'];
914+
915+
try
916+
eval(txt);
917+
catch ME
918+
if strcmp(ME.message,'Unrecognized field name "role".')
919+
keytype = '';
920+
else
921+
txt
922+
throw(ME);
923+
end
924+
end
925+
else
926+
keytype = '';
927+
end
897928

898929
% check for objects
899930
if strcmp(keytype,'object')
900931

901932
% clean up font keys
902-
if any(strfind(fn{d},'font'))
903-
fnmod{d} = 'font';
904-
end
933+
% if any(strfind(fn{d},'font'))
934+
% fnmod{d} = 'font';
935+
% end
905936

906937
% handle annotations
907938
if strcmp(fn{d},'annotations')
908939
annot = stripped.(fn{d});
909940
fnmod{d} = 'annotation';
910941
for a = 1:length(annot)
911942
%recursive call to stripkeys
912-
stripped.annotations{a} = obj.stripkeys(annot{a}, fnmod{d}, key);
943+
stripped.annotations{a} = obj.stripkeys(annot{a}, key, 'layout', 'layoutAttributes', 'annotations', 'items', fnmod{d});
913944
end
914945
else
915946
%recursive call to stripkeys
916-
stripped.(fn{d}) = obj.stripkeys(stripped.(fn{d}), fnmod{d}, key);
947+
txt2 = 'prN = pr';
948+
for i = 1:numel(varargin)
949+
txt2 = [txt2,'.',varargin{i}];
950+
end
951+
txt2 = [txt2,';'];
952+
try
953+
eval(txt2);
954+
catch ME
955+
txt2
956+
throw(ME);
957+
end
958+
stripped.(fn{d}) = obj.stripkeys(stripped.(fn{d}), key, prN, fnmod{d});
917959
end
918960

919961
% look for desired key and strip if not an exception
@@ -922,7 +964,6 @@ function delete(obj)
922964
stripped = rmfield(stripped, fn{d});
923965
end
924966
end
925-
926967
end
927968

928969
%----CLEAN UP----%
@@ -942,13 +983,13 @@ function delete(obj)
942983
catch exception
943984
if obj.UserData.Verbose
944985
% catch 3D output until integrated into graphref
945-
if ~( ...
946-
strcmpi(fieldname,'surface') || strcmpi(fieldname,'scatter3d') ...
947-
|| strcmpi(fieldname,'mesh3d') || strcmpi(fieldname,'bar') ...
948-
|| strcmpi(fieldname,'scatterpolar') || strcmpi(fieldname,'barpolar') ...
949-
)
950-
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']);
951-
end
986+
% if ~( ...
987+
% strcmpi(fieldname,'surface') || strcmpi(fieldname,'scatter3d') ...
988+
% || strcmpi(fieldname,'mesh3d') ...
989+
% || strcmpi(fieldname,'scatterpolar') || strcmpi(fieldname,'barpolar') ...
990+
% )
991+
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' varargin{1} '\n\n']);
992+
% end
952993
end
953994
end
954995
end

plotly/plotlyfig_aux/core/updateColorbar.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,34 +124,34 @@
124124

125125
if ~isempty(colorbar_title_data.String)
126126
%-colorbar titleside-%
127-
colorbar.titleside = 'top';
127+
colorbar.title.side = 'top';
128128
%-colorbar titlefont family-%:
129-
colorbar.titlefont.family = matlab2plotlyfont(colorbar_title_data.FontName);
129+
colorbar.title.font.family = matlab2plotlyfont(colorbar_title_data.FontName);
130130
%-colorbar titlefont color-%
131131
col = 255*colorbar_title_data.Color;
132-
colorbar.titlefont.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
132+
colorbar.title.font.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
133133
%-colorbar titlefont size-%
134-
colorbar.titlefont.size = colorbar_title_data.FontSize;
134+
colorbar.title.font.size = colorbar_title_data.FontSize;
135135
elseif ~isempty(colorbar_xlabel_data.String)
136136
%-colorbar titleside-%
137-
colorbar.titleside = 'right';
137+
colorbar.title.side = 'right';
138138
%-colorbar titlefont family-%:
139-
colorbar.titlefont.family = matlab2plotlyfont(colorbar_xlabel_data.FontName);
139+
colorbar.title.font.family = matlab2plotlyfont(colorbar_xlabel_data.FontName);
140140
%-colorbar titlefont color-%
141141
col = 255*colorbar_xlabel_data.Color;
142-
colorbar.titlefont.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
142+
colorbar.title.font.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
143143
%-colorbar titlefont size-%
144-
colorbar.titlefont.size = colorbar_xlabel_data.FontSize;
144+
colorbar.title.font.size = colorbar_xlabel_data.FontSize;
145145
elseif ~isempty(colorbar_ylabel_data.String)
146146
%-colorbar titleside-%
147-
colorbar.titleside = 'bottom';
147+
colorbar.title.side = 'bottom';
148148
%-colorbar titlefont family-%:
149-
colorbar.titlefont.family = matlab2plotlyfont(colorbar_ylabel_data.FontName);
149+
colorbar.title.font.family = matlab2plotlyfont(colorbar_ylabel_data.FontName);
150150
%-colorbar titlefont color-%
151151
col = 255*colorbar_ylabel_data.Color;
152-
colorbar.titlefont.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
152+
colorbar.title.font.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
153153
%-colorbar titlefont size-%
154-
colorbar.titlefont.size = colorbar_ylabel_data.FontSize;
154+
colorbar.title.font.size = colorbar_ylabel_data.FontSize;
155155
end
156156

157157
%-REVERT UNITS-%

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,4 @@
131131
end
132132

133133
%-------------------------------------------------------------------------%
134-
135134
end

plotly/plotlyfig_aux/core/updateLegend.m

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@
3636

3737
%-------------------------------------------------------------------------%
3838

39-
%-legend xref-%
40-
obj.layout.legend.xref = 'paper';
41-
42-
%-------------------------------------------------------------------------%
43-
4439
%-legend xanchor-%
4540
obj.layout.legend.xanchor = 'left';
4641

@@ -51,11 +46,6 @@
5146

5247
%-------------------------------------------------------------------------%
5348

54-
%-legend yref-%
55-
obj.layout.legend.yref = 'paper';
56-
57-
%-------------------------------------------------------------------------%
58-
5949
%-legend yanchor-%
6050
obj.layout.legend.yanchor = 'bottom';
6151

plotly/plotlyfig_aux/handlegraphics/updateBar.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@
176176

177177
%-bar marker line-%
178178
markerline = extractAreaLine(bar_data);
179-
obj.data{barIndex}.marker.line = markerline;
179+
180+
% No dash property in line for bars.
181+
markerline = rmfield(markerline,'dash');
182+
183+
obj.data{barIndex}.marker.line = markerline;
180184

181185
%-------------------------------------------------------------------------%
182186
end

0 commit comments

Comments
 (0)