Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a tikz method to FinitePoset class #38848

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/sage/combinat/posets/posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,76 @@
"""
return self.hasse_diagram()._latex_()

def tikz(self, format=None, edge_labels=False, color_by_label=False,
prog='dot', rankdir='up', standalone_config=None,
usepackage=None, usetikzlibrary=None, macros=None,
use_sage_preamble=None, **kwds):
r"""
Return a TikzPicture illustrating the poset.

If ``graphviz`` and ``dot2tex`` are available, it uses these packages for
placements of vertices and edges.

INPUT:

- ``format`` -- string (default: ``None``), ``'dot2tex'`` or
``'tkz_graph'``. If ``None``, it is set to ``'dot2tex'`` if
dot2tex is present, otherwise it is set to ``'tkz_graph'``.
- ``edge_labels`` -- bool (default: ``False``)
- ``color_by_label`` -- boolean or dictionary or function (default:
``False``); whether to color each edge with a different color
according to its label; the colors are chosen along a rainbow, unless
they are specified by a function or dictionary mapping labels to
colors;

When using format ``'dot2tex'``, the following inputs are considered:

- ``prog`` -- string (default: ``'dot'``) the program used for the
layout corresponding to one of the software of the graphviz
suite: 'dot', 'neato', 'twopi', 'circo' or 'fdp'.
- ``rankdir`` -- string (default: ``'up'``), direction of graph layout
when prog is ``'dot'``, possible values are ``'down'``,
``'up'``, ``'right'`` and ``'left'``.

Additional keywords arguments are forwarded to
:meth:`sage.graphs.graph_latex.GraphLatex.set_option`.

The following inputs define the preamble of the latex standalone
document class file containing the tikzpicture:

- ``standalone_config`` -- list of strings (default: ``["border=4mm"]``);
latex document class standalone configuration options
- ``usepackage`` -- list of strings (default: ``[]``); latex
packages
- ``usetikzlibrary`` -- list of strings (default: ``[]``); tikz
libraries to use
- ``macros`` -- list of strings (default: ``[]``); list of
newcommands needed for the picture
- ``use_sage_preamble`` -- bool (default: ``None``), if ``None``
it is set to ``True`` if and only if format is ``'tkz_graph'``

OUTPUT:

An instance of :mod:`sage.misc.latex_standalone.TikzPicture`.

.. NOTE::

Prerequisite: dot2tex optional Sage package and graphviz must be
installed when using format ``'dot2tex'``.

EXAMPLES::

sage: P = Poset(([1,2], [[1,2]]), cover_relations=True)
sage: tikz = P.tikz() # optional - dot2tex graphviz # long time
sage: _ = tikz.pdf(view=False) # optional - dot2tex graphviz latex # long time
"""
G = self.hasse_diagram()
return G.tikz(format=format, edge_labels=edge_labels,

Check warning on line 1466 in src/sage/combinat/posets/posets.py

View check run for this annotation

Codecov / codecov/patch

src/sage/combinat/posets/posets.py#L1465-L1466

Added lines #L1465 - L1466 were not covered by tests
color_by_label=color_by_label, prog=prog, rankdir=rankdir,
standalone_config=standalone_config, usepackage=usepackage,
usetikzlibrary=usetikzlibrary, macros=macros,
use_sage_preamble=use_sage_preamble, **kwds)

def _repr_(self):
r"""
Return a string representation of the poset.
Expand Down
Loading