Skip to content

Fix indentation #507

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

Merged
merged 1 commit into from
Aug 6, 2024
Merged
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
19 changes: 6 additions & 13 deletions plotly/addtheme.m
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
function f = addtheme(f, theme)

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

%-validate theme name-%

themePath = 'plotly/themes';
S = dir(themePath);

if isempty(S)
paths = split(path, ':');

for p = 1:length(paths)
if ~isempty(strfind(paths{p}, themePath))
themePath = paths{p};
break;
end
end

S = dir(themePath);
end

N = {S.name};

if ~any(strcmp(N,strcat(theme, '.json'))) == 1
ME = MException('MyComponent:noSuchVariable',...
[strcat('\n<strong>', theme,...
'</strong> is not a supported themes.'),...
' Please choose one of these theme names:\n\n',...
strrep(strrep([S.name], '...', ''), '.json', ' | ')]);
ME = MException('MyComponent:noSuchVariable', ...
[strcat('\n<strong>', theme, ...
'</strong> is not a supported themes.'), ...
' Please choose one of these theme names:\n\n', ...
strrep(strrep([S.name], '...', ''), '.json', ' | ')]);
throw(ME)
end

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

%-add theme to figure-%

Expand All @@ -54,6 +49,4 @@
disp(strcat('layout.plot_bgcolor:::',...
f.layout.template.layout.plot_bgcolor))
end

%-------------------------------------------------------------------------%
end
65 changes: 29 additions & 36 deletions plotly/fig2plotly.m
Original file line number Diff line number Diff line change
@@ -1,53 +1,46 @@
function p = fig2plotly(varargin)
%----------------------------FIG2PLOTLY-------------------------------%

%------------------------------FIG2PLOTLY---------------------------------%
% Convert a MATLAB figure to a Plotly Figure

% Convert a MATLAB figure to a Plotly Figure
% [CALL]:

% [CALL]:
% p = fig2plotly
% p = fig2plotly(fig_han)
% p = fig2plotly(fig_han, 'property', value, ...)

% p = fig2plotly
% p = fig2plotly(fig_han)
% p = fig2plotly(fig_han, 'property', value, ...)
% [INPUTS]: [TYPE]{default} - description/'options'

% [INPUTS]: [TYPE]{default} - description/'options'
% fig_han: [handle]{gcf} - figure handle
% fig_struct: [structure array]{get(gcf)} - figure handle structure
% array

% fig_han: [handle]{gcf} - figure handle
% fig_struct: [structure array]{get(gcf)} - figure handle structure array
% [VALID PROPERTIES / VALUES]:

% [VALID PROPERTIES / VALUES]:
% filename: [string]{'untitled'} - filename as appears on Plotly
% fileopt: [string]{'new'} - 'new, overwrite, extend, append'
% world_readable: [boolean]{true} - public(true) / private(false)
% link: [boolean]{true} - show hyperlink (true) / no hyperlink (false)
% open: [boolean]{true} - open plot in browser (true)

% filename: [string]{'untitled'} - filename as appears on Plotly
% fileopt: [string]{'new'} - 'new, overwrite, extend, append'
% world_readable: [boolean]{true} - public(true) / private(false)
% link: [boolean]{true} - show hyperlink (true) / no hyperlink (false)
% open: [boolean]{true} - open plot in browser (true)
% [OUTPUT]:

% [OUTPUT]:
% p - plotlyfig object

% p - plotlyfig object
% [ADDITIONAL RESOURCES]:

% [ADDITIONAL RESOURCES]:
% For full documentation and examples, see https://plot.ly/matlab

% For full documentation and examples, see https://plot.ly/matlab
%---------------------------------------------------------------------%

%-------------------------------------------------------------------------%
%--FIGURE INITIALIZATION--%
if nargin == 0
varargin{1} = gcf;
end

%--FIGURE INITIALIZATION--%
if nargin == 0
varargin{1} = gcf;
end

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

%--CONSTRUCT PLOTLY FIGURE OBJECT--%
p = plotlyfig(varargin{:});

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

%--MAKE CALL TO PLOTLY--%
p.plotly;

%-------------------------------------------------------------------------%
%--CONSTRUCT PLOTLY FIGURE OBJECT--%
p = plotlyfig(varargin{:});

%--MAKE CALL TO PLOTLY--%
p.plotly;
end
45 changes: 20 additions & 25 deletions plotly/getplotlyfig.m
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
function p = getplotlyfig(file_owner, file_id)
%-----------------------------SAVEPLOTLYFIG---------------------------%
% Grab an online Plotly figure's data/layout information
% [CALL]:
% p = getplotlyfig(file_owner file_id)
% [INPUTS]: [TYPE]{default} - description/'options'
% file_owner: [string]{} - Unique Plotly username
% file_id [int]{} - the id of the graph you want to obtain
% [OUTPUT]:
% p - plotlyfig object
% [EXAMPLE]:
% url: https://plot.ly/~demos/1526
% fig = getplotlyfig('demos','1526');
% [ADDITIONAL RESOURCES]:
% For full documentation and examples, see
% https://plot.ly/matlab/get-requests/
%---------------------------------------------------------------------%

%-----------------------------SAVEPLOTLYFIG-------------------------------%
% Grab an online Plotly figure's data/layout information
% [CALL]:
% p = getplotlyfig(file_owner file_id)
% [INPUTS]: [TYPE]{default} - description/'options'
% file_owner: [string]{} - Unique Plotly username
% file_id [int]{} - the id of the graph you want to obtain
% [OUTPUT]:
% p - plotlyfig object
% [EXAMPLE]:
% url: https://plot.ly/~demos/1526
% fig = getplotlyfig('demos','1526');
% [ADDITIONAL RESOURCES]:
% For full documentation and examples, see https://plot.ly/matlab/get-requests/
%-------------------------------------------------------------------------%

%--CONSTRUCT PLOTLY FIGURE OBJECT--%
p = plotlyfig('Visible','off');

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

%--MAKE CALL TO DOWNLOAD METHOD--%
p.download(file_owner, file_id);

%-------------------------------------------------------------------------%
%--CONSTRUCT PLOTLY FIGURE OBJECT--%
p = plotlyfig('Visible','off');

%--MAKE CALL TO DOWNLOAD METHOD--%
p.download(file_owner, file_id);
end
32 changes: 16 additions & 16 deletions plotly/plotly_aux/checkescape.m
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
function escaped_val = checkescape(val)
%adds '\' escape character if needed
ec = '\';
ind = find( (val == '"') | (val == '\' ) | (val == '/' ));
if(ind)
if(ind(1) == 1)
val = ['\' val];
ind = ind + 1;
ind(1) = [];
end
if (ind)
val = [val ec(ones(1,length(ind)))]; %extend lengh of val to prep for char shifts.
for i = 1:length(ind)
val(ind(i):end) = [ec val(ind(i):end-1)];
ind = ind+1;
%adds '\' escape character if needed
ec = '\';
ind = find( (val == '"') | (val == '\' ) | (val == '/' ));
if ind
if ind(1) == 1
val = ['\' val];
ind = ind + 1;
ind(1) = [];
end
if ind
val = [val ec(ones(1,length(ind)))]; %extend lengh of val to prep for char shifts.
for i = 1:length(ind)
val(ind(i):end) = [ec val(ind(i):end-1)];
ind = ind+1;
end
end
end
escaped_val = val;
end

escaped_val = val;
27 changes: 14 additions & 13 deletions plotly/plotly_aux/getuserdir.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
function userDir = getuserdir
% GETUSERDIR Retrieve the user directory
% - Under Windows returns the %APPDATA% directory
% - For other OSs uses java to retrieve the user.home directory

if ispc
% userDir = winqueryreg('HKEY_CURRENT_USER',...
% ['Software\Microsoft\Windows\CurrentVersion\' ...
% 'Explorer\Shell Folders'],'Personal');
userDir = getenv('appdata');
else
userDir = char(java.lang.System.getProperty('user.home'));
end
function userDir = getuserdir
% GETUSERDIR Retrieve the user directory
% - Under Windows returns the %APPDATA% directory
% - For other OSs uses java to retrieve the user.home directory

if ispc
% userDir = winqueryreg('HKEY_CURRENT_USER',...
% ['Software\Microsoft\Windows\CurrentVersion\' ...
% 'Explorer\Shell Folders'],'Personal');
userDir = getenv('appdata');
else
userDir = char(java.lang.System.getProperty('user.home'));
end
end
9 changes: 4 additions & 5 deletions plotly/plotly_aux/makecall.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function st = makecall(args, origin, structargs)

% check if signed in and grab username, key, domain
[un, key, domain] = signin;
if isempty(un) || isempty(key)
Expand All @@ -17,7 +16,9 @@
args = m2json(args);
kwargs = m2json(structargs);
url = [domain '/clientresp'];
payload = {'platform', platform, 'version', plotly_version, 'args', args, 'un', un, 'key', key, 'origin', origin, 'kwargs', kwargs};
payload = {'platform', platform, 'version', plotly_version, ...
'args', args, 'un', un, 'key', key, 'origin', origin, ...
'kwargs', kwargs};

if (is_octave)
% use octave super_powers
Expand All @@ -28,7 +29,5 @@
end

st = jsondecode(resp);

response_handler(resp);

end
end
Loading