Class Canvas

java.lang.Object
org.aesh.charts.canvas.Canvas

public class Canvas extends Object
A 2D character grid for rendering chart content.

The canvas uses a coordinate system where (0,0) is the top-left corner. Each cell holds a character and an optional ANSI color/style string.

For braille mode, the canvas operates at sub-cell resolution: each character cell represents a 2x4 dot matrix. Use setBrailleDot(int, int, java.lang.String) to set individual dots within cells.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Canvas(int width, int height)
     
    Canvas(int width, int height, boolean braille)
    Create a canvas with the given dimensions in character cells.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear the canvas to spaces.
    char
    get(int x, int y)
    Get the character at the given position.
    int
     
    void
    horizontalLine(int x, int y, int length, char ch)
    Draw a horizontal line.
    void
    horizontalLine(int x, int y, int length, char ch, String style)
     
    Render the canvas to a multi-line string.
    void
    set(int x, int y, char ch)
    Set a character at the given position.
    void
    set(int x, int y, char ch, String style)
    Set a character with an ANSI style at the given position.
    void
    setBrailleDot(int subX, int subY, String style)
    Set a braille dot at sub-cell coordinates.
    void
    verticalLine(int x, int y, int length, char ch)
    Draw a vertical line.
    void
    verticalLine(int x, int y, int length, char ch, String style)
     
    int
     
    void
    writeString(int x, int y, String text)
    Write a string starting at the given position.
    void
    writeString(int x, int y, String text, String style)
    Write a string with style starting at the given position.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Canvas

      public Canvas(int width, int height, boolean braille)
      Create a canvas with the given dimensions in character cells.
      Parameters:
      width - width in character cells
      height - height in character cells
      braille - whether to enable braille sub-cell rendering
    • Canvas

      public Canvas(int width, int height)
  • Method Details

    • clear

      public void clear()
      Clear the canvas to spaces.
    • width

      public int width()
    • height

      public int height()
    • set

      public void set(int x, int y, char ch)
      Set a character at the given position.
      Parameters:
      x - column (0 = left)
      y - row (0 = top)
      ch - the character
    • set

      public void set(int x, int y, char ch, String style)
      Set a character with an ANSI style at the given position.
      Parameters:
      x - column (0 = left)
      y - row (0 = top)
      ch - the character
      style - ANSI escape sequence (e.g., ANSI.GREEN_TEXT), or null
    • get

      public char get(int x, int y)
      Get the character at the given position.
    • writeString

      public void writeString(int x, int y, String text)
      Write a string starting at the given position.
    • writeString

      public void writeString(int x, int y, String text, String style)
      Write a string with style starting at the given position.
    • setBrailleDot

      public void setBrailleDot(int subX, int subY, String style)
      Set a braille dot at sub-cell coordinates.

      The sub-cell coordinates are mapped to the containing character cell and the appropriate dot bit is set.

      Parameters:
      subX - sub-cell X coordinate (each cell is 2 sub-pixels wide)
      subY - sub-cell Y coordinate (each cell is 4 sub-pixels tall)
      style - ANSI style for the cell
    • horizontalLine

      public void horizontalLine(int x, int y, int length, char ch)
      Draw a horizontal line.
    • horizontalLine

      public void horizontalLine(int x, int y, int length, char ch, String style)
    • verticalLine

      public void verticalLine(int x, int y, int length, char ch)
      Draw a vertical line.
    • verticalLine

      public void verticalLine(int x, int y, int length, char ch, String style)
    • render

      public String render()
      Render the canvas to a multi-line string.

      Each cell is rendered with its ANSI style (if any), and styles are reset after each styled run to prevent color bleeding.

      Returns:
      the rendered string