diff --git a/pyqtgraph/exporters/SVGExporter.py b/pyqtgraph/exporters/SVGExporter.py index 6f0035bb..84af1a19 100644 --- a/pyqtgraph/exporters/SVGExporter.py +++ b/pyqtgraph/exporters/SVGExporter.py @@ -17,17 +17,17 @@ class SVGExporter(Exporter): def __init__(self, item): Exporter.__init__(self, item) - #tr = self.getTargetRect() + tr = self.getTargetRect() self.params = Parameter(name='params', type='group', children=[ - #{'name': 'width', 'type': 'float', 'value': tr.width(), 'limits': (0, None)}, - #{'name': 'height', 'type': 'float', 'value': tr.height(), 'limits': (0, None)}, + {'name': 'width', 'type': 'float', 'value': tr.width(), 'limits': (0, None)}, + {'name': 'height', 'type': 'float', 'value': tr.height(), 'limits': (0, None)}, #{'name': 'viewbox clipping', 'type': 'bool', 'value': True}, #{'name': 'normalize coordinates', 'type': 'bool', 'value': True}, {'name': 'scaling stroke', 'type': 'bool', 'value': False, 'tip': "If False, strokes are non-scaling, " "which means that they appear the same width on screen regardless of how they are scaled or how the view is zoomed."}, ]) - #self.params.param('width').sigValueChanged.connect(self.widthChanged) - #self.params.param('height').sigValueChanged.connect(self.heightChanged) + self.params.param('width').sigValueChanged.connect(self.widthChanged) + self.params.param('height').sigValueChanged.connect(self.heightChanged) def widthChanged(self): sr = self.getSourceRect() @@ -51,6 +51,8 @@ class SVGExporter(Exporter): ## Instead, we will use Qt to generate SVG for each item independently, ## then manually reconstruct the entire document. options = {ch.name():ch.value() for ch in self.params.children()} + options['width'] = self.params['width'] + options['height'] = self.params['height'] xml = generateSvg(self.item, options) if toBytes: @@ -63,10 +65,10 @@ class SVGExporter(Exporter): with open(fileName, 'wb') as fh: fh.write(asUnicode(xml).encode('utf-8')) - +# Includes space for extra attributes xmlHeader = """\ - + pyqtgraph SVG export Generated with Qt and pyqtgraph \n" + svgAttributes = f' viewBox ="0 0 {options["width"]} {options["height"]}"' + return (xmlHeader % svgAttributes) + defsXml + node.toprettyxml(indent=' ') + "\n\n" def _generateItemSvg(item, nodes=None, root=None, options={}):