[SVGExporter] Fix width and height
This commit is contained in:
parent
b5de577c28
commit
5ed2e760ea
@ -17,17 +17,17 @@ class SVGExporter(Exporter):
|
|||||||
|
|
||||||
def __init__(self, item):
|
def __init__(self, item):
|
||||||
Exporter.__init__(self, item)
|
Exporter.__init__(self, item)
|
||||||
#tr = self.getTargetRect()
|
tr = self.getTargetRect()
|
||||||
self.params = Parameter(name='params', type='group', children=[
|
self.params = Parameter(name='params', type='group', children=[
|
||||||
#{'name': 'width', 'type': 'float', 'value': tr.width(), 'limits': (0, None)},
|
{'name': 'width', 'type': 'float', 'value': tr.width(), 'limits': (0, None)},
|
||||||
#{'name': 'height', 'type': 'float', 'value': tr.height(), 'limits': (0, None)},
|
{'name': 'height', 'type': 'float', 'value': tr.height(), 'limits': (0, None)},
|
||||||
#{'name': 'viewbox clipping', 'type': 'bool', 'value': True},
|
#{'name': 'viewbox clipping', 'type': 'bool', 'value': True},
|
||||||
#{'name': 'normalize coordinates', '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, "
|
{'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."},
|
"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('width').sigValueChanged.connect(self.widthChanged)
|
||||||
#self.params.param('height').sigValueChanged.connect(self.heightChanged)
|
self.params.param('height').sigValueChanged.connect(self.heightChanged)
|
||||||
|
|
||||||
def widthChanged(self):
|
def widthChanged(self):
|
||||||
sr = self.getSourceRect()
|
sr = self.getSourceRect()
|
||||||
@ -51,6 +51,8 @@ class SVGExporter(Exporter):
|
|||||||
## Instead, we will use Qt to generate SVG for each item independently,
|
## Instead, we will use Qt to generate SVG for each item independently,
|
||||||
## then manually reconstruct the entire document.
|
## then manually reconstruct the entire document.
|
||||||
options = {ch.name():ch.value() for ch in self.params.children()}
|
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)
|
xml = generateSvg(self.item, options)
|
||||||
|
|
||||||
if toBytes:
|
if toBytes:
|
||||||
@ -63,10 +65,10 @@ class SVGExporter(Exporter):
|
|||||||
with open(fileName, 'wb') as fh:
|
with open(fileName, 'wb') as fh:
|
||||||
fh.write(asUnicode(xml).encode('utf-8'))
|
fh.write(asUnicode(xml).encode('utf-8'))
|
||||||
|
|
||||||
|
# Includes space for extra attributes
|
||||||
xmlHeader = """\
|
xmlHeader = """\
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny"%s>
|
||||||
<title>pyqtgraph SVG export</title>
|
<title>pyqtgraph SVG export</title>
|
||||||
<desc>Generated with Qt and pyqtgraph</desc>
|
<desc>Generated with Qt and pyqtgraph</desc>
|
||||||
<style>
|
<style>
|
||||||
@ -100,7 +102,8 @@ def generateSvg(item, options={}):
|
|||||||
for d in defs:
|
for d in defs:
|
||||||
defsXml += d.toprettyxml(indent=' ')
|
defsXml += d.toprettyxml(indent=' ')
|
||||||
defsXml += "</defs>\n"
|
defsXml += "</defs>\n"
|
||||||
return xmlHeader + defsXml + node.toprettyxml(indent=' ') + "\n</svg>\n"
|
svgAttributes = f' viewBox ="0 0 {options["width"]} {options["height"]}"'
|
||||||
|
return (xmlHeader % svgAttributes) + defsXml + node.toprettyxml(indent=' ') + "\n</svg>\n"
|
||||||
|
|
||||||
|
|
||||||
def _generateItemSvg(item, nodes=None, root=None, options={}):
|
def _generateItemSvg(item, nodes=None, root=None, options={}):
|
||||||
|
Loading…
Reference in New Issue
Block a user