View source on GitHub |
A utility class for creating simple text diagrams.
cirq.TextDiagramDrawer(
entries: Optional[Mapping[Tuple[int, int], _DiagramText]] = None,
horizontal_lines: Optional[Iterable[_HorizontalLine]] = None,
vertical_lines: Optional[Iterable[_VerticalLine]] = None,
horizontal_padding: Optional[Mapping[int, int]] = None,
vertical_padding: Optional[Mapping[int, int]] = None
) -> None
Methods
content_present
content_present(
x: int, y: int
) -> bool
Determines if a line or printed text is at the given location.
copy
copy()
force_horizontal_padding_after
force_horizontal_padding_after(
index: int, padding: Union[int, float]
) -> None
Change the padding after the given column.
force_vertical_padding_after
force_vertical_padding_after(
index: int, padding: Union[int, float]
) -> None
Change the padding after the given row.
grid_line
grid_line(
x1: int,
y1: int,
x2: int,
y2: int,
emphasize: bool = False,
doubled: bool = False
)
Adds a vertical or horizontal line from (x1, y1) to (x2, y2).
Horizontal line is selected on equality in the second coordinate and vertical line is selected on equality in the first coordinate.
Raises | |
---|---|
ValueError
|
If line is neither horizontal nor vertical. |
height
height() -> int
Determines how many entry rows are in the diagram.
horizontal_line
horizontal_line(
y: Union[int, float],
x1: Union[int, float],
x2: Union[int, float],
emphasize: bool = False,
doubled: bool = False
) -> None
Adds a line from (x1, y) to (x2, y).
hstack
@classmethod
hstack( diagrams: Sequence['cirq.TextDiagramDrawer'], padding_resolver: Optional[Callable[[Sequence[Optional[int]]], int]] = None )
Horizontally stack text diagrams.
Args | |
---|---|
diagrams
|
The diagrams to stack, ordered from left to right. |
padding_resolver
|
A function that takes a list of paddings specified for a row and returns the padding to use in the stacked diagram. Defaults to raising ValueError if the diagrams to stack contain inconsistent padding in any row, including if some specify a padding and others don't. |
Raises | |
---|---|
ValueError
|
Inconsistent padding cannot be resolved. |
Returns | |
---|---|
The horizontally stacked diagram. |
insert_empty_columns
insert_empty_columns(
x: int, amount: int = 1
) -> None
Insert a number of columns after the given column.
insert_empty_rows
insert_empty_rows(
y: int, amount: int = 1
) -> None
Insert a number of rows after the given row.
render
render(
horizontal_spacing: int = 1,
vertical_spacing: int = 1,
crossing_char: Optional[str] = None,
use_unicode_characters: bool = True
) -> str
Outputs text containing the diagram.
shift
shift(
dx: int = 0, dy: int = 0
) -> 'cirq.TextDiagramDrawer'
shifted
shifted(
dx: int = 0, dy: int = 0
) -> 'cirq.TextDiagramDrawer'
superimpose
superimpose(
other: 'cirq.TextDiagramDrawer'
) -> 'cirq.TextDiagramDrawer'
superimposed
superimposed(
other: 'cirq.TextDiagramDrawer'
) -> 'cirq.TextDiagramDrawer'
transpose
transpose() -> 'cirq.TextDiagramDrawer'
Returns the same diagram, but mirrored across its diagonal.
vertical_line
vertical_line(
x: Union[int, float],
y1: Union[int, float],
y2: Union[int, float],
emphasize: bool = False,
doubled: bool = False
) -> None
Adds a line from (x, y1) to (x, y2).
vstack
@classmethod
vstack( diagrams: Sequence['cirq.TextDiagramDrawer'], padding_resolver: Optional[Callable[[Sequence[Optional[int]]], int]] = None )
Vertically stack text diagrams.
Args | |
---|---|
diagrams
|
The diagrams to stack, ordered from bottom to top. |
padding_resolver
|
A function that takes a list of paddings specified for a column and returns the padding to use in the stacked diagram. If None, defaults to raising ValueError if the diagrams to stack contain inconsistent padding in any column, including if some specify a padding and others don't. |
Raises | |
---|---|
ValueError
|
Inconsistent padding cannot be resolved. |
Returns | |
---|---|
The vertically stacked diagram. |
width
width() -> int
Determines how many entry columns are in the diagram.
write
write(
x: int, y: int, text: str, transposed_text: Optional[str] = None
)
Adds text to the given location.
Args | |
---|---|
x
|
The column in which to write the text. |
y
|
The row in which to write the text. |
text
|
The text to write at location (x, y). |
transposed_text
|
Optional text to write instead, if the text diagram is transposed. |
__bool__
__bool__()
__eq__
__eq__(
other: _SupportsValueEquality
) -> bool
__ne__
__ne__(
other: _SupportsValueEquality
) -> bool