From 069edc1a4bbcd5a284a6d1e450de77f2f4216ce4 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Mon, 14 Apr 2025 16:57:07 +0200 Subject: [PATCH] Fix #13954: Plotting graphs with limited data to the right. (#13956) --- src/graph_gui.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index e3b89744b4..7cb36d9dbe 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -442,10 +442,14 @@ protected: y += y_sep; } + x = rtl ? r.right : r.left; + y = r.bottom + ScaleGUITrad(2); + + /* if there are not enough datapoints to fill the graph, align to the right */ + x += (this->num_vert_lines - this->num_on_x_axis) * x_sep; + /* Draw x-axis labels and markings for graphs based on financial quarters and years. */ if (this->draw_dates) { - x = rtl ? r.right : r.left; - y = r.bottom + ScaleGUITrad(2); TimerGameEconomy::Month month = this->month; TimerGameEconomy::Year year = this->year; for (int i = 0; i < this->num_on_x_axis; i++) { @@ -471,9 +475,6 @@ protected: } } else { /* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates, and all graphs when using wallclock units). */ - x = rtl ? r.right : r.left; - y = r.bottom + ScaleGUITrad(2); - int16_t iterator; uint16_t label; if (this->x_values_reversed) { @@ -512,6 +513,9 @@ protected: x = r.left + (x_sep / 2); } + /* if there are not enough datapoints to fill the graph, align to the right */ + x += (this->num_vert_lines - this->num_on_x_axis) * x_sep; + uint prev_x = INVALID_DATAPOINT_POS; uint prev_y = INVALID_DATAPOINT_POS;