fortplot_legend_layout Module

Shared legend layout calculations following DRY principle

Single Responsibility: Legend box sizing and positioning calculations DRY: Centralized legend layout logic for consistent behavior KISS: Simple, clear calculation functions Uses text system measurements for accurate sizing



Derived Types

type, public ::  legend_box_t

Single Responsibility: Legend box dimensions and position

Components

Type Visibility Attributes Name Initial
real(kind=wp), public :: x
real(kind=wp), public :: y
real(kind=wp), public :: width
real(kind=wp), public :: height
real(kind=wp), public :: padding
real(kind=wp), public :: entry_height
real(kind=wp), public :: entry_spacing
real(kind=wp), public :: line_length
real(kind=wp), public :: text_spacing

Functions

public function calculate_legend_box(labels, data_width, data_height, num_entries, position) result(box)

Calculate optimal legend box dimensions and position DRY: Centralized legend box calculation logic

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: labels(:)
real(kind=wp), intent(in) :: data_width
real(kind=wp), intent(in) :: data_height
integer, intent(in) :: num_entries
integer, intent(in) :: position

Return Value type(legend_box_t)

public function get_actual_text_dimensions(label, data_to_pixel_x, data_to_pixel_y) result(dimensions)

Get actual text dimensions using text system measurements
Returns [width, height] in data coordinates

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: label
real(kind=wp), intent(in) :: data_to_pixel_x
real(kind=wp), intent(in) :: data_to_pixel_y

Return Value real(kind=wp), (2)

public function get_legend_margins(data_width, data_height) result(margins)

Get appropriate margins for legend placement DRY: Centralized margin calculation

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: data_width
real(kind=wp), intent(in) :: data_height

Return Value real(kind=wp), (2)


Subroutines

public subroutine calculate_optimal_legend_dimensions(labels, data_width, data_height, max_text_width, total_text_width, box)

Calculate optimal legend dimensions using actual text system measurements KISS: Based on measured text content, not estimates

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: labels(:)
real(kind=wp), intent(in) :: data_width
real(kind=wp), intent(in) :: data_height
real(kind=wp), intent(out) :: max_text_width
real(kind=wp), intent(out) :: total_text_width
type(legend_box_t), intent(inout) :: box