Ejemplo n.º 1
0
    def _build_drawing(self):
        doc = Document()
        with doc.create(TikZ()) as tikz_pic:

            # create a node
            node_options = {
                'align': 'center',
                'inner sep': '20pt',
                'label': '{{270:{}}}'.format(self.module.name)
            }
            box = TikZNode(handle='module',
                           options=TikZOptions('draw', 'rounded corners',
                                               **node_options))

            tikz_pic.append(box)
            for port in self.module.ports:
                if port.direction == 'in':
                    tikz_pic.append(
                        TikZNode(text=port.name,
                                 options=TikZOptions(anchor='west'),
                                 at=TikZCoordinate(-1, 1)))
                    break

        doc.generate_tex('test')
        return doc
Ejemplo n.º 2
0
def generate_organigram(schema: PLDSchema, locale: LocaleDictionary,
                        document: Document) -> Document:
    document.append(NewPage())
    with document.create(Figure()) as figure:
        figure: Figure
        with figure.create(Section(title=locale.organigram)) as section:
            section: Section
            section.append(Command("centering"))
            with section.create(Center()) as center:
                center: Center
                with center.create(TikZ()) as forest:
                    forest: TikZ

                    node_kwargs = {'align': 'center', 'minimum size': '20pt'}

                    # noinspection PyTypeChecker
                    top_box = TikZNode(text=schema.title,
                                       handle=f"project-box",
                                       options=TikZOptions(
                                           'draw', 'rounded corners',
                                           **node_kwargs))
                    forest.append(top_box)
                    last_box_handle = top_box.handle

                    for n_deliverable, deliverable in enumerate(
                            schema.deliverables, start=1):
                        # noinspection PyTypeChecker
                        box = TikZNode(
                            text=f"{n_deliverable}. {deliverable.name}",
                            handle=f"deliverable-box-{n_deliverable}",
                            options=TikZOptions(
                                'draw', 'rounded corners',
                                f'below = of {last_box_handle}'
                                if top_box.handle == last_box_handle else
                                f'right = of {last_box_handle}',
                                **node_kwargs))

                        last_box_handle = box.handle
                        # noinspection PyTypeChecker
                        path = TikZDraw(
                            TikZPathList(top_box.get_anchor_point("south"),
                                         "--", box.get_anchor_point("north")))
                        forest.append(box)
                        forest.append(path)
    document.append(VerticalSpace("2cm"))
    return document
Ejemplo n.º 3
0
    def dud(self):
        with self.q_doc.create(TikZ()) as pic:

            # options for our node
            node_kwargs = {
                'align': 'center',
                'minimum size': '100pt',
                'fill': 'black!20'
            }

            # create our test node
            box = TikZNode(text='My block',
                           handle='box',
                           options=TikZOptions('draw', 'rounded corners',
                                               **node_kwargs))

            # add to tikzpicture
            pic.append(box)

            # draw a few paths
            pic.append(
                TikZDraw([
                    TikZCoordinate(0, -6), 'rectangle',
                    TikZCoordinate(2, -8)
                ],
                         options=TikZOptions(fill='red')))

            # show use of anchor, relative coordinate
            pic.append(TikZDraw([box.west, '--', '++(-1,0)']))

            # demonstrate the use of the with syntax
            with pic.create(TikZDraw()) as path:

                # start at an anchor of the node
                path.append(box.east)

                # necessary here because 'in' is a python keyword
                path_options = {'in': 90, 'out': 0}
                path.append(
                    TikZUserPath('edge', TikZOptions('-latex',
                                                     **path_options)))

                path.append(TikZCoordinate(1, 0, relative=True))
Ejemplo n.º 4
0
        def add_edge(node_0, node_1, bend=bend, bend_type='left'):
            path_opts_1 = deepcopy(path_base)
            if bend_type == 'left':
                path_opts_1.update({'bend left': bend})
            else:
                path_opts_1.update({'bend right': bend})

            # path_opts_1.update({'bend left': 30, 'bend right': bend_right})

            # path_opts_1.append_positional)
            # path_options_1 = path_options
            path.append(node_0)
            path.append(TikZUserPath('edge', TikZOptions('->', **path_opts_1)))
            path.append(node_1)
Ejemplo n.º 5
0
        if in0 and in1:
            #import pdb; pdb.set_trace()
            pt0 = dt * t0 / T
            pz0 = dz * z0 / C
            pt1 = dt * t1 / T
            pz1 = dz * z1 / C
            pic.append(
                TikZDraw(
                    [
                        TikZCoordinate(pt0, pz0),
                        "--",
                        TikZCoordinate(pt1, pz1),
                    ],
                    options=TikZOptions({
                        "line width": "0.1pt",
                        "opacity": "0.1",
                        "fill": "black",
                    }),
                ))

    # labels
    for t in range(1, T):
        t0 = dt * t / T
        z0 = dz * -1.8 / C
        pic.append(
            TikZNode(
                handle=f"x{t}",
                at=TikZCoordinate(t0, z0),
                options={
                    #"fill": "white",
                },
Ejemplo n.º 6
0
# doc = Document(page_numbers=False, documentclass='article')

# doc.preamble.append(r'\usepackage{color}')
doc.preamble.append(NoEscape('\definecolor{mycolor}{RGB}{132,165,162}'))
# doc.preamble.append(NoEscape('\definecolor{edgecolor}{RGB}{0,0,0}'))
doc.preamble.append(NoEscape('\definecolor{edgecolor}{RGB}{240,0,0}'))
doc.preamble.append(NoEscape('\pgfdeclarelayer{bg}'))
doc.preamble.append(NoEscape('\pgfsetlayers{bg,main}'))

anchor = 'north west'
pic_opts = TikZOptions(
    'shorten >= 0pt',
    'shorten <= {}cm'.format(-.1 * global_scale),
    **{
        'draw': 'black',
        # 'line width': .05,
        'inner sep': '0pt',
        'node distance': '{}cm'.format(1 * global_scale),
        'anchor': anchor,
        'x': '{}cm'.format(global_scale),
        'y': '{}cm'.format(global_scale)
    })

with doc.create(TikZ(options=pic_opts)) as pic:
    # def c(x, y):
    # return TikZCoordinate(x*global_scale, y*global_scale)
    c = TikZCoordinate

    nodes = []
    node_opts = TikZOptions(
        'circle', **{
            'line width': 3 * global_scale,
Ejemplo n.º 7
0
    # add our sample drawings
    with doc.create(TikZ()) as pic:

        # options for our node
        node_kwargs = {
            'align': 'center',
            'minimum size': '100pt',
            'fill': 'black!20'
        }

        # create our test node
        box = TikZNode(text='My block',
                       handle='box',
                       at=TikZCoordinate(0, 0),
                       options=TikZOptions('draw', 'rounded corners',
                                           **node_kwargs))

        # add to tikzpicture
        pic.append(box)

        # draw a few paths
        pic.append(
            TikZDraw(
                [TikZCoordinate(0, -6), 'rectangle',
                 TikZCoordinate(2, -8)],
                options=TikZOptions(fill='red')))

        # show use of anchor, relative coordinate
        pic.append(TikZDraw([box.west, '--', '++(-1,0)']))

        # demonstrate the use of the with syntax
Ejemplo n.º 8
0
def test_tikz():
    # PGFPlots
    t = TikZ(data=None)
    repr(t)

    a = Axis(data=None, options=None)
    repr(a)

    p = Plot(name=None,
             func=None,
             coordinates=None,
             error_bar=None,
             options=None)
    repr(p)

    opt = TikZOptions(None)
    repr(opt)

    scope = TikZScope(data=None)
    repr(scope)

    c = TikZCoordinate.from_str("(0,0)")
    c = TikZCoordinate(x=0, y=0, relative=False)
    d = c + (0, 1)
    e = c - (0, 1)
    f = (0, 1) + c
    c.distance_to(d)
    repr(c)
    repr(d)
    repr(e)
    repr(f)

    bool(c == (1, 1))
    bool(c == TikZCoordinate(1, 1))
    bool(TikZCoordinate(1, 1, relative=True) == (1, 1))
    bool(TikZCoordinate(1, 1, relative=False) == (1, 1))
    bool(
        TikZCoordinate(1, 1, relative=True) == TikZCoordinate(
            1, 1, relative=False))

    # test expected to fail
    try:
        g = TikZCoordinate(0, 1, relative=True) +\
            TikZCoordinate(1, 0, relative=False)
        repr(g)
        raise Exception
    except ValueError:
        pass

    a = TikZNodeAnchor(node_handle=None, anchor_name=None)
    repr(a)

    n = TikZNode(handle=None, options=None, at=None, text=None)
    repr(n)

    p = n.get_anchor_point("north")
    repr(p)

    p = n.get_anchor_point('_180')
    repr(p)

    p = n.west
    repr(p)

    up = TikZUserPath(path_type="edge", options=TikZOptions('bend right'))
    repr(up)

    pl = TikZPathList('(0, 1)', '--', '(2, 0)')
    pl.append((0.5, 0))
    repr(pl)

    # generate a failure, illegal start
    try:
        pl = TikZPathList('--', '(0, 1)')
        raise Exception
    except TypeError:
        pass

    # fail with illegal path type
    try:
        pl = TikZPathList('(0, 1)', 'illegal', '(0, 2)')
        raise Exception
    except ValueError:
        pass

    # fail with path after path
    try:
        pl = TikZPathList('(0, 1)', '--', '--')
        raise Exception
    except ValueError:
        pass

    # other type of failure: illegal identifier after path
    try:
        pl = TikZPathList('(0, 1)', '--', 'illegal')
        raise Exception
    except (ValueError, TypeError):
        pass

    pt = TikZPath(path=None, options=TikZOptions("->"))
    pt.append(TikZCoordinate(0, 1, relative=True))
    repr(pt)

    pt = TikZPath(path=[n.west, 'edge', TikZCoordinate(0, 1, relative=True)])
    repr(pt)

    pt = TikZPath(path=pl, options=None)
    repr(pt)

    dr = TikZDraw(path=None, options=None)
    repr(dr)
Ejemplo n.º 9
0
    def draw_calendar(self, month: int):
        scope_kwargs = {
            'shift': f'{{({self.x:.4f}, {self.y:.4f})}}',
            'rotate': f'{self.rot:.4f}'
        }
        scope_options = TikZOptions(**scope_kwargs)
        scope = TikZScope(options=scope_options)

        rotation = {'rotate': f'{self.rot:.4f}'}

        if self.debug:
            debug_options = TikZOptions(**rotation)
            scope.append(
                TikZNode(text=r'\color{red} x',
                         at=TikZCoordinate(0.0, 0.0),
                         options=debug_options))

        ## First, the title
        title_xy = (0.0, 2.5 * self.DY)
        title_coords = TikZCoordinate(*title_xy)
        title_options = TikZOptions(**rotation)
        title_text = f'{{\\bfseries\\color{{blue!50}} {self.MONTH_NAMES[month]}}} {self.year}'
        title_node = TikZNode(text=title_text,
                              at=title_coords,
                              options=title_options)

        scope.append(title_node)

        ## Now the days
        default_options = TikZOptions(align='right', anchor='base', **rotation)
        special_options = TikZOptions(draw='none',
                                      radius='0.2',
                                      anchor='base',
                                      fill='blue!20')
        magical_options = TikZOptions(draw='blue!30',
                                      radius='0.2',
                                      anchor='base',
                                      fill='none')

        day = dt.date(self.year, month, 1)
        col = (day.weekday() + 1) % 7
        row = 0 if col != 0 else -1

        x0 = -3 * self.DX
        y0 = self.DY

        while day.month == month:
            col = (day.weekday() + 1) % 7
            if col == 0:
                color = 'blue!50'
                row += 1
            else:
                color = 'black'

            x = x0 + float(self.DX * col)
            y = y0 - float(self.DY * row)

            if day in self.dates:
                if col == 0:
                    scope.append(
                        TikZDraw([f'({x:.5f}, {y+0.125:.5f})', 'circle'],
                                 options=magical_options))
                else:
                    scope.append(
                        TikZDraw([f'({x:.5f}, {y+0.125:.5f})', 'circle'],
                                 options=special_options))

            xy = TikZCoordinate(x, y)

            node = TikZNode(text=f'\\color{{{color}}} {day.day}',
                            at=xy,
                            options=default_options)

            scope.append(node)

            day = day + self.DAY_DELTA

        self.pic.append(scope)