10 #include <wx/bars/barplot.h>
12 #include <wx/chartpanel.h>
14 #include <wx/axis/numberaxis.h>
15 #include <wx/axis/categoryaxis.h>
17 #include <wx/xy/xyhistorenderer.h>
19 #include <wx/category/categorysimpledataset.h>
53 GraphDialog( wxWindow* parent, wxWindowID
id = wxID_ANY,
const wxString& title = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxSize( 1000,650 ),
long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
58 GraphDialog::GraphDialog( wxWindow* parent, wxWindowID
id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style ) : wxDialog( parent, id, title, pos, size, style )
60 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
65 this->SetForegroundColour( wxColor(ColorRed[8],ColorGreen[8],ColorBlue[8]) );
66 this->SetBackgroundColour( wxColor(ColorRed[7],ColorGreen[7],ColorBlue[7]) );
69 bSizer1 =
new wxBoxSizer( wxVERTICAL );
74 m_staticline1 =
new wxStaticLine(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
78 gSizer1 =
new wxGridSizer( 0, 3, 0, 0 );
80 GraphList =
new wxListView(
this, wxID_ANY, wxDefaultPosition, wxSize( -1,-1 ),wxLC_REPORT );
82 gSizer1->Add(
GraphList, 1, wxALL|wxEXPAND, 5 );
85 bSizer2 =
new wxBoxSizer( wxVERTICAL );
88 gSizer2 =
new wxGridSizer( 0, 2, 0, 0 );
90 wxArrayString GraphModeChoiceChoices;
91 GraphModeChoice =
new wxChoice(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, GraphModeChoiceChoices, 0 );
95 GraphModeStat =
new wxStaticText(
this, wxID_ANY,
l(
"Step 1 - Graph Mode"), wxDefaultPosition, wxDefaultSize, 0 );
97 gSizer2->Add(
GraphModeStat, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL, 5 );
100 bSizer2->Add( gSizer2, 1, wxEXPAND, 5 );
102 GraphRefreshButton =
new wxButton(
this, wxID_ANY,
l(
"Step 3 - Refresh Graph"), wxDefaultPosition, wxDefaultSize, 0 );
106 GraphSaveButton =
new wxButton(
this,wxID_ANY,
l(
"Save Graph As Image"), wxDefaultPosition, wxDefaultSize, 0 );
110 GraphCloseButton =
new wxButton(
this, wxID_ANY,
l(
"Close"), wxDefaultPosition, wxDefaultSize, 0 );
114 gSizer1->Add( bSizer2, 1, wxEXPAND, 5 );
117 bSizer3 =
new wxBoxSizer( wxVERTICAL );
119 BlueCheckBox =
new wxCheckBox(
this, wxID_ANY,
l(
"Show % Were Fertile(Blue)"), wxDefaultPosition, wxDefaultSize, 0 );
123 YellowCheckBox =
new wxCheckBox(
this, wxID_ANY,
l(
"Show % Of Fertile Hatched(Yellow)"), wxDefaultPosition, wxDefaultSize, 0 );
127 RedCheckBox =
new wxCheckBox(
this, wxID_ANY,
l(
"Show % Of Total Hatched(Red)"), wxDefaultPosition, wxDefaultSize, 0 );
131 GreenCheckBox =
new wxCheckBox(
this, wxID_ANY,
l(
"Show % Of Total Unhatched(Green)"), wxDefaultPosition, wxDefaultSize, 0 );
136 gSizer1->Add( bSizer3, 1, wxEXPAND, 5 );
139 bSizer1->Add( gSizer1, 0, wxEXPAND, 5 );
147 this->SetSizer( bSizer1 );
150 this->Centre( wxBOTH );
159 wxInitAllImageHandlers();
185 if(
GraphList->GetSelectedItemCount() > 0)
192 if(
GraphList->GetSelectedItemCount() > 1)
205 vector<string> TempNames;
206 vector<double> TempValues1,TempValues2,TempValues3,TempValues4;
216 wxMessageDialog dialog(
this,
217 l(
"Hey Change The Mode And Select\nSomthing From The List!"));
233 if(TempNames.size() < 2) {
234 wxMessageDialog dialog(
this,
235 l(
"You'll Need To Select More Than 1\n Batch For This To Work.\n\nHold CTRL or Cmd + Click\n To Select Multiple Items."));
239 GrTitle =
l(
"Batches");
254 if(TempNames.size() < 2) {
255 wxMessageDialog dialog(
this,
256 l(
"This Group Only Has One Batch!\nAdd Some More To Compare."));
272 TempValues1.push_back(z[0]);
273 TempValues2.push_back(z[1]);
274 TempValues3.push_back(z[2]);
275 TempValues4.push_back(z[3]);
278 if(TempNames.size() < 2) {
279 wxMessageDialog dialog(
this,
280 l(
"You'll Need To Select More Than 1 Group\nFor This To Work.\n\nHold CTRL or Cmd + Click\n To Select Multiple Items"));
284 GrTitle =
l(
"Group Averages");
288 int DataCount = TempNames.size();
290 wxString names[DataCount];
291 double values1[DataCount];
292 double values2[DataCount];
293 double values3[DataCount];
294 double values4[DataCount];
296 bool oneFound =
false;
298 for(b = 0; b < DataCount; b++) {
299 names[b] = TempNames[b];
302 values1[b] = TempValues1[b];
309 values2[b] = TempValues2[b];
316 values3[b] = TempValues3[b];
323 values4[b] = TempValues4[b];
331 if(oneFound ==
false) {
332 wxMessageDialog dialog(
this,
333 l(
"You'll Need At Least One Check Box Checked!"));
339 CategorySimpleDataset *dataset =
new CategorySimpleDataset(names, WXSIZEOF(names));
343 dataset->AddSerie(
l(
"% Were Fertile"), values1, WXSIZEOF(values1));
344 dataset->AddSerie(
l(
"% Of Fertile Hatched"), values2, WXSIZEOF(values2));
345 dataset->AddSerie(
l(
"% Of Total Hatched"), values3, WXSIZEOF(values3));
346 dataset->AddSerie(
l(
"% Of Total UnHatched"), values4, WXSIZEOF(values4));
348 BarType *barType =
new LayeredBarType(40, 0);
351 BarRenderer *renderer =
new BarRenderer(barType);
354 renderer->SetBarDraw(0,
new GradientAreaDraw(*wxBLUE, wxColor(0,171,255),
355 wxColor(0,171,255).ChangeLightness(150), wxNORTH));
356 renderer->SetBarDraw(1,
new GradientAreaDraw(*wxYELLOW, wxColor(215,215,35),
357 wxColor(215,215,35).ChangeLightness(150), wxNORTH));
359 renderer->SetBarDraw(2,
new GradientAreaDraw(*wxRED, wxColor(255,0,0),
360 wxColor(255,0,0).ChangeLightness(150), wxNORTH));
362 renderer->SetBarDraw(3,
new GradientAreaDraw(*wxGREEN, wxColor(0,128,0),
363 wxColor(0,128,0).ChangeLightness(150), wxNORTH));
366 dataset->SetRenderer(renderer);
369 BarPlot *plot =
new BarPlot();
372 NumberAxis *leftAxis =
new NumberAxis(AXIS_LEFT);
373 leftAxis->SetMargins(0, 0);
374 plot->AddAxis(leftAxis);
377 CategoryAxis *bottomAxis =
new CategoryAxis(AXIS_BOTTOM);
378 bottomAxis->SetMargins(20, 20);
379 plot->AddAxis(bottomAxis);
382 plot->AddDataset(dataset);
385 plot->LinkDataHorizontalAxis(0, 0);
388 plot->LinkDataVerticalAxis(0, 0);
391 Legend* legend =
new Legend(wxCENTER, wxRIGHT,
new FillAreaDraw(*wxTRANSPARENT_PEN, *wxTRANSPARENT_BRUSH));
392 plot->SetLegend(legend);
404 string ext1, ext2 =
"png";
408 wxFileDialog dlg(
this,
l(
"Choose file..."), wxEmptyString, wxEmptyString,
409 wxString(wxT(
"PNG files (*.png)|*.png")), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
411 if (dlg.ShowModal() != wxID_OK)
414 path = dlg.GetPath();
416 wxFileName fname(path.c_str());
417 ext1 = fname.GetExt();
420 path = path +
".png";
424 bitmap.ConvertToImage().SaveFile(path.c_str(), wxBITMAP_TYPE_PNG);
427 wxMessageDialog dialog(
this,
428 l(
"Error! No Graph is Being Shown!"));
443 GraphList->InsertColumn(0,
l(
"Step 2 - Select Item(s)" ), wxLIST_FORMAT_LEFT, 400);
470 int fertileTotal = 0;
471 int hatchOfTotal = 0;
485 Out.push_back(fertileTotal / d);
486 Out.push_back(hatchOfTotal / d);
487 Out.push_back(hatchOfFer / d);
488 Out.push_back(unHatchOfT / d);
std::string l(std::string Text)
A Helper Function For HK_Language.
A Dialog For Viewing Graph Stats.
void OnModeChoice(wxCommandEvent &)
wxChoice * GraphModeChoice
wxCheckBox * GreenCheckBox
wxButton * GraphSaveButton
void OnGraphRefresh(wxCommandEvent &)
Redraws The Graph When The Refresh Button Is Clicked.
void OnListSelect(wxListEvent &evt)
wxButton * GraphRefreshButton
vector< int > GroupAverage(int a)
Returns An Array Of Group Averages.
wxButton * GraphCloseButton
GraphDialog(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(1000, 650), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
Constructor.
void OnGraphClose(wxCommandEvent &)
Closes Dialog.
wxStaticText * GraphModeStat
wxChartPanel * GraphChartPanel
void FillGraphList(int a)
Populates GraphList.
void OnGraphSave(wxCommandEvent &)
Saves The Graph To A PNG File.
wxCheckBox * YellowCheckBox
wxStaticLine * m_staticline1
wxCheckBox * BlueCheckBox
int PercentOfTotalUnhatched(int Select)
Returns The Percentage Of Total Eggs That Didn't Hatch For The Selected Batch.
int GetFertile(int Select)
Returns Number Of Fertile Eggs For Selected Batch.
int PercentOfTotal(int Select)
Returns The Percentage Of Total Eggs That Hatched For The Selected Batch.
string GetGroup(int Select)
Returns Batch Group For Selected Batch.
int PercentFertile(int Select)
Returns The Percentage Of Egg That Were Fertile For The Selected Batch.
int GetCount()
Returns The Number Of Batches Stored.
int PercentOfFertile(int Select)
Returns The Percentage Of Fertile Eggs That Hatched For The Selected Batch.
string GetName(int Select)
Returns Batch Name For Selected Batch.
vector< int > GetIntArray(int Selection)
Returns The Selected Value As An Array Of Integers.
int GetCount()
Returns The Number Of Elements Stored.
string GetName(int Select)
Returns The Selected Stored Name.