40 lines
1.1 KiB
Python
40 lines
1.1 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=True, label=None, **kargs):
|
|
super().__init__(parent, label=label)
|
|
self.options = kargs
|
|
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
|
|
})
|