Skip to content

Commit de6f6c9

Browse files
committed
Remove code duplication by moving the draw function into the drawing module
1 parent d7cfffd commit de6f6c9

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

python/tskit/drawing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,13 @@ def __init__(
894894
self.dwg_base = dwg.add(dwg.g(class_=svg_class))
895895
self.drawing = dwg
896896

897+
def draw(self, path=None):
898+
output = self.drawing.tostring()
899+
if path is not None:
900+
# TODO remove the 'pretty' when we are done debugging this.
901+
self.drawing.saveas(path, pretty=True)
902+
return SVGString(output)
903+
897904
def get_plotbox(self):
898905
"""
899906
Get the svgwrite plotbox, creating it if necessary.

python/tskit/trees.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ def draw_svg(
19651965
:return: An SVG representation of a tree.
19661966
:rtype: SVGString
19671967
"""
1968-
draw = drawing.SvgTree(
1968+
svgtree = drawing.SvgTree(
19691969
self,
19701970
size,
19711971
time_scale=time_scale,
@@ -1996,11 +1996,7 @@ def draw_svg(
19961996
preamble=preamble,
19971997
**kwargs,
19981998
)
1999-
output = draw.drawing.tostring()
2000-
if path is not None:
2001-
# TODO: removed the pretty here when this is stable.
2002-
draw.drawing.saveas(path, pretty=True)
2003-
return drawing.SVGString(output)
1999+
return svgtree.draw(path)
20042000

20052001
def draw(
20062002
self,
@@ -7600,7 +7596,7 @@ def draw_svg(
76007596
strictly within an empty region then that tree will not be plotted on the
76017597
right hand side, and the X axis will end at ``empty_tree.interval.left``
76027598
"""
7603-
draw = drawing.SvgTreeSequence(
7599+
svgtreesequence = drawing.SvgTreeSequence(
76047600
self,
76057601
size,
76067602
x_scale=x_scale,
@@ -7630,11 +7626,7 @@ def draw_svg(
76307626
preamble=preamble,
76317627
**kwargs,
76327628
)
7633-
output = draw.drawing.tostring()
7634-
if path is not None:
7635-
# TODO remove the 'pretty' when we are done debugging this.
7636-
draw.drawing.saveas(path, pretty=True)
7637-
return drawing.SVGString(output)
7629+
return svgtreesequence.draw(path)
76387630

76397631
def draw_text(
76407632
self,

0 commit comments

Comments
 (0)