提交 46e3c80e 编写于 作者: HansBug's avatar HansBug 😆

dev(hansbug): add jupyter repr support

上级 a5addeb2
......@@ -47,6 +47,8 @@ cdef class TreeValue:
cpdef void validate(self) except*
cdef object _get_tree_graph(self)
cdef str _prefix_fix(object text, object prefix)
cdef str _title_repr(TreeStorage st, object type_)
cdef object _build_tree(TreeStorage st, object type_, str prefix, dict id_pool, tuple path)
......
......@@ -932,6 +932,23 @@ cdef class TreeValue:
else:
return self._type(self._st, constraint=to_constraint([constraint, self.constraint]))
@cython.final
cdef inline object _get_tree_graph(self):
from .graph import graphics
return graphics((self, '<root>'))
@cython.binding(True)
def _repr_svg_(self):
return self._get_tree_graph().pipe(format='svg', encoding='utf-8')
@cython.binding(True)
def _repr_png_(self):
return self._get_tree_graph().pipe(format='png')
@cython.binding(True)
def _repr_jpeg_(self):
return self._get_tree_graph().pipe(format='jpeg')
cdef str _prefix_fix(object text, object prefix):
cdef list lines = []
cdef int i
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册