fortplot_legend Module

Legend module following SOLID principles

Single Responsibility: Legend rendering and positioning Open/Closed: Extensible legend types via interfaces Liskov Substitution: Legend renderers work across backends Interface Segregation: Focused legend interface Dependency Inversion: Depends on abstractions, not concrete backends



Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: LEGEND_UPPER_LEFT = 1
integer, public, parameter :: LEGEND_UPPER_RIGHT = 2
integer, public, parameter :: LEGEND_LOWER_LEFT = 3
integer, public, parameter :: LEGEND_LOWER_RIGHT = 4

Derived Types

type, public ::  legend_entry_t

Single Responsibility: Represents one legend entry

Components

Type Visibility Attributes Name Initial
character(len=:), public, allocatable :: label
real(kind=wp), public, dimension(3) :: color
character(len=:), public, allocatable :: linestyle
character(len=:), public, allocatable :: marker

type, public ::  legend_t

Single Responsibility: Legend layout and rendering coordination

Components

Type Visibility Attributes Name Initial
type(legend_entry_t), public, allocatable :: entries(:)
integer, public :: position = LEGEND_UPPER_RIGHT
integer, public :: num_entries = 0
real(kind=wp), public :: x_offset = 10.0_wp
real(kind=wp), public :: y_offset = 10.0_wp
real(kind=wp), public :: entry_height = 20.0_wp
real(kind=wp), public :: line_length = 30.0_wp
real(kind=wp), public :: text_padding = 10.0_wp

Type-Bound Procedures

procedure, public :: add_entry => legend_add_entry
procedure, public :: render => legend_render
procedure, public :: set_position => legend_set_position
procedure, public :: clear => legend_clear

Functions

public function create_legend() result(legend)

Factory function following Dependency Inversion

Arguments

None

Return Value type(legend_t)


Subroutines

public subroutine legend_render(this, backend)

Render legend following Liskov Substitution Works with any backend that implements plot_context interface

Arguments

Type IntentOptional Attributes Name
class(legend_t), intent(in) :: this
class(plot_context), intent(inout) :: backend

public subroutine render_ascii_legend(legend, backend, legend_x, legend_y)

Render compact ASCII legend with proper formatting

Arguments

Type IntentOptional Attributes Name
type(legend_t), intent(in) :: legend
class(plot_context), intent(inout) :: backend
real(kind=wp), intent(in) :: legend_x
real(kind=wp), intent(in) :: legend_y

public subroutine render_standard_legend(legend, backend, legend_x, legend_y)

Render standard legend for PNG/PDF backends with improved sizing Refactored to be under 100 lines (QADS compliance)

Arguments

Type IntentOptional Attributes Name
type(legend_t), intent(in) :: legend
class(plot_context), intent(inout) :: backend
real(kind=wp), intent(in) :: legend_x
real(kind=wp), intent(in) :: legend_y