Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseValue issue resolved #325

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions plotly/plotly_aux/expandStruct.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function strP = expandStruct(S,strP)

if nargin < 2
strP="pr(1)";
end

% fprintf('%s\n',strP(end));

strIn = strP(end);
if isstruct(S)
for j=1:numel(S)
fn=fieldnames(S(j));
for i = 1:numel(fn)
strP = [strP; join([strIn,fn{i}],'.')];
if isstruct(S(j).(fn{i}))
strP = expandStruct(S(j).(fn{i}), strP);
end
end
end
end
20 changes: 20 additions & 0 deletions plotly/plotly_aux/searchDoc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function ss = searchDoc(varargin)
%SEARCHDOC Searches plotly JSON documentation for keywords
if nargin==0
return;
end

if ~isstruct(varargin{1})
pr = load('plotly_reference.mat').pr;
else
pr = varargin{1};
varargin=varargin(2:end);
end

ss = expandStruct(pr,"pr(1)");
if ~isempty(varargin{1})
for i = 1:numel(varargin)
idx = cellfun(@(x) ~isempty(x), regexp(ss,['(\.',varargin{i},')$|(\.',varargin{i},'\.)']));
ss = ss(idx);
end
end
2 changes: 2 additions & 0 deletions plotly/plotly_help_aux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plot-schema.json
plotly_reference_old.mat
Binary file modified plotly/plotly_help_aux/plotly_reference.mat
Binary file not shown.
61 changes: 50 additions & 11 deletions plotly/plotly_help_aux/updateplotlyhelp.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,67 @@
function updateplotlyhelp

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

% download the remote content

% !!! old remote !!!
% remote = ['https://raw.githubusercontent.com/plotly/',...
% 'graph_reference/master/graph_objs/matlab/graph_objs_keymeta.json'];

% !!! new remote -- not recommended !!!
% remote = 'https://api.plot.ly/v2/plot-schema?format=json&sha1=';

% !!! new remote -- Recommended !!!
remote = 'https://github.com/plotly/plotly.js/raw/master/dist/plot-schema.json';

fprintf('Downloading plotly-schema.json from remote...\n%s\n',remote);
newFile=false;
try
prContent = urlread(remote);
prContent = webread(remote);
pr = jsondecode(prContent);
newFile=true;
catch
fprintf(['\nAn error occurred while trying to read the latest\n',...
'Plotly MATLAB API graph reference from:\n',...
'https://github.com/plotly/graph_reference.\n']);
return
'https://github.com/plotly/plotly.js/blob/master/dist/plot-schema.json.\n']);
try
pr = loadjson('plot-schema.json');
catch
fprintf('Failed to load the local file... Quiting!\n');
return;
end
end

% load the json into a struct
pr = loadjson(prContent);
if newFile
f=fopen('plot-schema.json','w');
fwrite(f,prContent);
fclose(f);
end

%------------------------MATLAB SPECIFIC TWEAKS---------------------------%

%-Dump non-relevant info & simplify the content-%
% fields=fieldnames(pr.traces);
% for i = 1:numel(fields)
% field = fields{i};
% try
% prN.(field) = pr.traces.(field);
% catch
% fprintf('No attributes for: %s | Adding entire field.\n',field);
% prN.(field) = pr.traces.(field);
% end
% end
% prN.layout = pr.layout.layoutAttributes;

% prN.annotation = pr.layout.layoutAttributes.annotations.items.annotation;
% prN.line = pr.line;

%-key_type changes-%
pr.annotation.xref.key_type = 'plot_info';
pr.annotation.yref.key_type = 'plot_info';
pr.line.shape.key_type = 'plot_info';
% prN.annotation.xref.key_type = 'plot_info';
% prN.annotation.yref.key_type = 'plot_info';
% prN.line.shape.key_type = 'plot_info';

% pr=prN;

%-------------------------------------------------------------------------%

Expand All @@ -34,6 +73,6 @@
prname = fullfile(helpdir);

%----save----%
save(prname,'pr');
save(prname,'pr');

end
94 changes: 64 additions & 30 deletions plotly/plotlyfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,21 @@

% strip the style keys from data
for d = 1:length(obj.data)
if ( ...
strcmpi(obj.data{d}.type, 'scatter') || ...
strcmpi(obj.data{d}.type, 'bar') ...
)
if strcmpi(obj.data{d}.type, 'scatter')
return
end
obj.data{d} = obj.stripkeys(obj.data{d}, obj.data{d}.type, 'style');
obj.data{d} = obj.stripkeys(obj.data{d},'style', 'traces',obj.data{d}.type,'attributes');
end

% strip the style keys from layout
obj.layout = obj.stripkeys(obj.layout, 'layout', 'style');
try
fields = fieldnames(obj.PlotlyReference.traces.(obj.data{d}.type).layoutAttributes);
for i = 1:numel(fields)
field = fields{i};
obj.PlotlyReference.layout.layoutAttributes.(field) = obj.PlotlyReference.traces.(obj.data{d}.type).layoutAttributes.(field);
end
end
obj.layout = obj.stripkeys(obj.layout,'style', 'layout','layoutAttributes');

end

Expand All @@ -301,7 +305,7 @@

% remove style / plot_info types in data
for d = 1:length(obj.data)
data{d} = obj.stripkeys(obj.data{d}, obj.data{d}.type, {'style','plot_info'});
data{d} = obj.stripkeys(obj.data{d}, {'style','plot_info'}, 'traces', obj.data{d}.type, 'attributes');
end

end
Expand All @@ -314,11 +318,18 @@ function validate(obj)

% validate data fields
for d = 1:length(obj.data)
obj.stripkeys(obj.data{d}, obj.data{d}.type, {'style','plot_info'});
obj.stripkeys(obj.data{d}, {'style','plot_info'}, 'traces', obj.data{d}.type, 'attributes');
end

% validate layout fields
obj.stripkeys(obj.layout, 'layout', 'style');
try
fields = fieldnames(obj.PlotlyReference.traces.(obj.data{d}.type).layoutAttributes);
for i = 1:numel(fields)
field = fields{i};
obj.PlotlyReference.layout.layoutAttributes.(field) = obj.PlotlyReference.traces.(obj.data{d}.type).layoutAttributes.(field);
end
end
obj.stripkeys(obj.layout, 'style', 'layout', 'layoutAttributes');

end

Expand Down Expand Up @@ -897,14 +908,15 @@ function delete(obj)

methods (Access=private)
%----STRIP THE FIELDS OF A SPECIFIED KEY-----%
function stripped = stripkeys(obj, fields, fieldname, key)

%plorlt reference
pr = obj.PlotlyReference;
function stripped = stripkeys(obj,stripped,key,pr,varargin)
if ~isstruct(pr)
varargin=[pr,varargin];
pr = obj.PlotlyReference;
end

% initialize output
% fields
stripped = fields;


% get fieldnames
fn = fieldnames(stripped);
Expand All @@ -918,28 +930,58 @@ function delete(obj)
fnmod{d} = fn{d}(1:length('_axis'));
end

% keys:(object, style, plot_info, data)
keytype = getfield(pr,fieldname,fnmod{d},'key_type');
if ~strcmp(fnmod{d},'type')
% keys:(object, style, plot_info, data)
txt = 'keytype = getfield(pr';
for i = 1:numel(varargin)
txt=[txt,',''',varargin{i},''''];
end
txt=[txt,',''',fnmod{d},''',''role'');'];

try
eval(txt);
catch ME
if strcmp(ME.message,'Unrecognized field name "role".')
keytype = '';
else
txt
throw(ME);
end
end
else
keytype = '';
end

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

% clean up font keys
if any(strfind(fn{d},'font'))
fnmod{d} = 'font';
end
% if any(strfind(fn{d},'font'))
% fnmod{d} = 'font';
% end

% handle annotations
if strcmp(fn{d},'annotations')
annot = stripped.(fn{d});
fnmod{d} = 'annotation';
for a = 1:length(annot)
%recursive call to stripkeys
stripped.annotations{a} = obj.stripkeys(annot{a}, fnmod{d}, key);
stripped.annotations{a} = obj.stripkeys(annot{a}, key, 'layout', 'layoutAttributes', 'annotations', 'items', fnmod{d});
end
else
%recursive call to stripkeys
stripped.(fn{d}) = obj.stripkeys(stripped.(fn{d}), fnmod{d}, key);
txt2 = 'prN = pr';
for i = 1:numel(varargin)
txt2 = [txt2,'.',varargin{i}];
end
txt2 = [txt2,';'];
try
eval(txt2);
catch ME
txt2
throw(ME);
end
stripped.(fn{d}) = obj.stripkeys(stripped.(fn{d}), key, prN, fnmod{d});
end

% look for desired key and strip if not an exception
Expand All @@ -948,7 +990,6 @@ function delete(obj)
stripped = rmfield(stripped, fn{d});
end
end

end

%----CLEAN UP----%
Expand All @@ -968,14 +1009,7 @@ function delete(obj)
catch exception
if obj.UserData.Verbose
% catch 3D output until integrated into graphref
if ~( ...
strcmpi(fieldname,'surface') || strcmpi(fieldname,'scatter3d') ...
|| strcmpi(fieldname,'mesh3d') || strcmpi(fieldname,'bar') ...
|| strcmpi(fieldname,'scatterpolar') || strcmpi(fieldname,'barpolar') ...
|| strcmpi(fieldname,'scene') ...
)
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']);
end
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' varargin{1} '\n\n']);
end
end
end
Expand Down
24 changes: 12 additions & 12 deletions plotly/plotlyfig_aux/core/updateColorbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,34 +124,34 @@

if ~isempty(colorbar_title_data.String)
%-colorbar titleside-%
colorbar.titleside = 'top';
colorbar.title.side = 'top';
%-colorbar titlefont family-%:
colorbar.titlefont.family = matlab2plotlyfont(colorbar_title_data.FontName);
colorbar.title.font.family = matlab2plotlyfont(colorbar_title_data.FontName);
%-colorbar titlefont color-%
col = 255*colorbar_title_data.Color;
colorbar.titlefont.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
colorbar.title.font.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
%-colorbar titlefont size-%
colorbar.titlefont.size = colorbar_title_data.FontSize;
colorbar.title.font.size = colorbar_title_data.FontSize;
elseif ~isempty(colorbar_xlabel_data.String)
%-colorbar titleside-%
colorbar.titleside = 'right';
colorbar.title.side = 'right';
%-colorbar titlefont family-%:
colorbar.titlefont.family = matlab2plotlyfont(colorbar_xlabel_data.FontName);
colorbar.title.font.family = matlab2plotlyfont(colorbar_xlabel_data.FontName);
%-colorbar titlefont color-%
col = 255*colorbar_xlabel_data.Color;
colorbar.titlefont.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
colorbar.title.font.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
%-colorbar titlefont size-%
colorbar.titlefont.size = colorbar_xlabel_data.FontSize;
colorbar.title.font.size = colorbar_xlabel_data.FontSize;
elseif ~isempty(colorbar_ylabel_data.String)
%-colorbar titleside-%
colorbar.titleside = 'bottom';
colorbar.title.side = 'bottom';
%-colorbar titlefont family-%:
colorbar.titlefont.family = matlab2plotlyfont(colorbar_ylabel_data.FontName);
colorbar.title.font.family = matlab2plotlyfont(colorbar_ylabel_data.FontName);
%-colorbar titlefont color-%
col = 255*colorbar_ylabel_data.Color;
colorbar.titlefont.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
colorbar.title.font.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
%-colorbar titlefont size-%
colorbar.titlefont.size = colorbar_ylabel_data.FontSize;
colorbar.title.font.size = colorbar_ylabel_data.FontSize;
end

%-REVERT UNITS-%
Expand Down
1 change: 0 additions & 1 deletion plotly/plotlyfig_aux/core/updateData.m
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,4 @@
end

%-------------------------------------------------------------------------%

end
10 changes: 0 additions & 10 deletions plotly/plotlyfig_aux/core/updateLegend.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@

%-------------------------------------------------------------------------%

%-legend xref-%
obj.layout.legend.xref = 'paper';

%-------------------------------------------------------------------------%

%-legend xanchor-%
obj.layout.legend.xanchor = 'left';

Expand All @@ -51,11 +46,6 @@

%-------------------------------------------------------------------------%

%-legend yref-%
obj.layout.legend.yref = 'paper';

%-------------------------------------------------------------------------%

%-legend yanchor-%
obj.layout.legend.yanchor = 'bottom';

Expand Down
Loading