| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (C) 2009 by Guy Rutenberg * |
|---|
| 3 | * guyrutenberg@gmail.com * |
|---|
| 4 | * * |
|---|
| 5 | * This program is free software; you can redistribute it and/or modify * |
|---|
| 6 | * it under the terms of the GNU General Public License as published by * |
|---|
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
|---|
| 8 | * (at your option) any later version. * |
|---|
| 9 | * * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, * |
|---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|---|
| 13 | * GNU General Public License for more details. * |
|---|
| 14 | * * |
|---|
| 15 | * You should have received a copy of the GNU General Public License * |
|---|
| 16 | * along with this program; if not, write to the * |
|---|
| 17 | * Free Software Foundation, Inc., * |
|---|
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
|---|
| 19 | ***************************************************************************/ |
|---|
| 20 | |
|---|
| 21 | #include <wx/wx.h> |
|---|
| 22 | #include <vector> |
|---|
| 23 | |
|---|
| 24 | #ifndef SIMPLE_HISTOGRAM_INC |
|---|
| 25 | #define SIMPLE_HISTOGRAM_INC |
|---|
| 26 | |
|---|
| 27 | namespace simple_pie_plot { |
|---|
| 28 | |
|---|
| 29 | class SimplePiePlot : public wxPanel { |
|---|
| 30 | public: |
|---|
| 31 | SimplePiePlot (wxWindow* parent, wxWindowID id, |
|---|
| 32 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, |
|---|
| 33 | long style = wxNO_BORDER, const wxString& name = wxPanelNameStr); |
|---|
| 34 | void SetData(std::vector<double> d, std::vector<wxString> labels); |
|---|
| 35 | void OnPaint(wxPaintEvent& event); |
|---|
| 36 | void OnResize(wxSizeEvent& event); |
|---|
| 37 | void OnMouseLeaveWindow(wxMouseEvent& event); |
|---|
| 38 | void OnMouseMove(wxMouseEvent& event); |
|---|
| 39 | wxSize GetMinSize() const; |
|---|
| 40 | private: |
|---|
| 41 | /** |
|---|
| 42 | * Gets the color suiting the \a i th segment. |
|---|
| 43 | * \param i The segment number. |
|---|
| 44 | */ |
|---|
| 45 | wxColour GetSegmentColor(int i); |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * Calculate the angles in the plot and populate the m_angles array. |
|---|
| 49 | */ |
|---|
| 50 | void CalculateAngles(); |
|---|
| 51 | |
|---|
| 52 | /** |
|---|
| 53 | * Calculate the maximum widht and height for a label in the legend. |
|---|
| 54 | */ |
|---|
| 55 | void CalculateLegendDimensions(wxGraphicsContext *dc); |
|---|
| 56 | |
|---|
| 57 | /** |
|---|
| 58 | * Calculate the location and radius of the pie plot. |
|---|
| 59 | */ |
|---|
| 60 | void CalculatePiePlotLocation(); |
|---|
| 61 | |
|---|
| 62 | void DrawLegend(wxGraphicsContext *dc); |
|---|
| 63 | |
|---|
| 64 | void Highlight(int i); |
|---|
| 65 | void ClearHighlight(); |
|---|
| 66 | |
|---|
| 67 | std::vector<double> m_data; |
|---|
| 68 | std::vector<wxString> m_labels; |
|---|
| 69 | std::vector<double> m_angles; |
|---|
| 70 | double m_data_total; |
|---|
| 71 | int m_highlight; |
|---|
| 72 | |
|---|
| 73 | /// maximum width for a label in the legend. |
|---|
| 74 | double m_max_legend_width; |
|---|
| 75 | /// maximum height for a label in the legend. |
|---|
| 76 | double m_max_legend_height; |
|---|
| 77 | /// total width of the legend |
|---|
| 78 | double m_legend_width; |
|---|
| 79 | /// the line height of each legend entry including padding |
|---|
| 80 | double m_legend_line_height; |
|---|
| 81 | |
|---|
| 82 | static const double m_legend_left_padding = 10; |
|---|
| 83 | |
|---|
| 84 | // The center point of the pie plot |
|---|
| 85 | double m_pie_x; |
|---|
| 86 | double m_pie_y; |
|---|
| 87 | double m_radius; |
|---|
| 88 | |
|---|
| 89 | }; |
|---|
| 90 | |
|---|
| 91 | } // namespace |
|---|
| 92 | |
|---|
| 93 | #endif |
|---|