@@ -304,48 +304,51 @@ protected:
/* Initial number of horizontal lines. */
int num_hori_lines = 160 / MIN_GRID_PIXEL_SIZE;
/* For the rest of the height, the number of horizontal lines will increase more slowly. */
int resize = (r.bottom - r.top - 160) / (2 * MIN_GRID_PIXEL_SIZE);
if (resize > 0) num_hori_lines += resize;
interval = GetValuesInterval(num_hori_lines);
int label_width = GetYLabelWidth(interval, num_hori_lines);
r.left += label_width;
int x_sep = (r.right - r.left) / this->num_vert_lines;
int y_sep = (r.bottom - r.top) / num_hori_lines;
/* Redetermine right and bottom edge of graph to fit with the integer
* separation values. */
r.right = r.left + x_sep * this->num_vert_lines;
r.bottom = r.top + y_sep * num_hori_lines;
OverflowSafeInt64 interval_size = interval.highest + abs(interval.lowest);
/* Where to draw the X axis. Use floating point to avoid overflowing and results of zero. */
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));
/* Draw the vertical grid lines. */
/* Don't draw the first line, as that's where the axis will be. */
x = r.left + x_sep;
for (int i = 0; i < this->num_vert_lines; i++) {
GfxFillRect(x, r.top, x, r.bottom, grid_colour);
x += x_sep;
}
/* Draw the horizontal grid lines. */
y = r.bottom;
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);
y -= y_sep;
/* Draw the y axis. */
GfxFillRect(r.left, r.top, r.left, r.bottom, GRAPH_AXIS_LINE_COLOUR);
/* Draw the x axis. */
y = x_axis_offset + r.top;
Status change: