Alignment
In [1]:
Copied!
from chalk.core import BaseDiagram
from chalk import *
def help(f):
import pydoc
from IPython.display import HTML
return HTML(pydoc.HTMLDoc().docroutine(f))
from chalk.core import BaseDiagram from chalk import * def help(f): import pydoc from IPython.display import HTML return HTML(pydoc.HTMLDoc().docroutine(f))
Each diagram has an origin and an envelope. Manipulating the position of the diagram with respect to its origin and envelope allows for precise control of the layout. Note that the Chalk API is immutable and always returns a new Diagram
object.
Diagram.show_origin¶
In [2]:
Copied!
help(BaseDiagram.show_origin)
help(BaseDiagram.show_origin)
Out[2]:
- show_origin(self: chalk.types.Diagram) -> chalk.types.Diagram
- Add a red dot at the origin of a diagram for debugging.
In [3]:
Copied!
triangle(1).show_origin()
triangle(1).show_origin()
Out[3]:
Diagram.show_envelope¶
In [4]:
Copied!
help(BaseDiagram.show_envelope)
help(BaseDiagram.show_envelope)
Out[4]:
- show_envelope(self: chalk.types.Diagram, phantom: bool = False, angle: int = 45) -> chalk.types.Diagram
- Add red envelope to diagram for debugging.
Args:
self (Diagram) : Diagram
phantom (bool): Don't include debugging in the envelope
angle (int): Angle increment to show debugging lines.
Returns:
Diagram
In [5]:
Copied!
rectangle(1, 1).show_envelope()
rectangle(1, 1).show_envelope()
Out[5]:
In [6]:
Copied!
triangle(1).show_envelope()
triangle(1).show_envelope()
Out[6]:
In [7]:
Copied!
rectangle(1, 1).show_beside(triangle(1), unit_x)
rectangle(1, 1).show_beside(triangle(1), unit_x)
Out[7]:
In [8]:
Copied!
(rectangle(1, 1) | triangle(1)).pad(1.4)
(rectangle(1, 1) | triangle(1)).pad(1.4)
Out[8]:
In [9]:
Copied!
arc(1, 0, math.pi).show_origin().show_envelope(angle=10)
arc(1, 0, math.pi).show_origin().show_envelope(angle=10)
Out[9]:
Diagram.align_*¶
In [10]:
Copied!
help(BaseDiagram.align_t)
help(BaseDiagram.align_t)
Out[10]:
- align_t(self: chalk.types.Diagram) -> chalk.types.Diagram
In [11]:
Copied!
triangle(1).align_t().show_envelope()
triangle(1).align_t().show_envelope()
Out[11]:
In [12]:
Copied!
triangle(1).align_t().show_beside(rectangle(1, 1).align_b(), unit_x)
triangle(1).align_t().show_beside(rectangle(1, 1).align_b(), unit_x)
Out[12]:
In [13]:
Copied!
help(BaseDiagram.align_r)
help(BaseDiagram.align_r)
Out[13]:
- align_r(self: chalk.types.Diagram) -> chalk.types.Diagram
In [14]:
Copied!
triangle(1).align_r().show_envelope().show_origin()
triangle(1).align_r().show_envelope().show_origin()
Out[14]:
Diagram.center_xy¶
In [15]:
Copied!
help(BaseDiagram.center_xy)
help(BaseDiagram.center_xy)
Out[15]:
- center_xy(self: chalk.types.Diagram) -> chalk.types.Diagram
In [16]:
Copied!
triangle(1).center_xy().show_envelope().show_origin()
triangle(1).center_xy().show_envelope().show_origin()
Out[16]:
Diagram.pad_*¶
In [17]:
Copied!
help(BaseDiagram.pad)
help(BaseDiagram.pad)
Out[17]:
- pad(self: chalk.types.Diagram, extra: float) -> chalk.types.Diagram
- Scale outward directed padding for a diagram.
Be careful using this if your diagram is not centered.
Args:
self (Diagram): Diagram object.
extra (float): Amount of padding to add.
Returns:
Diagram: A diagram object.
In [18]:
Copied!
triangle(1).pad(1.5).show_envelope().show_origin()
triangle(1).pad(1.5).show_envelope().show_origin()
Out[18]:
Diagram.with_envelope¶
In [19]:
Copied!
help(BaseDiagram.with_envelope)
help(BaseDiagram.with_envelope)
Out[19]:
- with_envelope(self: chalk.types.Diagram, other: chalk.types.Diagram) -> chalk.types.Diagram
In [20]:
Copied!
from colour import Color
from colour import Color
In [21]:
Copied!
(rectangle(1, 1) + triangle(0.5)) | rectangle(1, 1)
(rectangle(1, 1) + triangle(0.5)) | rectangle(1, 1)
Out[21]:
In [22]:
Copied!
(rectangle(1, 1) + triangle(0.5)).with_envelope(triangle(0.5)) | rectangle(1, 1).fill_color(Color("red"))
(rectangle(1, 1) + triangle(0.5)).with_envelope(triangle(0.5)) | rectangle(1, 1).fill_color(Color("red"))
Out[22]:
Last update: 2022-08-19