Пример #1
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
Пример #2
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)