| 662 | |
| 663 | public: |
| 664 | void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override |
| 665 | { |
| 666 | switch (widget) { |
| 667 | case WID_GRAPH_RANGE_MATRIX: |
| 668 | this->UpdateMatrixSize(widget, size, resize, this->ranges); |
| 669 | break; |
| 670 | |
| 671 | case WID_GRAPH_SCALE_MATRIX: |
| 672 | this->UpdateMatrixSize(widget, size, resize, this->scales | std::views::transform(&GraphScale::label)); |
| 673 | break; |
| 674 | |
| 675 | case WID_GRAPH_GRAPH: { |
| 676 | uint x_label_width = 0; |
| 677 | |
| 678 | /* Draw x-axis labels and markings for graphs based on financial quarters and years. */ |
| 679 | if (this->draw_dates) { |
| 680 | uint year = GetParamMaxValue(this->year.base(), 4, FS_SMALL); |
| 681 | for (uint month = 0; month < 12; ++month) { |
| 682 | x_label_width = std::max(x_label_width, GetStringBoundingBox(GetString(month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, STR_MONTH_ABBREV_JAN + month, year)).width); |
| 683 | } |
| 684 | } else { |
| 685 | /* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates). */ |
| 686 | uint64_t max_value = GetParamMaxValue((this->num_on_x_axis + 1) * this->x_values_increment, 0, FS_SMALL); |
| 687 | x_label_width = GetStringBoundingBox(GetString(STR_GRAPH_Y_LABEL_NUMBER, max_value)).width; |
| 688 | } |
| 689 | |
| 690 | uint y_label_width = GetStringBoundingBox(GetString(STR_GRAPH_Y_LABEL, this->format_str_y_axis, INT64_MAX)).width; |
| 691 | |
| 692 | size.width = std::max<uint>(size.width, ScaleGUITrad(5) + y_label_width + this->num_vert_lines * (x_label_width + ScaleGUITrad(5)) + ScaleGUITrad(9)); |
| 693 | size.height = std::max<uint>(size.height, ScaleGUITrad(5) + (1 + MIN_GRAPH_NUM_LINES_Y * 2 + (this->draw_dates ? 3 : 1)) * GetCharacterHeight(FS_SMALL) + ScaleGUITrad(4)); |
| 694 | size.height = std::max<uint>(size.height, size.width / 3); |
| 695 | break; |
| 696 | } |
| 697 | |
| 698 | default: break; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | void DrawWidget(const Rect &r, WidgetID widget) const override |
| 703 | { |
nothing calls this directly
no test coverage detected