Skip to content

Commit 2b5d237

Browse files
authored
Create addtheme.m
1 parent e65b3db commit 2b5d237

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

plotly/addtheme.m

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function figure = addtheme(f, theme)
2+
3+
% validate theme name
4+
5+
S = dir('plotly/themes');
6+
N = {S.name};
7+
8+
if ~any(strcmp(N,strcat(theme, '.json'))) == 1
9+
ME = MException('MyComponent:noSuchVariable',...
10+
[strcat('\n<strong>', theme, '</strong> is not a supported themes.'),...
11+
' Please choose one of these theme names:\n\n',...
12+
strrep(strrep([S.name], '...', ''), '.json', ' | ')]);
13+
throw(ME)
14+
end
15+
16+
% add theme to figure
17+
18+
fname = strcat('plotly/themes/', theme, '.json');
19+
fid = fopen(fname);
20+
raw = fread(fid,inf);
21+
str = char(raw');
22+
fclose(fid);
23+
theme_template = jsondecode(str);
24+
25+
f.layout.template = theme_template;
26+
27+
if isfield(f.layout.template.layout, 'paper_bgcolor')
28+
disp([strcat('layout.bg_paper:::',...
29+
f.layout.template.layout.paper_bgcolor)])
30+
end
31+
32+
if isfield(f.layout.template.layout, 'plot_bgcolor')
33+
disp([strcat('layout.plot_bgcolor:::',...
34+
f.layout.template.layout.plot_bgcolor)])
35+
end
36+
37+
end

0 commit comments

Comments
 (0)