47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
# -*- encoding: utf-8 -*-
|
|
|
|
from ..element import element
|
|
|
|
|
|
class axis(element):
|
|
""" Class representing an axis. """
|
|
|
|
templates = {
|
|
"options": "[{content}]",
|
|
"legends": "\\legend{{{content}}}",
|
|
"content": """\\begin{{axis}}{options}
|
|
{inner}
|
|
{legend}
|
|
\\end{{axis}}""",
|
|
}
|
|
|
|
def __init__(self, *args, parent=None, legend=None, label=None, **kwargs):
|
|
super().__init__(parent, label=label)
|
|
self.options = kwargs
|
|
self.legend = legend
|
|
for arg in args:
|
|
self.add(arg)
|
|
|
|
def content(self):
|
|
leg = ""
|
|
if self.legend:
|
|
if type(self.legend) is str:
|
|
leg = self.legend
|
|
else:
|
|
leg = self.fmt().format(
|
|
"legends",
|
|
{
|
|
"content": ", ".join(
|
|
"{{{}}}".format(p.legend) for p in self.childrens
|
|
)
|
|
},
|
|
)
|
|
return self.fmt().format(
|
|
"content",
|
|
{
|
|
"options": self.format_options(self.options),
|
|
"inner": super().content(),
|
|
"legend": leg,
|
|
},
|
|
)
|