From 0d507a4ddc09e166dd93da7ef51080d54919f9d0 Mon Sep 17 00:00:00 2001 From: Gilberto Galvis Date: Tue, 12 Oct 2021 12:20:26 -0400 Subject: [PATCH] fix issue related to add plotly themes (addtheme functionality) --- plotly/addtheme.m | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/plotly/addtheme.m b/plotly/addtheme.m index b92d12d0..f016150d 100644 --- a/plotly/addtheme.m +++ b/plotly/addtheme.m @@ -1,10 +1,27 @@ function f = addtheme(f, theme) - % validate theme name - - S = dir('plotly/themes'); - N = {S.name}; + %-------------------------------------------------------------------------% + + %-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', theme,... @@ -13,10 +30,13 @@ strrep(strrep([S.name], '...', ''), '.json', ' | ')]); throw(ME) end + + %-------------------------------------------------------------------------% - % add theme to figure + %-add theme to figure-% - fname = strcat('plotly/themes/', theme, '.json'); + fname = sprintf('%s/%s.json', themePath, theme); + % fname = strcat('plotly/themes/', theme, '.json'); fid = fopen(fname); raw = fread(fid,inf); str = char(raw'); @@ -33,5 +53,7 @@ if isfield(f.layout.template.layout, 'plot_bgcolor') disp(strcat('layout.plot_bgcolor:::',... f.layout.template.layout.plot_bgcolor)) - end + end + + %-------------------------------------------------------------------------% end