Skip to content

Commit 8e22f01

Browse files
committed
Create the document element inside the function to allow for multiple uses (i.e., library)
1 parent 703d445 commit 8e22f01

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

python/svgFactory.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
import sys
1111
from enum import Enum
1212

13-
document = dom.Document()
14-
1513
def generateSVG(plot):
1614
# Create svg with similar attributes to plotter
15+
document = dom.Document()
1716
svg = document.appendChild(document.createElement('svg'))
1817
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg")
1918
svg.setAttribute("id", "main-plot")
@@ -107,11 +106,11 @@ def generateSVG(plot):
107106
plot.create_legend()
108107
svg.appendChild(plot.get_plot())
109108
# Create axes with tick marks
110-
axis_left = axis("left", None, plot)
111-
axis_right = axis("right", None, plot)
112-
axis_bottom = axis("bottom", None, plot)
113-
axis_top = axis("top", None, plot)
114-
axis_middle = axis("middle", None, plot)
109+
axis_left = axis("left", None, plot, document)
110+
axis_right = axis("right", None, plot, document)
111+
axis_bottom = axis("bottom", None, plot, document)
112+
axis_top = axis("top", None, plot, document)
113+
axis_middle = axis("middle", None, plot, document)
115114
# Append all elements to svg
116115
svg.appendChild(axis_left)
117116
svg.appendChild(axis_right)
@@ -122,7 +121,7 @@ def generateSVG(plot):
122121
return svg
123122

124123
# Create axis elements for plot
125-
def axis(orient, scale, plot):
124+
def axis(orient, scale, plot, document):
126125
# Use appropriate tick parameters for axis
127126
tickSpacing = 23.5 if orient == "left" or orient == "right" else 25
128127
tickSize = 6 if orient == "left" or orient == "top" else -6

0 commit comments

Comments
 (0)