IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
colors2map.m
Go to the documentation of this file.
1 %> @brief converts colors to a map to be used by @ref draw_stacked.m
2 %> @file
3 %> @ingroup graphicsapi conversion
4 %
5 %> @param colors =(default colors). Can be a cell of 2 elements, 3 elements or 4 elements.
6 %> @arg 2 elements: {informative color | [] | "colormap name", non-informative color}
7 %> @arg 3 elements: {[] | "colormap name", non-informative color start, non-informative color end}
8 %> @arg 4 elements: {informative color start, informative color end, non-informative color start, non-informative color end}
9 %> @note the empty cases ("[]") mean that find_color_stackedhist() will be used; the 3-element case only accepts an empty first element
10 %
11 %> @param no_hists
12 %> @param no_informative
13 %> @return <code>[cm, leg_cm, leg_la]</code> @cm is a color map with @c no_hists rows; @c leg_cm is a color map with repeating colors grouped;
14 %> @c leg_la are the legend labels that correspond to @c leg_cm
15 function [cm, leg_cm, leg_la] = colors2map(colors, no_hists, no_informative)
16 %==============
17 % Makes colormap and legends simultaneously
18 if numel(colors) == 3 || isempty(colors{1}) || ischar(colors{1})
19  % note that here, colors may be 2- or 3-element
20 
21  if isempty(colors{1})
22  for i = 1:no_informative
23  cm(i, :) = rgb(find_color_stackedhist(i));
24  end;
25  else
26  cm = feval(colors{1}, no_informative);
27  end;
28 
29  leg_cm = cm;
30  leg_la = arrayfun(@int2ord, 1:no_informative, 'UniformOutput', 0);
31 
32 
33  flag_gradient = numel(colors) > 2;
34  if no_informative < no_hists
35  if ~flag_gradient
36  cm = [cm; ones(no_hists-no_informative, 1)*colors{2}];
37  leg_cm = [leg_cm; colors{2}];
38  leg_la = [leg_la, iif(no_informative < no_hists-1, sprintf('%s-%s', int2ord(no_informative+1), int2ord(no_hists)), int2ord(no_hists))];
39  else
40  for i = 1:3
41  cm(no_informative+1:no_hists, i) = linspace(colors{2}(i), colors{3}(i), no_hists-no_informative);
42  end;
43  leg_cm = cm;
44  leg_la = arrayfun(@int2ord, 1:no_hists, 'UniformOutput', 0);
45  end;
46  end;
47 
48 else
49  % Note that here, colors may be 2- or 4-element
50 
51  flag_gradient = numel(colors) > 2;
52 
53  if ~flag_gradient
54  % 2-element
55  cm = ones(no_informative, 1)*colors{1};
56  if no_informative < no_hists
57  cm = [cm; ones(no_hists-no_informative, 1)*colors{2}];
58  end;
59 
60  leg_cm(1, :) = colors{1};
61  leg_la = {iif(no_informative > 1, sprintf('%s-%s', int2ord(1), int2ord(no_informative)), int2ord(1))};
62  if no_informative < no_hists
63  leg_cm(2, :) = colors{2};
64  leg_la{2} = iif(no_informative < no_hists-1, sprintf('%s-%s', int2ord(no_informative+1), int2ord(no_hists)), int2ord(no_hists));
65  end;
66 
67  else
68  % 4-element
69 
70  for i = 1:3
71  cm(1:no_informative, i) = linspace(colors{1}(i), colors{2}(i), no_informative);
72  end;
73 
74  if no_informative < no_hists
75  for i = 1:3
76  cm(no_informative+1:no_hists, i) = linspace(colors{3}(i), colors{4}(i), no_hists-no_informative);
77  end;
78  end;
79 
80  leg_cm = cm;
81  leg_la = arrayfun(@int2ord, 1:no_hists, 'UniformOutput', 0);
82  end;
83 end;
function colors2map(in colors, in no_hists, in no_informative)
function iif(in cond, in x1, in x2)
function int2ord(in idx)
function find_color_stackedhist(in i)
function draw_stacked(in x, in histss, in no_informative, in colors, in x_hint, in hint, in peakd, in flag_trace_minalt, in flag_draw_peaks, in flag_print_peaks, in flag_text)