Return a unicode bar plot. * @param n number of buckets */
| 67 | * @param n number of buckets |
| 68 | */ |
| 69 | string Histogram::barplot(unsigned nbins) const |
| 70 | { |
| 71 | /** Unicode bar characters. */ |
| 72 | static const char* bars[10] = { |
| 73 | " ", "_", |
| 74 | "\342\226\201", // 9601 |
| 75 | "\342\226\202", // 9602 |
| 76 | "\342\226\203", // 9603 |
| 77 | "\342\226\204", // 9604 |
| 78 | "\342\226\205", // 9605 |
| 79 | "\342\226\206", // 9606 |
| 80 | "\342\226\207", // 9607 |
| 81 | "\342\226\210", // 9608 |
| 82 | }; |
| 83 | |
| 84 | Histogram::Bins bins = bin(nbins); |
| 85 | ostringstream ss; |
| 86 | Histogram::Bins::value_type max |
| 87 | = 1 + *max_element(bins.begin(), bins.end()); |
| 88 | for (Histogram::Bins::const_iterator it = bins.begin(); |
| 89 | it != bins.end(); ++it) |
| 90 | ss << bars[10 * *it / max]; |
| 91 | string s(ss.str()); |
| 92 | while (!s.empty() && *s.rbegin() == ' ') |
| 93 | s.erase(s.size() - 1); |
| 94 | return s; |
| 95 | } |
| 96 | |
| 97 | /** Return a unicode bar plot. */ |
| 98 | string Histogram::barplot() const |
no test coverage detected