plot_data.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <limits>
14 
15 namespace illumina { namespace interop { namespace logic { namespace plot
16 {
17 
24  template<typename Point>
25  void auto_scale(model::plot::plot_data <Point> &data, const bool zero_min = true, const float scale_y_max = 1.1f)
26  {
27  typedef typename model::plot::plot_data<Point>::const_iterator const_series_iterator;
28  typedef typename model::plot::series<Point>::const_iterator const_point_iterator;
29  float ymin = std::numeric_limits<float>::max();
30  float xmin = std::numeric_limits<float>::max();
31  float ymax = -std::numeric_limits<float>::max();
32  float xmax = -std::numeric_limits<float>::max();
33  for (const_series_iterator cur_series = data.begin(), series_end = data.end();
34  cur_series != series_end; ++cur_series)
35  {
36  for (const_point_iterator cur_pt = cur_series->begin(), end_pt = cur_series->end();
37  cur_pt != end_pt; ++cur_pt)
38  {
39  ymax = std::max(ymax, cur_pt->max_value());
40  xmax = std::max(xmax, cur_pt->x());
41  if (zero_min) continue;
42  ymin = std::min(ymin, cur_pt->min_value());
43  xmin = std::min(xmin, cur_pt->x());
44  }
45  }
46  if (ymin == std::numeric_limits<float>::max()) ymin = 0;
47  if (xmin == std::numeric_limits<float>::max()) xmin = 0;
48  ymax = (ymax == -std::numeric_limits<float>::max()) ? 0 : scale_y_max * ymax + 0.0001f;
49  if (xmax == -std::numeric_limits<float>::max()) xmax = 0;
50  data.set_range(xmin, xmax, ymin, ymax);
51  }
52 
58  template<typename Point>
59  void auto_scale_x(model::plot::plot_data <Point> &data, const bool zero_min = true)
60  {
61  typedef typename model::plot::plot_data<Point>::const_iterator const_series_iterator;
62  typedef typename model::plot::series<Point>::const_iterator const_point_iterator;
63  float xmin = std::numeric_limits<float>::max();
64  float xmax = -std::numeric_limits<float>::max();
65  for (const_series_iterator cur_series = data.begin(), series_end = data.end();
66  cur_series != series_end; ++cur_series)
67  {
68  for (const_point_iterator cur_pt = cur_series->begin(), end_pt = cur_series->end();
69  cur_pt != end_pt; ++cur_pt)
70  {
71  xmax = std::max(xmax, cur_pt->x());
72  if (zero_min) continue;
73  xmin = std::min(xmin, cur_pt->x());
74  }
75  }
76  if (xmin == std::numeric_limits<float>::max()) xmin = 0;
77  if (xmax == -std::numeric_limits<float>::max()) xmax = 0;
78  data.set_xrange(xmin, xmax);
79  }
80 
87  template<typename Point>
88  void auto_scale_y(model::plot::plot_data <Point> &data, const bool zero_min = true, const float scale_y_max = 1.1f)
89  {
90  typedef typename model::plot::plot_data<Point>::const_iterator const_series_iterator;
91  typedef typename model::plot::series<Point>::const_iterator const_point_iterator;
92  float ymin = std::numeric_limits<float>::max();
93  float ymax = -std::numeric_limits<float>::max();
94  for (const_series_iterator cur_series = data.begin(), series_end = data.end();
95  cur_series != series_end; ++cur_series)
96  {
97  for (const_point_iterator cur_pt = cur_series->begin(), end_pt = cur_series->end();
98  cur_pt != end_pt; ++cur_pt)
99  {
100  ymax = std::max(ymax, cur_pt->max_value());
101  if (zero_min) continue;
102  ymin = std::min(ymin, cur_pt->min_value());
103  }
104  }
105  if (ymin == std::numeric_limits<float>::max()) ymin = 0;
106  ymax = (ymax == -std::numeric_limits<float>::max()) ? 0 : scale_y_max * ymax + 0.0001f;
107  data.set_yrange(ymin, ymax);
108  }
109 
110 
117  inline std::string color_name_for_index(const size_t index)
118  {
119  const char* more_colors[] =
120  {
121  "#01FFFE",
122  "#FFA6FE",
123  "#FFDB66",
124  "#006401",
125  "#010067",
126  "#95003A",
127  "#007DB5",
128  "#FF00F6",
129  "#FFEEE8",
130  "#774D00",
131  "#90FB92",
132  "#0076FF",
133  "#D5FF00",
134  "#FF937E",
135  "#6A826C",
136  "#FF029D",
137  "#FE8900",
138  "#7A4782",
139  "#7E2DD2",
140  "#85A900",
141  "#FF0056",
142  "#A42400",
143  "#00AE7E",
144  "#683D3B",
145  "#BDC6FF",
146  "#263400",
147  "#BDD393",
148  "#00B917",
149  "#9E008E",
150  "#001544",
151  "#C28C9F",
152  "#FF74A3",
153  "#01D0FF",
154  "#004754",
155  "#E56FFE",
156  "#788231",
157  "#0E4CA1",
158  "#91D0CB",
159  "#BE9970",
160  "#968AE8",
161  "#BB8800",
162  "#43002C",
163  "#DEFF74",
164  "#00FFC6",
165  "#FFE502",
166  "#620E00",
167  "#008F9C",
168  "#98FF52",
169  "#7544B1",
170  "#B500FF",
171  "#00FF78",
172  "#FF6E41",
173  "#005F39",
174  "#6B6882",
175  "#5FAD4E",
176  "#A75740",
177  "#A5FFD2",
178  "#FFB167",
179  "#009BFF",
180  "#E85EBE"
181  };
182  const size_t color_offset = static_cast<size_t>(constants::PlotColorCount);
183  if(index < color_offset)
184  {
186  return constants::to_string(static_cast<constants::plot_colors>(index));
187  }
188  if(index >= (util::length_of(more_colors)+color_offset))
189  {
191  }
192  return more_colors[index-color_offset];
193  }
194 }}}}
195 
series_collection_t::const_iterator const_iterator
Definition: plot_data.h:42
Definition: enum_description.h:15
const_iterator end() const
Definition: plot_data.h:147
void auto_scale(model::plot::plot_data< Point > &data, const bool zero_min=true, const float scale_y_max=1.1f)
Definition: plot_data.h:25
const_iterator begin() const
Definition: plot_data.h:139
std::string color_name_for_index(const size_t index)
Definition: plot_data.h:117
void set_xrange(const float vmin, const float vmax)
Definition: chart_data.h:85
void auto_scale_x(model::plot::plot_data< Point > &data, const bool zero_min=true)
Definition: plot_data.h:59
#define INTEROP_ASSERT(TST)
Definition: assert.h:21
void set_range(const float xmin, const float xmax, const float ymin, const float ymax)
Definition: chart_data.h:74
void auto_scale_y(model::plot::plot_data< Point > &data, const bool zero_min=true, const float scale_y_max=1.1f)
Definition: plot_data.h:88
void set_yrange(const float vmin, const float vmax)
Definition: chart_data.h:95
size_t length_of(const T &val)
Definition: length_of.h:55
std::string to_string(Enum value)
Definition: enums.h:43
point_collection_t::const_iterator const_iterator
Definition: series.h:25