1 #ifndef _ScatterDraw_PieDraw_h_ 2 #define _ScatterDraw_PieDraw_h_ 3 4 #include <Draw/Draw.h> 5 #include <Painter/Painter.h> 6 #include "DataSource.h" 7 8 namespace Upp { 9 10 class PieDraw { 11 public: 12 PieDraw(); ~PieDraw()13 virtual ~PieDraw() noexcept {}; 14 15 enum titlePosition {BOTTOM, TOP}; 16 SetColor(const Color & _color)17 PieDraw& SetColor(const Color& _color) {backColor = _color; 18 RGBA r; 19 r = backColor; 20 r.a = 0; 21 backColor = r; 22 23 return *this;} SetTitle(const String & _title)24 PieDraw& SetTitle(const String& _title) {title = _title; return *this;} GetTitle()25 String GetTitle() {return title;} SetTitleFont(const Upp::Font & font)26 PieDraw& SetTitleFont(const Upp::Font& font){titleFont = font; return *this;} SetTitleColor(const Color & color)27 PieDraw& SetTitleColor(const Color& color) {titleColor = color; return *this;} SetTitlePos(titlePosition pos)28 PieDraw& SetTitlePos(titlePosition pos) {titlePos = pos; return *this;} SetTitleGap(const int & gap)29 PieDraw& SetTitleGap(const int& gap) {titleGap = gap; return *this;} 30 31 PieDraw& ShowPercent(bool show = true) {showPercent = show; return *this;} SetPercentBack(const Color & pbcolor)32 PieDraw& SetPercentBack(const Color& pbcolor) {percentBack = pbcolor; return *this;} 33 34 PieDraw& ShowLegend(bool show = true) {showLegend = show; return *this;} SetLegendFont(const Upp::Font & font)35 PieDraw& SetLegendFont(const Upp::Font& font) {legendFont = font; return *this;} SetLegendTextColor(const Color & color)36 PieDraw& SetLegendTextColor(const Color& color) {legendTextColor = color; return *this;} SetLegendBackColor(const Color & color)37 PieDraw& SetLegendBackColor(const Color& color) {legendBackColor = color; return *this;} SetLegendLeft(const int & left)38 PieDraw& SetLegendLeft(const int& left) {legendLeft = left; return *this;} SetLegendTop(const int & top)39 PieDraw& SetLegendTop(const int& top) {legendTop = top; return *this;} 40 SetPieAngle(const double & angle)41 PieDraw& SetPieAngle(const double& angle) {pieAngle = angle; return *this;} SetPieMarginLeft(const int & left)42 PieDraw& SetPieMarginLeft(const int& left) {pieMarginLeft = left; return *this;} SetPieMarginTop(const int & top)43 PieDraw& SetPieMarginTop(const int& top) {pieMarginTop = top; return *this;} SetPieMarginRight(const int & right)44 PieDraw& SetPieMarginRight(const int& right) {pieMarginRight = right; return *this;} SetPieMarginBottom(const int & bottom)45 PieDraw& SetPieMarginBottom(const int& bottom) {pieMarginBottom = bottom; return *this;} 46 47 void AddCategory(const String& name, const double& value, const Color& catcolor); 48 void RemoveCategory(const int& index); 49 PieDraw& SetCatValue(const int& index, const double& value); 50 PieDraw& SetCatName(const int& index, const String& name); 51 PieDraw& SetCatColor(const int& index, const Color& catcolor); 52 double GetCatValue (const int& index)const; 53 String GetCatName (const int& index)const; 54 Color GetCatColor (const int& index)const; GetCatCount()55 int GetCatCount() const {return vColors.GetCount();} 56 57 Drawing GetDrawing(int scale = 3); 58 Image GetImage(int scale = 1); 59 Refresh()60 virtual void Refresh() {}; 61 SetSize(Size sz)62 PieDraw& SetSize(Size sz) {size = sz; return *this;}; GetSize()63 virtual Size GetSize() const {return size;}; 64 65 protected: 66 void PaintPie(Draw& w, int scale); 67 68 private: 69 Color backColor; 70 String title; 71 Upp::Font titleFont; 72 Color titleColor; 73 titlePosition titlePos; 74 int titleGap; 75 76 bool showPercent; 77 Color percentBack; 78 79 Upp::Font legendFont; 80 Color legendTextColor, legendBackColor; 81 bool showLegend; 82 int legendLeft, legendTop; 83 84 double pieAngle; 85 int pieMarginLeft, pieMarginTop, pieMarginRight, pieMarginBottom; 86 87 Vector<String> vNames; 88 Vector<double> vValues; 89 Vector<Color> vColors; 90 91 Size size; 92 93 String GetPercent(double a, double total); 94 }; 95 96 } 97 98 #endif 99