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
Single Responsibility: Legend box dimensions and position
| 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 | :: | padding_x | ||||
| real(kind=wp), | public | :: | entry_height | ||||
| real(kind=wp), | public | :: | entry_spacing | ||||
| real(kind=wp), | public | :: | line_length | ||||
| real(kind=wp), | public | :: | text_spacing | 
Calculate optimal legend box dimensions and position DRY: Centralized legend box calculation logic
| Type | Intent | Optional | 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 | |||
| integer, | intent(in), | optional | :: | pixel_plot_width | ||
| integer, | intent(in), | optional | :: | pixel_plot_height | 
Get actual text dimensions using text system measurements
Returns [width, height] in data coordinates
| Type | Intent | Optional | 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 | 
Get appropriate margins for legend placement DRY: Centralized margin calculation
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | data_width | |||
| real(kind=wp), | intent(in) | :: | data_height | 
Calculate optimal legend dimensions using actual text system measurements KISS: Based on measured text content, not estimates
| Type | Intent | Optional | 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 | |||
| integer, | intent(in) | :: | pixel_plot_width | |||
| integer, | intent(in) | :: | pixel_plot_height |