|
@@ -395,22 +395,27 @@ protected:
|
|
|
Window(desc, window_number), has_negative_values(has_negative_values),
|
|
|
format_str_y_axis(format_str_y_axis)
|
|
|
{
|
|
|
InvalidateWindow(WC_GRAPH_LEGEND, 0);
|
|
|
this->num_vert_lines = 24;
|
|
|
|
|
|
/* Initialise the dataset */
|
|
|
this->OnTick();
|
|
|
|
|
|
this->graph_location.left = left;
|
|
|
this->graph_location.right = left + GRAPH_X_POSITION_BEGINNING + this->num_vert_lines * GRAPH_X_POSITION_SEPARATION - 1;
|
|
|
|
|
|
this->graph_location.top = top;
|
|
|
this->graph_location.bottom = top + height - 1;
|
|
|
}
|
|
|
|
|
|
void InitializeWindow(const WindowDesc *desc)
|
|
|
{
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
|
|
/* Initialise the dataset */
|
|
|
this->UpdateStatistics(true);
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
virtual void OnPaint()
|
|
|
{
|
|
|
this->DrawWidgets();
|
|
|
|
|
|
this->DrawGraph(this->graph_location);
|
|
@@ -426,12 +431,21 @@ public:
|
|
|
/* Clicked on legend? */
|
|
|
if (widget == BGW_KEY_BUTTON) ShowGraphLegend();
|
|
|
}
|
|
|
|
|
|
virtual void OnTick()
|
|
|
{
|
|
|
this->UpdateStatistics(false);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Update the statistics.
|
|
|
* @param initialize Initialize the data structure.
|
|
|
*/
|
|
|
void UpdateStatistics(bool initialize)
|
|
|
{
|
|
|
uint excluded_companies = _legend_excluded_companies;
|
|
|
|
|
|
/* Exclude the companies which aren't valid */
|
|
|
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
|
|
if (!Company::IsValidID(c)) SetBit(excluded_companies, c);
|
|
|
}
|
|
@@ -446,13 +460,13 @@ public:
|
|
|
int yr = _cur_year;
|
|
|
while (mo < 0) {
|
|
|
yr--;
|
|
|
mo += 12;
|
|
|
}
|
|
|
|
|
|
if (this->excluded_data == excluded_companies && this->num_on_x_axis == nums &&
|
|
|
if (!initialize && this->excluded_data == excluded_companies && this->num_on_x_axis == nums &&
|
|
|
this->year == yr && this->month == mo) {
|
|
|
/* There's no reason to get new stats */
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this->excluded_data = excluded_companies;
|
|
@@ -483,13 +497,13 @@ public:
|
|
|
/********************/
|
|
|
|
|
|
struct OperatingProfitGraphWindow : BaseGraphWindow {
|
|
|
OperatingProfitGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
|
|
|
BaseGraphWindow(desc, window_number, 2, 18, 136, true, STR_JUST_CURRCOMPACT)
|
|
|
{
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
this->InitializeWindow(desc);
|
|
|
}
|
|
|
|
|
|
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
|
|
{
|
|
|
return c->old_economy[j].income + c->old_economy[j].expenses;
|
|
|
}
|
|
@@ -531,13 +545,13 @@ void ShowOperatingProfitGraph()
|
|
|
/****************/
|
|
|
|
|
|
struct IncomeGraphWindow : BaseGraphWindow {
|
|
|
IncomeGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
|
|
|
BaseGraphWindow(desc, window_number, 2, 18, 104, false, STR_JUST_CURRCOMPACT)
|
|
|
{
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
this->InitializeWindow(desc);
|
|
|
}
|
|
|
|
|
|
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
|
|
{
|
|
|
return c->old_economy[j].income;
|
|
|
}
|
|
@@ -578,13 +592,13 @@ void ShowIncomeGraph()
|
|
|
/*******************/
|
|
|
|
|
|
struct DeliveredCargoGraphWindow : BaseGraphWindow {
|
|
|
DeliveredCargoGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
|
|
|
BaseGraphWindow(desc, window_number, 2, 18, 104, false, STR_JUST_COMMA)
|
|
|
{
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
this->InitializeWindow(desc);
|
|
|
}
|
|
|
|
|
|
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
|
|
{
|
|
|
return c->old_economy[j].delivered_cargo;
|
|
|
}
|
|
@@ -633,13 +647,13 @@ enum PerformanceHistoryGraphWidgets {
|
|
|
};
|
|
|
|
|
|
struct PerformanceHistoryGraphWindow : BaseGraphWindow {
|
|
|
PerformanceHistoryGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
|
|
|
BaseGraphWindow(desc, window_number, 2, 18, 200, false, STR_JUST_COMMA)
|
|
|
{
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
this->InitializeWindow(desc);
|
|
|
}
|
|
|
|
|
|
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
|
|
{
|
|
|
return c->old_economy[j].performance_history;
|
|
|
}
|
|
@@ -687,13 +701,13 @@ void ShowPerformanceHistoryGraph()
|
|
|
/*****************/
|
|
|
|
|
|
struct CompanyValueGraphWindow : BaseGraphWindow {
|
|
|
CompanyValueGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
|
|
|
BaseGraphWindow(desc, window_number, 2, 18, 200, false, STR_JUST_CURRCOMPACT)
|
|
|
{
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
this->InitializeWindow(desc);
|
|
|
}
|
|
|
|
|
|
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
|
|
{
|
|
|
return c->old_economy[j].company_value;
|
|
|
}
|