示例#1
0
    def connect(self, source: Mobject, target: Mobject, label: Optional[str] = None) -> Connection:

        result = Connection()
        label_direction = UP
        label_buff = 0

        arrow: Optional[Arrow] = None
        if source.get_x(RIGHT) <= target.get_x(LEFT):
            arrow = Arrow(start=source.get_edge_center(RIGHT), end=target.get_edge_center(LEFT), buff=0)
            label_direction = UP
        elif source.get_x(LEFT) >= target.get_x(RIGHT):
            arrow = Arrow(start=source.get_edge_center(LEFT), end=target.get_edge_center(RIGHT), buff=0)
            label_direction = UP
        elif source.get_y(DOWN) >= target.get_y(UP):
            arrow = Arrow(start=source.get_edge_center(DOWN), end=target.get_edge_center(UP), buff=0)
            label_direction = RIGHT
            label_buff = VERTICAL_ARROW_LABEL_BUFF
        elif source.get_y(UP) <= target.get_y(DOWN):
            arrow = Arrow(start=source.get_edge_center(UP), end=target.get_edge_center(DOWN), buff=0)
            label_direction = RIGHT
            label_buff = VERTICAL_ARROW_LABEL_BUFF

        if not arrow:
            raise ValueError("Unable to connect")

        result.add(arrow)
        if label:
            text = Text(label, font=self.text_font, size=0.7, slant=ITALIC)
            text.next_to(arrow, direction=label_direction, buff=label_buff)
            result.add(text)

        return result
示例#2
0
    def __init__(self,
                 source: Mobject,
                 target: Mobject,
                 label: Optional[str] = None,
                 font=DEFAULT_FONT,
                 **kwargs):
        """
        Args:
            source: The source object
            target: The target object
            label: The optional label text to put over the arrow
        """
        super().__init__(**kwargs)
        self.font = font
        label_direction = UP
        label_buff = 0

        arrow: Optional[Arrow] = None
        if source.get_x(RIGHT) <= target.get_x(LEFT):
            arrow = Arrow(start=source.get_edge_center(RIGHT),
                          end=target.get_edge_center(LEFT),
                          buff=0)
            label_direction = UP
        elif source.get_x(LEFT) >= target.get_x(RIGHT):
            arrow = Arrow(start=source.get_edge_center(LEFT),
                          end=target.get_edge_center(RIGHT),
                          buff=0)
            label_direction = UP
        elif source.get_y(DOWN) >= target.get_y(UP):
            arrow = Arrow(start=source.get_edge_center(DOWN),
                          end=target.get_edge_center(UP),
                          buff=0)
            label_direction = RIGHT
            label_buff = VERTICAL_ARROW_LABEL_BUFF
        elif source.get_y(UP) <= target.get_y(DOWN):
            arrow = Arrow(start=source.get_edge_center(UP),
                          end=target.get_edge_center(DOWN),
                          buff=0)
            label_direction = RIGHT
            label_buff = VERTICAL_ARROW_LABEL_BUFF

        if not arrow:
            raise ValueError("Unable to connect")

        self.add(arrow)
        if label:
            text = Text(label, font=self.font, size=0.5, slant=ITALIC)
            text.next_to(arrow, direction=label_direction, buff=label_buff)
            self.add(text)
示例#3
0
    def finish(self, target: Actor):
        self.target = target

        line = Arrow(start=[self.source.get_center()[0], 0, 0],
                     end=[self.target.get_center()[0], 0, 0],
                     buff=0)
        self.add(line)
        text = Text(self.label,
                    font=self.source.CONFIG["text_font"]).scale(0.7).next_to(
                        line, direction=UP, buff=0)
        self.add(text)
    def __init__(self, source: Actor, target: Actor, label: str = "", font=DEFAULT_FONT, **kwargs):
        super().__init__(source, font=font, **kwargs)
        self.target = target
        self.label = label
        self.font = font

        line = Arrow(
            start=[self.source.get_center()[0], 0, 0],
            end=[self.target.get_center()[0], 0, 0],
            buff=0,
            stroke_width=ARROW_STROKE_WIDTH,
        )
        text = Text(self.label, font=self.font, size=0.5, slant=ITALIC)
        text.next_to(line, direction=UP, buff=0)
        self.add(line, text)
示例#5
0
    def finish(self, target: Actor):
        self.target = target

        line = Arrow(
            start=[self.source.get_center()[0], 0, 0],
            end=[self.target.get_center()[0], 0, 0],
            buff=0,
            stroke_width=ARROW_STROKE_WIDTH,
        )
        text = Text(self.label,
                    font=self.source.diagram.lib.text_font,
                    size=0.7,
                    slant=ITALIC)
        text.next_to(line, direction=UP, buff=0)
        self.add(line, text)
        return self
    def __init__(self, source: Actor, label: str):
        super().__init__(source)
        self.label = "\n".join(wrap(label, 30))

        line_block = VGroup()

        spacing = 0.4
        distance = 0.8
        center_x = source.get_center()[0]
        line = Polygon(
            [center_x, spacing, 0],
            [center_x + distance, spacing, 0],
            [center_x + distance, -1 * spacing, 0],
            [center_x + distance / 2, -1 * spacing, 0],
            [center_x + distance, -1 * spacing, 0],
            [center_x + distance, spacing, 0],
            [center_x, spacing, 0],
            color=WHITE,
        )
        line.set_stroke(width=ARROW_STROKE_WIDTH)

        arrow = Arrow(
            start=[center_x + distance, -1 * spacing, 0],
            end=[center_x, -1 * spacing, 0],
            buff=0,
            stroke_width=ARROW_STROKE_WIDTH,
        )
        line_block.add(line, arrow)

        title = Text(self.label, font=self.source.font, size=0.5, slant=ITALIC)
        title.next_to(line_block)

        block = VGroup()
        block.add(line_block, title)
        block.next_to(source.get_center(), RIGHT)
        self.add(block)
示例#7
0
    def __init__(self, target: Actor, label: str):
        super().__init__(target)
        self.target = target
        self.label = "\n".join(wrap(label, 30))

        line_block = VGroup()

        spacing = 0.4
        distance = 0.8
        line = Polygon(
            [target.get_center()[0], spacing, 0],
            [target.get_center()[0] + distance, spacing, 0],
            [target.get_center()[0] + distance, -1 * spacing, 0],
            [target.get_center()[0] + distance / 2, -1 * spacing, 0],
            [target.get_center()[0] + distance, -1 * spacing, 0],
            [target.get_center()[0] + distance, spacing, 0],
            [target.get_center()[0], spacing, 0],
            color=WHITE,
        )
        line.set_stroke(width=ARROW_STROKE_WIDTH)

        arrow = Arrow(
            start=[target.get_center()[0] + distance, -1 * spacing, 0],
            end=[target.get_center()[0], -1 * spacing, 0],
            buff=0,
            stroke_width=ARROW_STROKE_WIDTH,
        )
        line_block.add(line, arrow)

        title = Text(self.label, font="Helvetica", size=0.7, slant=ITALIC)
        title.next_to(line_block)

        block = VGroup()
        block.add(line_block, title)
        block.next_to(target.get_center(), RIGHT)
        self.add(block)