IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
html_table_std_colors.m
Go to the documentation of this file.
1 %>@ingroup string htmlgen
2 %>@file
3 %>@brief HTML table where data items may have associated standard deviations
4 %>
5 %> This version of HTML table paints each cell with a colour proportional to corresponding element in M
6 %>
8 
9 
10 %> @param M Square matrix or cell. If cell, may contain either numbers of strings
11 %> @param S Matrix of standard deviations. This one must be a matrix
12 %> @param rowlabels cell of row labels
13 %> @param collabels cell of column labels
14 %> @param cornerstr =''. String to put in the corner
15 %> @param minimum
16 %> @param maximum
17 %> @param pow =10. Color function power. See internal function cellcolor2()
18 %> @return s A string
19 function s = html_table_std_colors(M, S, rowlabels, collabels, cornerstr, minimum, maximum, pow)
20 
21 flag_std = nargin > 1 && ~isempty(S);
22 
23 if nargin < 5
24  cornerstr = '';
25 end;
26 if nargin < 6 || isempty(minimum)
27  minimum = min(M(:));
28 end;
29 if nargin < 7 || isempty(maximum)
30  maximum = max(M(:));
31 end;
32 if nargin < 8 || isempty(pow)
33  pow = 10;
34 end;
35 
36 
37 funla = @(x) ['<td class="bob"><div class="hec">', iif(isnumeric(x), mat2str(x), x), '</div></td>'];
38 hete = cellfun(funla, collabels, 'UniformOutput', 0);
39 
40 s = ['<table class="bo">', 10];
41 s = cat(2, s, sprintf('<tr><td class="bobbor">%s</td>', cornerstr), cat(2, hete{:}), '</tr>', 10);
42 % mi = min(M(:));
43 for i = 1:size(M, 1)
44  s = cat(2, s, '<tr><td class="bor"><div class="hel">', iif(isnumeric(rowlabels{i}), mat2str(rowlabels{i}), rowlabels{i}), '</td>', 10);
45  for j = 1:size(M, 2)
46  [fg, bg] = cellcolor2(M(i, j), minimum, maximum, pow);
47  if flag_std
48  ssij = ['&plusmn;', num2str(S(i, j))];
49  else
50  ssij = '';
51  end;
52  s = cat(2, s, '<td class="nu" style="background-color: #', bg, '; color: #', fg, ';">', ...
53  num2str(M(i, j)), ssij, '</td>', 10);
54  end;
55  s = cat(2, s, '</tr>', 10);
56 end;
57 s = cat(2, s, '</table>', 10);
58 
59 
60 %=================================================================================================================================
61 %>@brief Calculates a background color based on percentage
62 %>
63 %> Sqrt improves the color representation, because it makes low values already some color
64 %> Color formula is:
65 %> - Red: maximum;
66 %> - Green and blue: sqrt(value)/sqrt(sum of row)
67 %
68 %> @param n intensity
69 %> @param ma Maximum
70 %> @retval [bgcolor] or [bgcolor, fgcolor]
71 function [fg, bg] = cellcolor2(n, min, max, pow)
72 
73 
74 % n = exp(n);
75 % min = exp(min);
76 % max = exp(max);
77 
78 N = 100;
79 cm = autumn(N);
80 cm = cm(end:-1:1, :);
81 
82 if min == max
83  vbg = [.8, .8, .8];
84 else
85  n = n^pow;
86  min = min^pow;
87  max = max^pow;
88  idx = (n-min)/(max-min)*(N-1)+1;
89  if idx < 1
90  idx = 1;
91  end;
92  if idx > N
93  idx = N;
94  end;
95  vbg = cm(round(idx), :);
96 end;
97 bg = color2hex(vbg);
98 fg = color2hex(iif(vbg(2) < .5, [1, 1, 1], [0, 0, 0]));
99 
100 
101 
102 %
103 % maximum = sqrt(maximum);
104 % if maximum == 0
105 % maximum = 1;
106 % end;
107 %
108 % if 1
109 % bgcolor = [1, [1, 1]*(1-sqrt(n)/maximum)];
110 % else
111 % bgcolor = [1, 1, 1];
112 % end;
113 % fgcolor = 1-bgcolor;
114 %
115 % bgcolor = color2hex(bgcolor);
116 % fgcolor = color2hex(fgcolor);
117 %
118 % if nargout == 1
119 % varargout = {bgcolor};
120 % else
121 % varargout = {bgcolor, fgcolor};
122 % end;
function html_comparison_std(in M, in S, in labels, in B, in cornerstr)
function html_confusion(in CC, in rowlabels, in collabels, in flag_perc, in flag_rejected, in flag_color, in SS)
function html_table_std(in M, in S, in rowlabels, in collabels, in B, in cornerstr)
function cellcolor2(in n, in min, in max, in pow)
Calculates a background color based on percentage.
function html_comparison(in M, in labels, in B, in cornerstr)
function html_table_std_colors(in M, in S, in rowlabels, in collabels, in cornerstr, in minimum, in maximum, in pow)
function color2hex(in x)
function iif(in cond, in x1, in x2)