|
A library for working with phylogenetic and population genetic data.
v0.27.0
|
|
Go to the documentation of this file.
71 std::string
const gradient_id = (
id.empty()
101 throw std::runtime_error(
"Invalid SvgPalette direction." );
106 auto const norm_gradient =
color_stops( map, norm );
110 for(
auto const& g : norm_gradient ) {
111 if( g.first < 0.0 || g.first > 1.0 ) {
112 throw std::runtime_error(
"Color Normalization gradient out of [ 0.0, 1.0 ]" );
114 grad.add_stop({ g.first, g.second });
126 return { grad, group };
131 std::map<double, Color>
const& stops
135 for(
auto it = stops.begin(); it != stops.end(); ++it ) {
138 auto const& pos = it->first;
139 auto const& color = it->second;
140 if( pos < 0.0 || pos > 1.0 ) {
141 throw std::runtime_error(
"Color Normalization stops out of [ 0.0, 1.0 ]" );
156 double next_pos = 1.0;
157 if( next != stops.end() ) {
158 next_pos = next->first;
160 assert( next_pos > pos );
165 double w = settings.
width;
166 double h = settings.
height;
170 h = ( next_pos - pos ) * settings.
height;
174 y = pos * settings.
height;
175 h = ( next_pos - pos ) * settings.
height;
179 x = pos * settings.
width;
180 w = ( next_pos - pos ) * settings.
width;
184 x = settings.
width - next_pos * settings.
width;
185 w = ( next_pos - pos ) * settings.
width;
189 throw std::runtime_error(
"Invalid SvgPalette direction." );
219 auto make_tick = [&](
double rel_pos, std::string label ){
220 assert( 0.0 <= rel_pos && rel_pos <= 1.0 );
231 v = rel_pos * settings.
height;
235 h = rel_pos * settings.
width;
239 h = settings.
width - ( rel_pos * settings.
width );
243 throw std::runtime_error(
"Invalid SvgPalette direction." );
277 throw std::runtime_error(
"Invalid SvgPalette direction." );
282 if( rel_pos != 0.0 && rel_pos != 1.0 ) {
283 group <<
SvgLine( line1_p1, line1_p2 );
284 group <<
SvgLine( line2_p1, line2_p2 );
287 if( rel_pos == 1.0 && map.
clip_over() ) {
288 label =
"≥ " + label;
291 label =
"≤ " + label;
293 auto text_s =
SvgText( label );
311 for(
auto const& tick : tickmarks ) {
312 if( tick.first < 0.0 || tick.first > 1.0 ) {
313 throw std::runtime_error(
"Color Normalization tickmark out of [ 0.0, 1.0 ]" );
315 make_tick( tick.first, tick.second );
328 std::string
const&
id
332 throw std::runtime_error(
333 "Cannot make SvgPalette with a ColorMap of less than two colors."
337 throw std::runtime_error(
338 "Invaid ColorNormalization settings."
343 auto result = std::pair<SvgGradientLinear, SvgGroup>();
348 if( norm_boundary ) {
349 auto const norm_gradient =
color_stops( map, norm );
368 0.0, i * 15.0, 10.0, 10.0,
377 std::vector<std::string>
const&
labels
381 for(
size_t i = 0; i <
labels.size(); ++i ) {
389 std::vector<Color>
const& colors,
390 std::vector<std::string>
const&
labels
392 if( colors.size() !=
labels.size() ) {
393 throw std::invalid_argument(
"List of colors and list of labels have different size." );
397 for(
size_t i = 0; i <
labels.size(); ++i ) {
Store a list of colors and offer them as a map for values in range [ 0.0, 1.0 ].
std::map< double, Color > color_stops(ColorMap const &map, ColorNormalization const &norm)
std::pair< SvgGradientLinear, SvgGroup > make_svg_color_bar(SvgColorBarSettings const &settings, ColorMap const &map, ColorNormalization const &norm, std::string const &id)
static std::pair< SvgGradientLinear, SvgGroup > make_svg_color_bar_discrete_(SvgColorBarSettings const &settings, std::map< double, Color > const &stops)
Base class for color normalization.
void make_svg_color_list_entry_(size_t i, Color const &color, std::string const &label, SvgGroup &group)
bool clip_over() const
Clip (clamp) values greater than max() to be inside [ min, max ].
std::map< double, std::string > color_tickmarks(ColorNormalization const &norm, size_t num_ticks)
std::string to_string(GenomeLocus const &locus)
Provides some commonly used string utility functions.
std::unordered_set< std::string > labels(SequenceSet const &set)
Return a set of all labels of the SequenceSet.
bool is_valid() const
Return whether ranges and other values are correct.
Color normalization that maps to discrete intervals.
static std::pair< SvgGradientLinear, SvgGroup > make_svg_color_bar_gradient_(SvgColorBarSettings const &settings, ColorMap const &map, ColorNormalization const &norm, std::string const &id)
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
bool clip_under() const
Clip (clamp) values less than min() to be inside [ min, max ].
static void make_svg_color_bar_tickmarks_(SvgColorBarSettings const &settings, ColorMap const &map, ColorNormalization const &norm, SvgGroup &group)
ColorMap & palette(std::vector< Color > const &value)
SvgGroup make_svg_color_list(ColorMap const &map, std::vector< std::string > const &labels)
size_t size() const
Return the size of the map, that is, the number of colors in the list.
Color color(size_t index) const
Return a particular color from the palette, module the palette size.