1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
* \class storage::PieChart
* \ingroup util
*
* \brief Helper library to print pie charts in HTML.
*/
#pragma once
#include <string>
#include <vector>
#include <ostream>
namespace storage {
class PieChart {
public:
static double _minValue;
enum ColorScheme {
SCHEME_CUSTOM,
SCHEME_RED,
SCHEME_BLUE
};
enum Color {
UNDEFINED = -1,
BLACK = 0x000000,
RED = 0xFF0000,
GREEN = 0x00FF00,
BLUE = 0x0000FF,
WHITE = 0xFFFFFF
};
struct Entry {
double _value;
std::string _name;
int32_t _color;
Entry(double val, const std::string& name, int32_t col);
};
static void printHtmlHeadAdditions(
std::ostream& out, const std::string& indent = "");
private:
const std::string _name;
std::vector<Entry> _values;
ColorScheme _colors;
bool _printLabels;
public:
PieChart(const std::string&, ColorScheme = SCHEME_BLUE);
~PieChart();
void printLabels(bool doprint) { _printLabels = doprint; }
void add(double value, const std::string& name);
void add(double value, const std::string& name, Color c);
void add(double value, const std::string& name, int32_t color);
void printCanvas(std::ostream& out, uint32_t width, uint32_t height) const;
void printScript(std::ostream& out, const std::string& indent = "") const;
};
} // storage
|