AsciiCanvas Class — langchain Architecture
Architecture documentation for the AsciiCanvas class in graph_ascii.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 76bb01c4_195c_1bd6_3c3d_0ecb71e225e5["AsciiCanvas"] bd48fe30_3177_b41c_8c8f_66e31a6b4ecb["graph_ascii.py"] 76bb01c4_195c_1bd6_3c3d_0ecb71e225e5 -->|defined in| bd48fe30_3177_b41c_8c8f_66e31a6b4ecb ed0555ed_e7b5_cf1d_10e2_0f69d983b69f["__init__()"] 76bb01c4_195c_1bd6_3c3d_0ecb71e225e5 -->|method| ed0555ed_e7b5_cf1d_10e2_0f69d983b69f ec70c8d9_4454_4221_ac85_d75695eb85fc["draw()"] 76bb01c4_195c_1bd6_3c3d_0ecb71e225e5 -->|method| ec70c8d9_4454_4221_ac85_d75695eb85fc d9684099_24e5_2267_1d5c_54ff6c1d5f0d["point()"] 76bb01c4_195c_1bd6_3c3d_0ecb71e225e5 -->|method| d9684099_24e5_2267_1d5c_54ff6c1d5f0d 1dbc3354_2bab_b41d_7aa9_14f4624a2a20["line()"] 76bb01c4_195c_1bd6_3c3d_0ecb71e225e5 -->|method| 1dbc3354_2bab_b41d_7aa9_14f4624a2a20 53579b11_7da2_b348_12e0_809b3a0e0405["text()"] 76bb01c4_195c_1bd6_3c3d_0ecb71e225e5 -->|method| 53579b11_7da2_b348_12e0_809b3a0e0405 333b0598_86ec_e08e_fb9e_97bb5d448e1d["box()"] 76bb01c4_195c_1bd6_3c3d_0ecb71e225e5 -->|method| 333b0598_86ec_e08e_fb9e_97bb5d448e1d
Relationship Graph
Source Code
libs/core/langchain_core/runnables/graph_ascii.py lines 57–190
class AsciiCanvas:
"""Class for drawing in ASCII."""
TIMEOUT = 10
def __init__(self, cols: int, lines: int) -> None:
"""Create an ASCII canvas.
Args:
cols: number of columns in the canvas. Should be `> 1`.
lines: number of lines in the canvas. Should be `> 1`.
Raises:
ValueError: if canvas dimensions are invalid.
"""
if cols <= 1 or lines <= 1:
msg = "Canvas dimensions should be > 1"
raise ValueError(msg)
self.cols = cols
self.lines = lines
self.canvas = [[" "] * cols for line in range(lines)]
def draw(self) -> str:
"""Draws ASCII canvas on the screen.
Returns:
The ASCII canvas string.
"""
lines = map("".join, self.canvas)
return os.linesep.join(lines)
def point(self, x: int, y: int, char: str) -> None:
"""Create a point on ASCII canvas.
Args:
x: x coordinate. Should be `>= 0` and `<` number of columns in
the canvas.
y: y coordinate. Should be `>= 0` an `<` number of lines in the
canvas.
char: character to place in the specified point on the
canvas.
Raises:
ValueError: if char is not a single character or if
coordinates are out of bounds.
"""
if len(char) != 1:
msg = "char should be a single character"
raise ValueError(msg)
if x >= self.cols or x < 0:
msg = "x should be >= 0 and < number of columns"
raise ValueError(msg)
if y >= self.lines or y < 0:
msg = "y should be >= 0 and < number of lines"
raise ValueError(msg)
self.canvas[y][x] = char
def line(self, x0: int, y0: int, x1: int, y1: int, char: str) -> None:
"""Create a line on ASCII canvas.
Args:
x0: x coordinate where the line should start.
y0: y coordinate where the line should start.
x1: x coordinate where the line should end.
y1: y coordinate where the line should end.
char: character to draw the line with.
"""
if x0 > x1:
x1, x0 = x0, x1
y1, y0 = y0, y1
dx = x1 - x0
dy = y1 - y0
if dx == 0 and dy == 0:
self.point(x0, y0, char)
elif abs(dx) >= abs(dy):
for x in range(x0, x1 + 1):
Source
Frequently Asked Questions
What is the AsciiCanvas class?
AsciiCanvas is a class in the langchain codebase, defined in libs/core/langchain_core/runnables/graph_ascii.py.
Where is AsciiCanvas defined?
AsciiCanvas is defined in libs/core/langchain_core/runnables/graph_ascii.py at line 57.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free