SVGExporter.py 19.1 KB
Newer Older
1
from .Exporter import Exporter
2
from pyqtgraph.python2_3 import asUnicode
3
4
from pyqtgraph.parametertree import Parameter
from pyqtgraph.Qt import QtGui, QtCore, QtSvg
Luke Campagnola's avatar
Luke Campagnola committed
5
import pyqtgraph as pg
6
7
import re
import xml.dom.minidom as xml
Luke Campagnola's avatar
Luke Campagnola committed
8
import numpy as np
9
10
11
12
13
14


__all__ = ['SVGExporter']

class SVGExporter(Exporter):
    Name = "Scalable Vector Graphics (SVG)"
15
16
    allowCopy=True
    
17
18
19
20
21
22
    def __init__(self, item):
        Exporter.__init__(self, item)
        #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)},
Luke Campagnola's avatar
Luke Campagnola committed
23
24
25
            #{'name': 'viewbox clipping', 'type': 'bool', 'value': True},
            #{'name': 'normalize coordinates', 'type': 'bool', 'value': True},
            #{'name': 'normalize line width', 'type': 'bool', 'value': True},
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
        ])
        #self.params.param('width').sigValueChanged.connect(self.widthChanged)
        #self.params.param('height').sigValueChanged.connect(self.heightChanged)

    def widthChanged(self):
        sr = self.getSourceRect()
        ar = sr.height() / sr.width()
        self.params.param('height').setValue(self.params['width'] * ar, blockSignal=self.heightChanged)
        
    def heightChanged(self):
        sr = self.getSourceRect()
        ar = sr.width() / sr.height()
        self.params.param('width').setValue(self.params['height'] * ar, blockSignal=self.widthChanged)
        
    def parameters(self):
        return self.params
    
43
44
    def export(self, fileName=None, toBytes=False, copy=False):
        if toBytes is False and copy is False and fileName is None:
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
            self.fileSaveDialog(filter="Scalable Vector Graphics (*.svg)")
            return
        #self.svg = QtSvg.QSvgGenerator()
        #self.svg.setFileName(fileName)
        #dpi = QtGui.QDesktopWidget().physicalDpiX()
        ### not really sure why this works, but it seems to be important:
        #self.svg.setSize(QtCore.QSize(self.params['width']*dpi/90., self.params['height']*dpi/90.))
        #self.svg.setResolution(dpi)
        ##self.svg.setViewBox()
        #targetRect = QtCore.QRect(0, 0, self.params['width'], self.params['height'])
        #sourceRect = self.getSourceRect()
        
        #painter = QtGui.QPainter(self.svg)
        #try:
            #self.setExportMode(True)
            #self.render(painter, QtCore.QRectF(targetRect), sourceRect)
        #finally:
            #self.setExportMode(False)
        #painter.end()

        ## Workaround to set pen widths correctly
        #data = open(fileName).readlines()
        #for i in range(len(data)):
            #line = data[i]
            #m = re.match(r'(<g .*)stroke-width="1"(.*transform="matrix\(([^\)]+)\)".*)', line)
            #if m is not None:
                ##print "Matched group:", line
                #g = m.groups()
                #matrix = list(map(float, g[2].split(',')))
                ##print "matrix:", matrix
                #scale = max(abs(matrix[0]), abs(matrix[3]))
                #if scale == 0 or scale == 1.0:
                    #continue
                #data[i] = g[0] + ' stroke-width="%0.2g" ' % (1.0/scale) + g[1] + '\n'
                ##print "old line:", line
                ##print "new line:", data[i]
        #open(fileName, 'w').write(''.join(data))
Luke Campagnola's avatar
Luke Campagnola committed
82
83
84
85
86
87
88
        
        ## Qt's SVG generator is not complete. (notably, it lacks clipping)
        ## Instead, we will use Qt to generate SVG for each item independently,
        ## then manually reconstruct the entire document.
        xml = generateSvg(self.item)
        
        if toBytes:
89
90
91
92
93
            return xml.encode('UTF-8')
        elif copy:
            md = QtCore.QMimeData()
            md.setData('image/svg+xml', QtCore.QByteArray(xml.encode('UTF-8')))
            QtGui.QApplication.clipboard().setMimeData(md)
Luke Campagnola's avatar
Luke Campagnola committed
94
        else:
95
96
            with open(fileName, 'wb') as fh:
                fh.write(asUnicode(xml).encode('utf-8'))
97

98

Luke Campagnola's avatar
Luke Campagnola committed
99
xmlHeader = """\
100
101
102
103
104
105
<?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">
<title>pyqtgraph SVG export</title>
<desc>Generated with Qt and pyqtgraph</desc>
<defs>
</defs>
Luke Campagnola's avatar
Luke Campagnola committed
106
"""
107

Luke Campagnola's avatar
Luke Campagnola committed
108
109
110
111
112
113
def generateSvg(item):
    global xmlHeader
    try:
        node = _generateItemSvg(item)
    finally:
        ## reset export mode for all items in the tree
114
        if isinstance(item, QtGui.QGraphicsScene):
Luke Campagnola's avatar
Luke Campagnola committed
115
            items = item.items()
116
        else:
Luke Campagnola's avatar
Luke Campagnola committed
117
118
119
120
121
122
123
124
125
126
            items = [item]
            for i in items:
                items.extend(i.childItems())
        for i in items:
            if hasattr(i, 'setExportMode'):
                i.setExportMode(False)
    
    cleanXml(node)
    
    return xmlHeader + node.toprettyxml(indent='    ') + "\n</svg>\n"
127

Luke Campagnola's avatar
Luke Campagnola committed
128
129
130
131
132
133
134

def _generateItemSvg(item, nodes=None, root=None):
    ## This function is intended to work around some issues with Qt's SVG generator
    ## and SVG in general.
    ## 1) Qt SVG does not implement clipping paths. This is absurd.
    ##    The solution is to let Qt generate SVG for each item independently,
    ##    then glue them together manually with clipping.
Luke Campagnola's avatar
Luke Campagnola committed
135
136
137
138
139
140
141
142
143
144
145
146
147
    ##    
    ##    The format Qt generates for all items looks like this:
    ##    
    ##    <g>
    ##        <g transform="matrix(...)">
    ##            one or more of: <path/> or <polyline/> or <text/>
    ##        </g>
    ##        <g transform="matrix(...)">
    ##            one or more of: <path/> or <polyline/> or <text/>
    ##        </g>
    ##        . . .
    ##    </g>
    ##    
Luke Campagnola's avatar
Luke Campagnola committed
148
149
150
151
152
    ## 2) There seems to be wide disagreement over whether path strokes
    ##    should be scaled anisotropically. 
    ##      see: http://web.mit.edu/jonas/www/anisotropy/
    ##    Given that both inkscape and illustrator seem to prefer isotropic
    ##    scaling, we will optimize for those cases.  
Luke Campagnola's avatar
Luke Campagnola committed
153
    ##    
Luke Campagnola's avatar
Luke Campagnola committed
154
155
    ## 3) Qt generates paths using non-scaling-stroke from SVG 1.2, but 
    ##    inkscape only supports 1.1. 
Luke Campagnola's avatar
Luke Campagnola committed
156
157
    ##    
    ##    Both 2 and 3 can be addressed by drawing all items in world coordinates.
Luke Campagnola's avatar
Luke Campagnola committed
158
    
159
    prof = pg.debug.Profiler('generateItemSvg %s' % str(item), disabled=True)
Luke Campagnola's avatar
Luke Campagnola committed
160
161
162
163
    
    if nodes is None:  ## nodes maps all node IDs to their XML element. 
                       ## this allows us to ensure all elements receive unique names.
        nodes = {}
164
        
Luke Campagnola's avatar
Luke Campagnola committed
165
166
    if root is None:
        root = item
Luke Campagnola's avatar
Luke Campagnola committed
167
                
Luke Campagnola's avatar
Luke Campagnola committed
168
169
170
171
172
173
174
175
    ## Skip hidden items
    if hasattr(item, 'isVisible') and not item.isVisible():
        return None
        
    ## If this item defines its own SVG generator, use that.
    if hasattr(item, 'generateSvg'):
        return item.generateSvg(nodes)
    
176

Luke Campagnola's avatar
Luke Campagnola committed
177
178
179
180
    ## Generate SVG text for just this item (exclude its children; we'll handle them later)
    tr = QtGui.QTransform()
    if isinstance(item, QtGui.QGraphicsScene):
        xmlStr = "<g>\n</g>\n"
181
        doc = xml.parseString(xmlStr)
Luke Campagnola's avatar
Luke Campagnola committed
182
        childs = [i for i in item.items() if i.parentItem() is None]
183
184
    elif item.__class__.paint == QtGui.QGraphicsItem.paint:
        xmlStr = "<g>\n</g>\n"
Luke Campagnola's avatar
Luke Campagnola committed
185
        doc = xml.parseString(xmlStr)
186
        childs = item.childItems()
Luke Campagnola's avatar
Luke Campagnola committed
187
188
    else:
        childs = item.childItems()
Luke Campagnola's avatar
Luke Campagnola committed
189
        tr = itemTransform(item, item.scene())
Luke Campagnola's avatar
Luke Campagnola committed
190
        
Luke Campagnola's avatar
Luke Campagnola committed
191
192
193
194
195
196
197
198
        ## offset to corner of root item
        if isinstance(root, QtGui.QGraphicsScene):
            rootPos = QtCore.QPoint(0,0)
        else:
            rootPos = root.scenePos()
        tr2 = QtGui.QTransform()
        tr2.translate(-rootPos.x(), -rootPos.y())
        tr = tr * tr2
Luke Campagnola's avatar
Luke Campagnola committed
199
200
        #print item, pg.SRTTransform(tr)

Luke Campagnola's avatar
Luke Campagnola committed
201
202
        #tr.translate(item.pos().x(), item.pos().y())
        #tr = tr * item.transform()
Luke Campagnola's avatar
Luke Campagnola committed
203
204
205
206
207
208
209
210
        arr = QtCore.QByteArray()
        buf = QtCore.QBuffer(arr)
        svg = QtSvg.QSvgGenerator()
        svg.setOutputDevice(buf)
        dpi = QtGui.QDesktopWidget().physicalDpiX()
        ### not really sure why this works, but it seems to be important:
        #self.svg.setSize(QtCore.QSize(self.params['width']*dpi/90., self.params['height']*dpi/90.))
        svg.setResolution(dpi)
211

Luke Campagnola's avatar
Luke Campagnola committed
212
213
214
215
216
        p = QtGui.QPainter()
        p.begin(svg)
        if hasattr(item, 'setExportMode'):
            item.setExportMode(True, {'painter': p})
        try:
Luke Campagnola's avatar
Luke Campagnola committed
217
            p.setTransform(tr)
Luke Campagnola's avatar
Luke Campagnola committed
218
219
220
221
222
223
224
            item.paint(p, QtGui.QStyleOptionGraphicsItem(), None)
        finally:
            p.end()
            ## Can't do this here--we need to wait until all children have painted as well.
            ## this is taken care of in generateSvg instead.
            #if hasattr(item, 'setExportMode'):
                #item.setExportMode(False)
225
226

        xmlStr = bytes(arr).decode('utf-8')
Luke Campagnola's avatar
Luke Campagnola committed
227
228
229
230
231
232
233
234
        doc = xml.parseString(xmlStr)
        
    try:
        ## Get top-level group for this item
        g1 = doc.getElementsByTagName('g')[0]
        ## get list of sub-groups
        g2 = [n for n in g1.childNodes if isinstance(n, xml.Element) and n.tagName == 'g']
    except:
235
        print(doc.toxml())
Luke Campagnola's avatar
Luke Campagnola committed
236
        raise
Luke Campagnola's avatar
Luke Campagnola committed
237

238
    prof.mark('render')
Luke Campagnola's avatar
Luke Campagnola committed
239
240
241
242

    ## Get rid of group transformation matrices by applying
    ## transformation to inner coordinates
    correctCoordinates(g1, item)
243
    prof.mark('correct')
Luke Campagnola's avatar
Luke Campagnola committed
244
    ## make sure g1 has the transformation matrix
Luke Campagnola's avatar
Luke Campagnola committed
245
246
    #m = (tr.m11(), tr.m12(), tr.m21(), tr.m22(), tr.m31(), tr.m32())
    #g1.setAttribute('transform', "matrix(%f,%f,%f,%f,%f,%f)" % m)
Luke Campagnola's avatar
Luke Campagnola committed
247
248
249
250
251
252
    
    #print "=================",item,"====================="
    #print g1.toprettyxml(indent="  ", newl='')
    
    ## Inkscape does not support non-scaling-stroke (this is SVG 1.2, inkscape supports 1.1)
    ## So we need to correct anything attempting to use this.
Luke Campagnola's avatar
Luke Campagnola committed
253
    #correctStroke(g1, item, root)
Luke Campagnola's avatar
Luke Campagnola committed
254
255
256
257
258
259
260
261
262
263
264
265
    
    ## decide on a name for this item
    baseName = item.__class__.__name__
    i = 1
    while True:
        name = baseName + "_%d" % i
        if name not in nodes:
            break
        i += 1
    nodes[name] = g1
    g1.setAttribute('id', name)
    
Luke Campagnola's avatar
Luke Campagnola committed
266
    ## If this item clips its children, we need to take care of that.
Luke Campagnola's avatar
Luke Campagnola committed
267
268
269
270
271
    childGroup = g1  ## add children directly to this node unless we are clipping
    if not isinstance(item, QtGui.QGraphicsScene):
        ## See if this item clips its children
        if int(item.flags() & item.ItemClipsChildrenToShape) > 0:
            ## Generate svg for just the path
Luke Campagnola's avatar
Luke Campagnola committed
272
273
274
275
276
277
278
279
280
281
282
            #if isinstance(root, QtGui.QGraphicsScene):
                #path = QtGui.QGraphicsPathItem(item.mapToScene(item.shape()))
            #else:
                #path = QtGui.QGraphicsPathItem(root.mapToParent(item.mapToItem(root, item.shape())))
            path = QtGui.QGraphicsPathItem(item.mapToScene(item.shape()))
            item.scene().addItem(path)
            try:
                pathNode = _generateItemSvg(path, root=root).getElementsByTagName('path')[0]
            finally:
                item.scene().removeItem(path)
            
Luke Campagnola's avatar
Luke Campagnola committed
283
284
285
286
287
288
289
290
291
292
            ## and for the clipPath element
            clip = name + '_clip'
            clipNode = g1.ownerDocument.createElement('clipPath')
            clipNode.setAttribute('id', clip)
            clipNode.appendChild(pathNode)
            g1.appendChild(clipNode)
            
            childGroup = g1.ownerDocument.createElement('g')
            childGroup.setAttribute('clip-path', 'url(#%s)' % clip)
            g1.appendChild(childGroup)
293
294
    prof.mark('clipping')
            
Luke Campagnola's avatar
Luke Campagnola committed
295
296
297
298
299
300
301
    ## Add all child items as sub-elements.
    childs.sort(key=lambda c: c.zValue())
    for ch in childs:
        cg = _generateItemSvg(ch, nodes, root)
        if cg is None:
            continue
        childGroup.appendChild(cg)  ### this isn't quite right--some items draw below their parent (good enough for now)
302
303
    prof.mark('children')
    prof.finish()
Luke Campagnola's avatar
Luke Campagnola committed
304
    return g1
305

Luke Campagnola's avatar
Luke Campagnola committed
306
307
def correctCoordinates(node, item):
    ## Remove transformation matrices from <g> tags by applying matrix to coordinates inside.
308
309
    ## Each item is represented by a single top-level group with one or more groups inside.
    ## Each inner group contains one or more drawing primitives, possibly of different types.
Luke Campagnola's avatar
Luke Campagnola committed
310
    groups = node.getElementsByTagName('g')
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
    
    ## Since we leave text unchanged, groups which combine text and non-text primitives must be split apart.
    ## (if at some point we start correcting text transforms as well, then it should be safe to remove this)
    groups2 = []
    for grp in groups:
        subGroups = [grp.cloneNode(deep=False)]
        textGroup = None
        for ch in grp.childNodes[:]:
            if isinstance(ch, xml.Element):
                if textGroup is None:
                    textGroup = ch.tagName == 'text'
                if ch.tagName == 'text':
                    if textGroup is False:
                        subGroups.append(grp.cloneNode(deep=False))
                        textGroup = True
                else:
                    if textGroup is True:
                        subGroups.append(grp.cloneNode(deep=False))
                        textGroup = False
            subGroups[-1].appendChild(ch)
        groups2.extend(subGroups)
        for sg in subGroups:
            node.insertBefore(sg, grp)
        node.removeChild(grp)
    groups = groups2
        
    
Luke Campagnola's avatar
Luke Campagnola committed
338
339
340
341
342
343
    for grp in groups:
        matrix = grp.getAttribute('transform')
        match = re.match(r'matrix\((.*)\)', matrix)
        if match is None:
            vals = [1,0,0,1,0,0]
        else:
344
            vals = [float(a) for a in match.groups()[0].split(',')]
Luke Campagnola's avatar
Luke Campagnola committed
345
346
347
348
349
350
351
352
        tr = np.array([[vals[0], vals[2], vals[4]], [vals[1], vals[3], vals[5]]])
        
        removeTransform = False
        for ch in grp.childNodes:
            if not isinstance(ch, xml.Element):
                continue
            if ch.tagName == 'polyline':
                removeTransform = True
353
                coords = np.array([[float(a) for a in c.split(',')] for c in ch.getAttribute('points').strip().split(' ')])
Luke Campagnola's avatar
Luke Campagnola committed
354
                coords = pg.transformCoordinates(tr, coords, transpose=True)
355
                ch.setAttribute('points', ' '.join([','.join([str(a) for a in c]) for c in coords]))
Luke Campagnola's avatar
Luke Campagnola committed
356
357
358
            elif ch.tagName == 'path':
                removeTransform = True
                newCoords = ''
Luke Campagnola's avatar
Luke Campagnola committed
359
360
361
362
                oldCoords = ch.getAttribute('d').strip()
                if oldCoords == '':
                    continue
                for c in oldCoords.split(' '):
Luke Campagnola's avatar
Luke Campagnola committed
363
364
365
366
367
368
369
370
371
372
373
                    x,y = c.split(',')
                    if x[0].isalpha():
                        t = x[0]
                        x = x[1:]
                    else:
                        t = ''
                    nc = pg.transformCoordinates(tr, np.array([[float(x),float(y)]]), transpose=True)
                    newCoords += t+str(nc[0,0])+','+str(nc[0,1])+' '
                ch.setAttribute('d', newCoords)
            elif ch.tagName == 'text':
                removeTransform = False
Luke Campagnola's avatar
Luke Campagnola committed
374
                ## leave text alone for now. Might need this later to correctly render text with outline.
Luke Campagnola's avatar
Luke Campagnola committed
375
376
377
378
379
380
381
382
383
384
                #c = np.array([
                    #[float(ch.getAttribute('x')), float(ch.getAttribute('y'))], 
                    #[float(ch.getAttribute('font-size')), 0], 
                    #[0,0]])
                #c = pg.transformCoordinates(tr, c, transpose=True)
                #ch.setAttribute('x', str(c[0,0]))
                #ch.setAttribute('y', str(c[0,1]))
                #fs = c[1]-c[2]
                #fs = (fs**2).sum()**0.5
                #ch.setAttribute('font-size', str(fs))
Luke Campagnola's avatar
Luke Campagnola committed
385
                
Luke Campagnola's avatar
Luke Campagnola committed
386
387
388
389
390
391
392
393
394
395
396
397
                ## Correct some font information
                families = ch.getAttribute('font-family').split(',')
                if len(families) == 1:
                    font = QtGui.QFont(families[0].strip('" '))
                    if font.style() == font.SansSerif:
                        families.append('sans-serif')
                    elif font.style() == font.Serif:
                        families.append('serif')
                    elif font.style() == font.Courier:
                        families.append('monospace')
                    ch.setAttribute('font-family', ', '.join([f if ' ' not in f else '"%s"'%f for f in families]))
                
Luke Campagnola's avatar
Luke Campagnola committed
398
399
400
401
402
403
            ## correct line widths if needed
            if removeTransform and ch.getAttribute('vector-effect') != 'non-scaling-stroke':
                w = float(grp.getAttribute('stroke-width'))
                s = pg.transformCoordinates(tr, np.array([[w,0], [0,0]]), transpose=True)
                w = ((s[0]-s[1])**2).sum()**0.5
                ch.setAttribute('stroke-width', str(w))
Luke Campagnola's avatar
Luke Campagnola committed
404
405
406
            
        if removeTransform:
            grp.removeAttribute('transform')
407

Luke Campagnola's avatar
Luke Campagnola committed
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
def itemTransform(item, root):
    ## Return the transformation mapping item to root
    ## (actually to parent coordinate system of root)
    
    if item is root:
        tr = QtGui.QTransform()
        tr.translate(*item.pos())
        tr = tr * item.transform()
        return tr
        
    
    if int(item.flags() & item.ItemIgnoresTransformations) > 0:
        pos = item.pos()
        parent = item.parentItem()
        if parent is not None:
            pos = itemTransform(parent, root).map(pos)
        tr = QtGui.QTransform()
        tr.translate(pos.x(), pos.y())
        tr = item.transform() * tr
    else:
        ## find next parent that is either the root item or 
        ## an item that ignores its transformation
        nextRoot = item
        while True:
            nextRoot = nextRoot.parentItem()
            if nextRoot is None:
                nextRoot = root
                break
            if nextRoot is root or int(nextRoot.flags() & nextRoot.ItemIgnoresTransformations) > 0:
                break
        
        if isinstance(nextRoot, QtGui.QGraphicsScene):
            tr = item.sceneTransform()
Luke Campagnola's avatar
Luke Campagnola committed
441
        else:
Luke Campagnola's avatar
Luke Campagnola committed
442
443
444
445
446
            tr = itemTransform(nextRoot, root) * item.itemTransform(nextRoot)[0]
            #pos = QtGui.QTransform()
            #pos.translate(root.pos().x(), root.pos().y())
            #tr = pos * root.transform() * item.itemTransform(root)[0]
        
Luke Campagnola's avatar
Luke Campagnola committed
447
    
Luke Campagnola's avatar
Luke Campagnola committed
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
    return tr


#def correctStroke(node, item, root, width=1):
    ##print "==============", item, node
    #if node.hasAttribute('stroke-width'):
        #width = float(node.getAttribute('stroke-width'))
    #if node.getAttribute('vector-effect') == 'non-scaling-stroke':
        #node.removeAttribute('vector-effect')
        #if isinstance(root, QtGui.QGraphicsScene):
            #w = item.mapFromScene(pg.Point(width,0))
            #o = item.mapFromScene(pg.Point(0,0))
        #else:
            #w = item.mapFromItem(root, pg.Point(width,0))
            #o = item.mapFromItem(root, pg.Point(0,0))
        #w = w-o
        ##print "   ", w, o, w-o
        #w = (w.x()**2 + w.y()**2) ** 0.5
        ##print "   ", w
        #node.setAttribute('stroke-width', str(w))
    
    #for ch in node.childNodes:
        #if isinstance(ch, xml.Element):
            #correctStroke(ch, item, root, width)
Luke Campagnola's avatar
Luke Campagnola committed
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
            
def cleanXml(node):
    ## remove extraneous text; let the xml library do the formatting.
    hasElement = False
    nonElement = []
    for ch in node.childNodes:
        if isinstance(ch, xml.Element):
            hasElement = True
            cleanXml(ch)
        else:
            nonElement.append(ch)
    
    if hasElement:
        for ch in nonElement:
            node.removeChild(ch)
Luke Campagnola's avatar
Luke Campagnola committed
487
488
    elif node.tagName == 'g':  ## remove childless groups
        node.parentNode.removeChild(node)