fortplot_context Module

Abstract base class for plotting backends

This module defines the common interface that all plotting backends (PNG, PDF, ASCII) must implement. Provides polymorphic interface for unified plotting operations across different output formats.

Author: fortplot contributors



Derived Types

type, public, abstract ::  plot_context

Components

Type Visibility Attributes Name Initial
integer, public :: width
integer, public :: height
real(kind=wp), public :: x_min
real(kind=wp), public :: x_max
real(kind=wp), public :: y_min
real(kind=wp), public :: y_max
real(kind=wp), public :: view_azim = -1.0471975511965976_wp
real(kind=wp), public :: view_elev = 0.5235987755982988_wp
real(kind=wp), public :: view_dist = 10.0_wp
logical, public :: has_rendered_arrows = .false.
logical, public :: uses_vector_arrows = .false.
logical, public :: has_triangular_arrows = .false.

Type-Bound Procedures

procedure(line_interface), public, deferred :: line
procedure(color_interface), public, deferred :: color
procedure(text_interface), public, deferred :: text
procedure(save_interface), public, deferred :: save
procedure(line_width_interface), public, deferred :: set_line_width
procedure(line_style_interface), public, deferred :: set_line_style
procedure(marker_interface), public, deferred :: draw_marker
procedure(marker_colors_interface), public, deferred :: set_marker_colors
procedure(marker_colors_alpha_interface), public, deferred :: set_marker_colors_with_alpha
procedure(arrow_interface), public, deferred :: draw_arrow
procedure(arrowhead_interface), public, deferred :: draw_arrowhead
procedure(ascii_output_interface), public, deferred :: get_ascii_output

Additional polymorphic methods to eliminate SELECT TYPE violations

procedure(get_width_scale_interface), public, deferred :: get_width_scale
procedure(get_height_scale_interface), public, deferred :: get_height_scale
procedure(fill_quad_interface), public, deferred :: fill_quad
procedure(fill_heatmap_interface), public, deferred :: fill_heatmap
procedure(extract_rgb_data_interface), public, deferred :: extract_rgb_data
procedure(get_png_data_interface), public, deferred :: get_png_data_backend
procedure(prepare_3d_data_interface), public, deferred :: prepare_3d_data
procedure(render_ylabel_interface), public, deferred :: render_ylabel
procedure(draw_axes_and_labels_interface), public, deferred :: draw_axes_and_labels_backend
procedure(save_coordinates_interface), public, deferred :: save_coordinates
procedure(set_coordinates_interface), public, deferred :: set_coordinates
procedure(render_axes_interface), public, deferred :: render_axes

Blank a horizontal run of cells behind a text block so overlays such as legends read against clear background. Raster/vector backends composite text on top already, so the base implementation is a no-op.

procedure, public :: clear_text_background => context_clear_text_background

Draw text as a fixed-position overlay. Raster/vector backends reuse their normal text path; the ASCII backend overrides this to place the glyphs at the exact cell without the auto-shift its buffered text path applies, so stacked legend rows never blend together.

procedure, public :: draw_text_overlay => context_draw_text_overlay

Select the text-backend charset ('ascii' or 'braille'). Only the text backend carries subpixel dots; raster/vector backends ignore it.

procedure, public :: set_text_charset => context_set_text_charset

Select the text-backend ANSI color mode. Only the text backend emits escapes; raster/vector backends ignore it (#2062).

procedure, public :: set_text_color_mode => context_set_text_color_mode

Subroutines

public subroutine setup_canvas(ctx, width, height)

Arguments

Type IntentOptional Attributes Name
class(plot_context), intent(inout) :: ctx
integer, intent(in) :: width
integer, intent(in) :: height