Learn R Programming

plotcli (version 0.2.0)

Canvas: Canvas Classes for Terminal Plotting

Description

Abstract canvas system that provides different rendering backends: - AsciiCanvas: Basic ASCII characters (*, -, |, +) - BrailleCanvas: Unicode Braille patterns (2x4 dots per cell = 8x resolution) - BlockCanvas: Unicode block elements (half-blocks for 2x vertical resolution)

Arguments

Public fields

width

Character width of the canvas

height

Character height of the canvas

pixel_width

Pixel width (may be higher than char width for Braille/Block)

pixel_height

Pixel height (may be higher than char height for Braille/Block)

matrix

Character matrix for rendering

color_matrix

Parallel matrix tracking colors per cell

x_mult

Horizontal multiplier (pixels per character)

y_mult

Vertical multiplier (pixels per character)

Methods


Method new()

Initialize the canvas

Usage

Canvas$new(width, height)

Arguments

width

Character width

height

Character height


Method set_pixel()

Set a pixel at the given coordinates

Usage

Canvas$set_pixel(x, y, color = NULL)

Arguments

x

X coordinate (1-based, in pixel space)

y

Y coordinate (1-based, in pixel space, 1 = top)

color

Optional color name


Method draw_line()

Draw a line between two points

Usage

Canvas$draw_line(x0, y0, x1, y1, color = NULL)

Arguments

x0

Start X coordinate

y0

Start Y coordinate

x1

End X coordinate

y1

End Y coordinate

color

Optional color name


Method draw_polyline()

Draw multiple connected line segments

Usage

Canvas$draw_polyline(xs, ys, color = NULL)

Arguments

xs

Vector of X coordinates

ys

Vector of Y coordinates

color

Optional color name


Method draw_points()

Draw points (scatter)

Usage

Canvas$draw_points(xs, ys, color = NULL)

Arguments

xs

Vector of X coordinates

ys

Vector of Y coordinates

color

Optional color name


Method fill_rect()

Fill a rectangle

Usage

Canvas$fill_rect(x0, y0, x1, y1, color = NULL)

Arguments

x0

Left X coordinate

y0

Top Y coordinate

x1

Right X coordinate

y1

Bottom Y coordinate

color

Optional color name


Method fill_bar()

Fill a vertical bar from bottom up to a height

Usage

Canvas$fill_bar(x, height, bar_width = 2, color = NULL)

Arguments

x

X coordinate (center of bar in pixel space)

height

Height in pixels from bottom

bar_width

Width of bar in pixels (default 2)

color

Optional color name


Method draw_text()

Place text at a position

Usage

Canvas$draw_text(x, y, text, color = NULL)

Arguments

x

X coordinate (character position)

y

Y coordinate (character position)

text

Text string to place

color

Optional color name


Method apply_colors()

Apply colors to the matrix

Usage

Canvas$apply_colors()

Returns

Matrix with ANSI color codes applied


Method render()

Get the rendered matrix (with colors)

Usage

Canvas$render()

Returns

Character matrix


Method print()

Print the canvas to console

Usage

Canvas$print()


Method clear()

Clear the canvas

Usage

Canvas$clear()


Method draw_rect()

Draw a rectangle outline

Usage

Canvas$draw_rect(x0, y0, x1, y1, color = NULL)

Arguments

x0

Left X coordinate (pixel space)

y0

Top Y coordinate (pixel space)

x1

Right X coordinate (pixel space)

y1

Bottom Y coordinate (pixel space)

color

Optional color name


Method fill_area()

Fill an area between a polyline and the bottom

Usage

Canvas$fill_area(xs, ys, color = NULL)

Arguments

xs

Vector of X coordinates

ys

Vector of Y coordinates

color

Optional color name


Method draw_segment()

Draw a segment (line with optional arrowhead)

Usage

Canvas$draw_segment(x0, y0, x1, y1, arrow_end = FALSE, color = NULL)

Arguments

x0

Start X coordinate

y0

Start Y coordinate

x1

End X coordinate

y1

End Y coordinate

arrow_end

Add arrowhead at end (default FALSE)

color

Optional color name


Method draw_hline()

Draw a horizontal line

Usage

Canvas$draw_hline(y, x0 = 1, x1 = NULL, color = NULL)

Arguments

y

Y coordinate

x0

Start X (default 1)

x1

End X (default pixel_width)

color

Optional color name


Method draw_vline()

Draw a vertical line

Usage

Canvas$draw_vline(x, y0 = 1, y1 = NULL, color = NULL)

Arguments

x

X coordinate

y0

Start Y (default 1)

y1

End Y (default pixel_height)

color

Optional color name


Method draw_circle()

Draw a circle outline

Usage

Canvas$draw_circle(cx, cy, r, color = NULL)

Arguments

cx

Center X coordinate

cy

Center Y coordinate

r

Radius in pixels

color

Optional color name


Method fill_circle()

Fill a circle

Usage

Canvas$fill_circle(cx, cy, r, color = NULL)

Arguments

cx

Center X coordinate

cy

Center Y coordinate

r

Radius in pixels

color

Optional color name


Method draw_polygon()

Draw a polygon outline

Usage

Canvas$draw_polygon(xs, ys, closed = TRUE, color = NULL)

Arguments

xs

Vector of X coordinates

ys

Vector of Y coordinates

closed

Whether to close the polygon (default TRUE)

color

Optional color name


Method clone()

The objects of this class are cloneable with this method.

Usage

Canvas$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Details

Abstract base class for all canvas types. Provides the interface that all canvas implementations must follow.