A library for working with phylogenetic and population genetic data.
v0.27.0
list_qualitative.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2020 Lucas Czech and HITS gGmbH
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Contact:
19  Lucas Czech <lucas.czech@h-its.org>
20  Exelixis Lab, Heidelberg Institute for Theoretical Studies
21  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
22 */
23 
32 
35 
36 #include <cassert>
37 #include <map>
38 #include <stdexcept>
39 
40 namespace genesis {
41 namespace utils {
42 
43 // =================================================================================================
44 // Qualitative Color Lists
45 // =================================================================================================
46 
47 /*
48  * These ColorBrewer color palettes are adapted from https://github.com/axismaps/colorbrewer and
49  * https://github.com/Gnuplotting/gnuplot-palettes by converting the colors to RGB `double` values.
50  * The original ColorBrewer color specifications and designs were developed by Cynthia Brewer
51  * (http://colorbrewer.org/), while their gnuplot equivalets are authored by Anna Schneider,
52  * and published under the [Apache-2.0 license](http://www.apache.org/licenses/LICENSE-2.0).
53  * See also our @link supplement_acknowledgements_code_reuse_colorbrewer Acknowledgements@endlink.
54  */
55 
56 const std::vector<Color> color_list_accent_ = {{
57  { 0.498039, 0.788235, 0.498039 }, // pale green
58  { 0.745098, 0.682353, 0.831373 }, // pale purple
59  { 0.992157, 0.752941, 0.525490 }, // pale orange
60  { 1.000000, 1.000000, 0.600000 }, // pale yellow
61  { 0.219608, 0.423529, 0.690196 }, // blue
62  { 0.941176, 0.007843, 0.498039 }, // magenta
63  { 0.749020, 0.356863, 0.090196 }, // brown
64  { 0.400000, 0.400000, 0.400000 } // grey
65 }};
66 
67 const std::vector<Color> color_list_dark2_ = {{
68  { 0.105882, 0.619608, 0.466667 }, // dark teal
69  { 0.850980, 0.372549, 0.007843 }, // dark orange
70  { 0.458824, 0.439216, 0.701961 }, // dark lilac
71  { 0.905882, 0.160784, 0.541176 }, // dark magenta
72  { 0.400000, 0.650980, 0.117647 }, // dark lime green
73  { 0.901961, 0.670588, 0.007843 }, // dark banana
74  { 0.650980, 0.462745, 0.113725 }, // dark tan
75  { 0.400000, 0.400000, 0.400000 } // dark gray
76 }};
77 
78 const std::vector<Color> color_list_paired_ = {{
79  { 0.650980, 0.807843, 0.890196 }, // light blue
80  { 0.121569, 0.470588, 0.705882 }, // dark blue
81  { 0.698039, 0.874510, 0.541176 }, // light green
82  { 0.200000, 0.627451, 0.172549 }, // dark green
83  { 0.984314, 0.603922, 0.600000 }, // light red
84  { 0.890196, 0.101961, 0.109804 }, // dark red
85  { 0.992157, 0.749020, 0.435294 }, // light orange
86  { 1.000000, 0.498039, 0.000000 }, // dark orange
87  { 0.792157, 0.698039, 0.839216 }, // light purple
88  { 0.415686, 0.239216, 0.603922 }, // dark purple
89  { 1.000000, 1.000000, 0.600000 }, // light yellow
90  { 0.694118, 0.349020, 0.156863 } // brown
91 }};
92 
93 const std::vector<Color> color_list_pastel1_ = {{
94  { 0.984314, 0.705882, 0.682353 }, // pale red
95  { 0.701961, 0.803922, 0.890196 }, // pale blue
96  { 0.800000, 0.921569, 0.772549 }, // pale green
97  { 0.870588, 0.796078, 0.894118 }, // pale purple
98  { 0.996078, 0.850980, 0.650980 }, // pale orange
99  { 1.000000, 1.000000, 0.800000 }, // pale yellow
100  { 0.898039, 0.847059, 0.741176 }, // pale brown
101  { 0.992157, 0.854902, 0.925490 }, // pale pink
102  { 0.949020, 0.949020, 0.949020 } // pale grey
103 }};
104 
105 const std::vector<Color> color_list_pastel2_ = {{
106  { 0.701961, 0.886275, 0.803922 }, // pale teal
107  { 0.992157, 0.803922, 0.674510 }, // pale orange
108  { 0.803922, 0.709804, 0.909804 }, // pale lilac
109  { 0.956863, 0.792157, 0.894118 }, // pale magenta
110  { 0.839216, 0.960784, 0.788235 }, // pale lime green
111  { 1.000000, 0.949020, 0.682353 }, // pale banana
112  { 0.945098, 0.886275, 0.800000 }, // pale tan
113  { 0.800000, 0.800000, 0.800000 } // pale grey
114 }};
115 
116 const std::vector<Color> color_list_set1_ = {{
117  { 0.894118, 0.101961, 0.109804 }, // red
118  { 0.215686, 0.494118, 0.721569 }, // blue
119  { 0.301961, 0.686275, 0.290196 }, // green
120  { 0.596078, 0.305882, 0.639216 }, // purple
121  { 1.000000, 0.498039, 0.000000 }, // orange
122  { 1.000000, 1.000000, 0.200000 }, // yellow
123  { 0.650980, 0.337255, 0.156863 }, // brown
124  { 0.968627, 0.505882, 0.749020 }, // pink
125  { 0.600000, 0.600000, 0.600000 } // grey
126 }};
127 
128 const std::vector<Color> color_list_set2_ = {{
129  { 0.400000, 0.760784, 0.647059 }, // teal
130  { 0.988235, 0.552941, 0.384314 }, // orange
131  { 0.552941, 0.627451, 0.796078 }, // lilac
132  { 0.905882, 0.541176, 0.764706 }, // magenta
133  { 0.650980, 0.847059, 0.329412 }, // lime green
134  { 1.000000, 0.850980, 0.184314 }, // banana
135  { 0.898039, 0.768627, 0.580392 }, // tan
136  { 0.701961, 0.701961, 0.701961 } // grey
137 }};
138 
139 const std::vector<Color> color_list_set3_ = {{
140  { 0.552941, 0.827451, 0.780392 }, // teal
141  { 1.000000, 1.000000, 0.701961 }, // banana
142  { 0.745098, 0.729412, 0.854902 }, // lilac
143  { 0.984314, 0.501961, 0.447059 }, // red
144  { 0.501961, 0.694118, 0.827451 }, // steel blue
145  { 0.992157, 0.705882, 0.384314 }, // adobe orange
146  { 0.701961, 0.870588, 0.411765 }, // lime green
147  { 0.988235, 0.803922, 0.898039 }, // mauve
148  { 0.850980, 0.850980, 0.850980 }, // grey
149  { 0.737255, 0.501961, 0.741176 }, // purple
150  { 0.800000, 0.921569, 0.772549 }, // green
151  { 1.000000, 0.929412, 0.435294 } // yellow
152 }};
153 
154 // =================================================================================================
155 // Color Lists Functions
156 // =================================================================================================
157 
158 std::vector<Color> const& color_list_accent()
159 {
160  return color_list_accent_;
161 }
162 
163 std::vector<Color> const& color_list_dark2()
164 {
165  return color_list_dark2_;
166 }
167 
168 std::vector<Color> const& color_list_paired()
169 {
170  return color_list_paired_;
171 }
172 
173 std::vector<Color> const& color_list_pastel1()
174 {
175  return color_list_pastel1_;
176 }
177 
178 std::vector<Color> const& color_list_pastel2()
179 {
180  return color_list_pastel2_;
181 }
182 
183 std::vector<Color> const& color_list_set1()
184 {
185  return color_list_set1_;
186 }
187 
188 std::vector<Color> const& color_list_set2()
189 {
190  return color_list_set2_;
191 }
192 
193 std::vector<Color> const& color_list_set3()
194 {
195  return color_list_set3_;
196 }
197 
198 // =================================================================================================
199 // Convenience Functions
200 // =================================================================================================
201 
202 std::vector<Color> const& color_list_qualitative( ColorListQualitative palette )
203 {
204  if( palette == ColorListQualitative::kAccent ) {
205  return color_list_accent_;
206  }
207  if( palette == ColorListQualitative::kDark2 ) {
208  return color_list_dark2_;
209  }
210  if( palette == ColorListQualitative::kPaired ) {
211  return color_list_paired_;
212  }
213  if( palette == ColorListQualitative::kPastel1 ) {
214  return color_list_pastel1_;
215  }
216  if( palette == ColorListQualitative::kPastel2 ) {
217  return color_list_pastel1_;
218  }
219  if( palette == ColorListQualitative::kSet1 ) {
220  return color_list_set1_;
221  }
222  if( palette == ColorListQualitative::kSet2 ) {
223  return color_list_set2_;
224  }
225  if( palette == ColorListQualitative::kSet3 ) {
226  return color_list_set3_;
227  }
228 
229  throw std::invalid_argument( "Invalid ColorListQualitative value." );
230 }
231 
232 std::vector<Color> const& color_list_qualitative( std::string const& palette )
233 {
234  auto const p = to_lower_ascii( palette );
235 
236  if( p == "accent" ) {
237  return color_list_accent_;
238  }
239  if( p == "dark2" ) {
240  return color_list_dark2_;
241  }
242  if( p == "paired" ) {
243  return color_list_paired_;
244  }
245  if( p == "pastel1" ) {
246  return color_list_pastel1_;
247  }
248  if( p == "pastel2" ) {
249  return color_list_pastel2_;
250  }
251  if( p == "set1" ) {
252  return color_list_set1_;
253  }
254  if( p == "set2" ) {
255  return color_list_set2_;
256  }
257  if( p == "set3" ) {
258  return color_list_set3_;
259  }
260 
261  throw std::invalid_argument( "Invalid ColorListQualitative name: '" + palette + "'." );
262 }
263 
264 std::vector<std::string> color_list_qualitative_names()
265 {
266  return {
267  "Accent",
268  "Dark2",
269  "Paired",
270  "Pastel1",
271  "Pastel2",
272  "Set1",
273  "Set2",
274  "Set3"
275  };
276 }
277 
278 } // namespace utils
279 } // namespace genesis
genesis::utils::color_list_pastel1
std::vector< Color > const & color_list_pastel1()
Color palette pastel1.
Definition: list_qualitative.cpp:173
genesis::utils::ColorListQualitative::kAccent
@ kAccent
genesis::utils::color_list_dark2_
const std::vector< Color > color_list_dark2_
Definition: list_qualitative.cpp:67
genesis::utils::color_list_qualitative
std::vector< Color > const & color_list_qualitative(ColorListQualitative palette)
Definition: list_qualitative.cpp:202
genesis::utils::color_list_set2_
const std::vector< Color > color_list_set2_
Definition: list_qualitative.cpp:128
genesis::utils::color_list_pastel2
std::vector< Color > const & color_list_pastel2()
Color palette pastel2.
Definition: list_qualitative.cpp:178
genesis::utils::color_list_dark2
std::vector< Color > const & color_list_dark2()
Color palette dark2.
Definition: list_qualitative.cpp:163
genesis::utils::color_list_paired_
const std::vector< Color > color_list_paired_
Definition: list_qualitative.cpp:78
genesis::utils::color_list_set1
std::vector< Color > const & color_list_set1()
Color palette set1.
Definition: list_qualitative.cpp:183
genesis::utils::ColorListQualitative::kSet3
@ kSet3
genesis::utils::ColorListQualitative::kPastel2
@ kPastel2
genesis::utils::ColorListQualitative
ColorListQualitative
Definition: list_qualitative.hpp:127
string.hpp
Provides some commonly used string utility functions.
genesis::utils::color_list_accent
std::vector< Color > const & color_list_accent()
Color palette accent.
Definition: list_qualitative.cpp:158
genesis::utils::color_list_set1_
const std::vector< Color > color_list_set1_
Definition: list_qualitative.cpp:116
genesis::utils::ColorListQualitative::kPaired
@ kPaired
genesis::utils::color_list_accent_
const std::vector< Color > color_list_accent_
Definition: list_qualitative.cpp:56
genesis::utils::color_list_set2
std::vector< Color > const & color_list_set2()
Color palette set2.
Definition: list_qualitative.cpp:188
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::utils::color_list_qualitative_names
std::vector< std::string > color_list_qualitative_names()
Definition: list_qualitative.cpp:264
functions.hpp
Color operators and functions.
genesis::utils::ColorListQualitative::kSet2
@ kSet2
genesis::utils::to_lower_ascii
std::string to_lower_ascii(std::string const &str)
Return an all-lowercase copy of the given string, ASCII-only.
Definition: string.cpp:668
genesis::utils::color_list_pastel2_
const std::vector< Color > color_list_pastel2_
Definition: list_qualitative.cpp:105
genesis::utils::ColorListQualitative::kDark2
@ kDark2
genesis::utils::ColorListQualitative::kSet1
@ kSet1
genesis::utils::color_list_pastel1_
const std::vector< Color > color_list_pastel1_
Definition: list_qualitative.cpp:93
list_qualitative.hpp
genesis::utils::color_list_set3_
const std::vector< Color > color_list_set3_
Definition: list_qualitative.cpp:139
genesis::utils::color_list_paired
std::vector< Color > const & color_list_paired()
Color palette paired.
Definition: list_qualitative.cpp:168
genesis::utils::color_list_set3
std::vector< Color > const & color_list_set3()
Color palette set3.
Definition: list_qualitative.cpp:193
genesis::utils::ColorListQualitative::kPastel1
@ kPastel1