|
1 | 1 | function f = addtheme(f, theme) |
2 | 2 |
|
3 | | - % validate theme name |
4 | | - |
5 | | - S = dir('plotly/themes'); |
6 | | - N = {S.name}; |
| 3 | + %-------------------------------------------------------------------------% |
| 4 | + |
| 5 | + %-validate theme name-% |
| 6 | + |
| 7 | + themePath = 'plotly/themes'; |
| 8 | + S = dir(themePath); |
| 9 | + |
| 10 | + if isempty(S) |
| 11 | + paths = split(path, ':'); |
7 | 12 |
|
| 13 | + for p = 1:length(paths) |
| 14 | + if ~isempty(strfind(paths{p}, themePath)) |
| 15 | + themePath = paths{p}; |
| 16 | + break; |
| 17 | + end |
| 18 | + end |
| 19 | + |
| 20 | + S = dir(themePath); |
| 21 | + end |
| 22 | + |
| 23 | + N = {S.name}; |
| 24 | + |
8 | 25 | if ~any(strcmp(N,strcat(theme, '.json'))) == 1 |
9 | 26 | ME = MException('MyComponent:noSuchVariable',... |
10 | 27 | [strcat('\n<strong>', theme,... |
|
13 | 30 | strrep(strrep([S.name], '...', ''), '.json', ' | ')]); |
14 | 31 | throw(ME) |
15 | 32 | end |
| 33 | + |
| 34 | + %-------------------------------------------------------------------------% |
16 | 35 |
|
17 | | - % add theme to figure |
| 36 | + %-add theme to figure-% |
18 | 37 |
|
19 | | - fname = strcat('plotly/themes/', theme, '.json'); |
| 38 | + fname = sprintf('%s/%s.json', themePath, theme); |
| 39 | + % fname = strcat('plotly/themes/', theme, '.json'); |
20 | 40 | fid = fopen(fname); |
21 | 41 | raw = fread(fid,inf); |
22 | 42 | str = char(raw'); |
|
33 | 53 | if isfield(f.layout.template.layout, 'plot_bgcolor') |
34 | 54 | disp(strcat('layout.plot_bgcolor:::',... |
35 | 55 | f.layout.template.layout.plot_bgcolor)) |
36 | | - end |
| 56 | + end |
| 57 | + |
| 58 | + %-------------------------------------------------------------------------% |
37 | 59 | end |
0 commit comments