diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -165,10 +165,15 @@ struct ValuesInterval { struct BaseGraphWindow : Window { protected: static const int GRAPH_MAX_DATASETS = 64; + static const int GRAPH_BASE_COLOUR = GREY_SCALE(2); + static const int GRAPH_GRID_COLOUR = GREY_SCALE(3); static const int GRAPH_AXIS_LINE_COLOUR = GREY_SCALE(1); static const int GRAPH_ZERO_LINE_COLOUR = GREY_SCALE(8); + static const int GRAPH_YEAR_LINE_COLOUR = GREY_SCALE(5); static const int GRAPH_NUM_MONTHS = 24; ///< Number of months displayed in the graph. + static const TextColour GRAPH_AXIS_LABEL_COLOUR = TC_BLACK; ///< colour of the graph axis label. + static const int MIN_GRAPH_NUM_LINES_Y = 9; ///< Minimal number of horizontal lines to draw. static const int MIN_GRID_PIXEL_SIZE = 20; ///< Minimum distance between graph lines. @@ -176,7 +181,6 @@ protected: byte num_dataset; byte num_on_x_axis; byte num_vert_lines; - static const TextColour graph_axis_label_colour = TC_BLACK; ///< colour of the graph axis label. /* The starting month and year that values are plotted against. If month is * 0xFF, use x_values_start and x_values_increment below instead. */ @@ -293,12 +297,10 @@ protected: static_assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_COMPANIES); assert(this->num_vert_lines > 0); - byte grid_colour = GREY_SCALE(3); - /* Rect r will be adjusted to contain just the graph, with labels being * placed outside the area. */ r.top += 5 + GetCharacterHeight(FS_SMALL) / 2; - r.bottom -= (this->month == 0xFF ? 1 : 3) * GetCharacterHeight(FS_SMALL) + 4; + r.bottom -= (this->month == 0xFF ? 1 : 2) * GetCharacterHeight(FS_SMALL) + 4; r.left += 9; r.right -= 5; @@ -327,7 +329,7 @@ protected: x_axis_offset = (int)((r.bottom - r.top) * (double)interval.highest / (double)interval_size); /* Draw the background of the graph itself. */ - GfxFillRect(r.left, r.top, r.right, r.bottom, GREY_SCALE(2)); + GfxFillRect(r.left, r.top, r.right, r.bottom, GRAPH_BASE_COLOUR); /* Draw the vertical grid lines. */ @@ -335,7 +337,7 @@ protected: x = r.left + x_sep; for (int i = 0; i < this->num_vert_lines; i++) { - GfxFillRect(x, r.top, x, r.bottom, grid_colour); + GfxFillRect(x, r.top, x, r.bottom, GRAPH_GRID_COLOUR); x += x_sep; } @@ -344,7 +346,7 @@ protected: for (int i = 0; i < (num_hori_lines + 1); i++) { GfxFillRect(r.left - 3, y, r.left - 1, y, GRAPH_AXIS_LINE_COLOUR); - GfxFillRect(r.left, y, r.right, y, grid_colour); + GfxFillRect(r.left, y, r.right, y, GRAPH_GRID_COLOUR); y -= y_sep; } @@ -370,13 +372,13 @@ protected: for (int i = 0; i < (num_hori_lines + 1); i++) { SetDParam(0, this->format_str_y_axis); SetDParam(1, y_label); - DrawString(r.left - label_width - 4, r.left - 4, y, STR_GRAPH_Y_LABEL, graph_axis_label_colour, SA_RIGHT); + DrawString(r.left - label_width - 4, r.left - 4, y, STR_GRAPH_Y_LABEL, GRAPH_AXIS_LABEL_COLOUR, SA_RIGHT); y_label -= y_label_separation; y += y_sep; } - /* draw strings on the x axis */ + /* Draw x-axis labels and markings for graphs based on financial quarters and years. */ if (this->month != 0xFF) { x = r.left; y = r.bottom + 2; @@ -384,26 +386,28 @@ protected: Year year = this->year; for (int i = 0; i < this->num_on_x_axis; i++) { SetDParam(0, month + STR_MONTH_ABBREV_JAN); - SetDParam(1, month + STR_MONTH_ABBREV_JAN + 2); - SetDParam(2, year); - DrawStringMultiLine(x, x + x_sep, y, this->height, month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, graph_axis_label_colour); + SetDParam(1, year); + DrawStringMultiLine(x, x + x_sep, y, this->height, month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, GRAPH_AXIS_LABEL_COLOUR, SA_LEFT); month += 3; if (month >= 12) { month = 0; year++; + + /* Draw a lighter grid line between years. Top and bottom adjustments ensure we don't draw over top and bottom horizontal grid lines. */ + GfxFillRect(x + x_sep, r.top + 1, x + x_sep, r.bottom - 1, GRAPH_YEAR_LINE_COLOUR); } x += x_sep; } } else { - /* Draw the label under the data point rather than on the grid line. */ + /* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates). */ x = r.left; y = r.bottom + 2; uint16 label = this->x_values_start; for (int i = 0; i < this->num_on_x_axis; i++) { SetDParam(0, label); - DrawString(x + 1, x + x_sep - 1, y, STR_GRAPH_Y_LABEL_NUMBER, graph_axis_label_colour, SA_HOR_CENTER); + DrawString(x + 1, x + x_sep - 1, y, STR_GRAPH_Y_LABEL_NUMBER, GRAPH_AXIS_LABEL_COLOUR, SA_HOR_CENTER); label += this->x_values_increment; x += x_sep; @@ -493,13 +497,13 @@ public: uint x_label_width = 0; + /* Draw x-axis labels and markings for graphs based on financial quarters and years. */ if (this->month != 0xFF) { byte month = this->month; Year year = this->year; for (int i = 0; i < this->num_on_x_axis; i++) { SetDParam(0, month + STR_MONTH_ABBREV_JAN); - SetDParam(1, month + STR_MONTH_ABBREV_JAN + 2); - SetDParam(2, year); + SetDParam(1, year); x_label_width = std::max(x_label_width, GetStringBoundingBox(month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH).width); month += 3; @@ -509,7 +513,7 @@ public: } } } else { - /* Draw the label under the data point rather than on the grid line. */ + /* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates). */ SetDParamMaxValue(0, this->x_values_start + this->num_on_x_axis * this->x_values_increment, 0, FS_SMALL); x_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL_NUMBER).width; }