Add "non fix" category to statistics (sum of all non fix categories)

This commit is contained in:
2011-05-28 19:31:42 +02:00
parent 33a2cd1f0c
commit 6fae41b4e8
5 changed files with 56 additions and 21 deletions

View File

@@ -92,7 +92,7 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent),
_statsGrid = new wxGrid(this, wxID_ANY);
_statsGrid->CreateGrid(user->GetCategoriesNumber(), 2);
_statsGrid->CreateGrid(user->GetCategoriesNumber()+1, 2);
_statsGrid->SetColLabelSize(0);
_statsGrid->SetRowLabelSize(0);
_statsGrid->EnableEditing(false);
@@ -102,10 +102,21 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent),
for(i=0; i<user->GetCategoriesNumber(); i++)
{
_statsGrid->SetCellValue(i, 0, _categories[i]);
_statsGrid->SetCellAlignment(i, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
if (i)
{
_statsGrid->SetCellValue(i+1, 0, _categories[i]);
_statsGrid->SetCellAlignment(i+1, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
}
else
{
_statsGrid->SetCellValue(i, 0, _categories[i]);
_statsGrid->SetCellAlignment(i, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
}
}
_statsGrid->SetCellValue(1, 0, _("Non fix"));
_statsGrid->SetCellAlignment(1, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
_vbox2->Add(_account, 0, wxGROW|wxALL, 5);
_vbox2->Add(_statsGrid, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 5);
@@ -127,11 +138,11 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent),
_pie->SetLegend(new Legend(wxBOTTOM, wxCENTER));
wxChartPanel* chart = new wxChartPanel(this);
chart->SetChart(new Chart(_pie, _("Cost repartition")));
chart->Fit();
chart->Layout();
chart->SetMinSize(// chart->GetSize()
_chartCategories = new wxChartPanel(this);
_chartCategories->SetChart(new Chart(_pie, _("Cost repartition")));
_chartCategories->Fit();
_chartCategories->Layout();
_chartCategories->SetMinSize(// chart->GetSize()
wxSize(200,250));
vbox->Add(hbox, 0, wxALIGN_CENTER_VERTICAL|wxGROW|wxALL, 5);
@@ -140,8 +151,6 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent),
wxCommandEvent event ;
OnRangeChange(event);
_hbox2->Add(chart, 0, wxGROW|wxALL, 10);
Fit();
}
@@ -171,7 +180,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
std::vector<Account>::iterator accountIt;
std::map<wxString, double>::iterator categoriesIt;
std::map<int, std::map<int, double> >::iterator accountYearIt;
double total;
double total, non_fix;
int account, size, i, a, b, percents, nbDays;
double *amounts;
wxString value;
@@ -183,6 +192,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
{
_hbox2->Detach(_chart);
_hbox2->Detach(_vbox2);
_hbox2->Detach(_chartCategories);
delete _chart;
}
@@ -335,7 +345,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
for(categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++)
total += categoriesIt->second;
for(categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++)
for(i=0, categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++, i++)
{
_categoriesValues[_categoriesIndexes[categoriesIt->first]] = categoriesIt->second;
if (total)
@@ -343,15 +353,28 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
else
percents = 0;
value = wxString::Format(wxT("%0.2lf (%02d%%)"), categoriesIt->second, percents);
_statsGrid->SetCellValue(_categoriesIndexes[categoriesIt->first], 1, value);
if (i)
_statsGrid->SetCellValue(_categoriesIndexes[categoriesIt->first]+1, 1, value);
else
_statsGrid->SetCellValue(_categoriesIndexes[categoriesIt->first], 1, value);
}
non_fix = total - _categoriesValues[0];
if (total)
percents = ((double) (non_fix*100))/total;
else
percents = 0;
value = wxString::Format(wxT("%0.2lf (%02d%%)"), non_fix, percents);
_statsGrid->SetCellValue(1, 1, value);
_statsGrid->AutoSizeColumn(0, true);
_statsGrid->AutoSizeColumn(1, true);
_pie->DatasetChanged(_dataset);
_hbox2->Add(_vbox2, 0, wxGROW|wxALL, 5);
_hbox2->Add(_chartCategories, 0, wxGROW|wxALL, 10);
Layout();
}