Skip to content

Commit

Permalink
Fixed #6196, dead clip path references.
Browse files Browse the repository at this point in the history
  • Loading branch information
oysteinmoseng committed Jan 4, 2017
1 parent 2fd714e commit 6b993dd
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
14 changes: 13 additions & 1 deletion js/parts/SvgRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1335,13 +1335,25 @@ SVGElement.prototype = {
parentToClean = wrapper.renderer.isSVG && element.nodeName === 'SPAN' && wrapper.parentGroup,
grandParent,
key,
i;
i,
elementsWithClipPaths;

// remove events
element.onclick = element.onmouseout = element.onmouseover = element.onmousemove = element.point = null;
stop(wrapper); // stop running animations

if (wrapper.clipPath) {
// Look for existing references to this clipPath and remove them
// before destroying the element
elementsWithClipPaths = wrapper.element.ownerSVGElement
.querySelectorAll('[clip-path]');
each(elementsWithClipPaths, function (el) {
if (el.getAttribute('clip-path').indexOf(
wrapper.clipPath.element.id) > -1) {
el.removeAttribute('clip-path');
}
});

wrapper.clipPath = wrapper.clipPath.destroy();
}

Expand Down
5 changes: 5 additions & 0 deletions samples/unit-tests/svgrenderer/clip-paths/demo.details
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
resources:
- https://code.jquery.com/qunit/qunit-2.0.1.js
- https://code.jquery.com/qunit/qunit-2.0.1.css
...
7 changes: 7 additions & 0 deletions samples/unit-tests/svgrenderer/clip-paths/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="qunit"></div>
<div id="qunit-fixture"></div>


<div id="container" style="width: 600px; margin: 0 auto;"></div>
43 changes: 43 additions & 0 deletions samples/unit-tests/svgrenderer/clip-paths/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
QUnit.test('Verify that references to unused clip paths are removed after animation',
function (assert) {
var done = assert.async(2),
// Get list of unique clip path references
getClipPathSet = function (chart) {
var clipPathList = [];
Highcharts.each(
chart.container.querySelectorAll('[clip-path]'),
function (clipPath) {
var p = clipPath.getAttribute('clip-path');
if (Highcharts.inArray(p, clipPathList) < 0) {
clipPathList.push(p);
}
}
);
return clipPathList;
};

Highcharts.chart('container', {
chart: {
events: {
load: function () {
assert.strictEqual(getClipPathSet(this).length, 2,
'There are references to two different clipPaths');
done();
}
}
},
series: [{
data: [1, 2, 3, 4],
animation: {
duration: 1
},
events: {
afterAnimate: function () {
assert.strictEqual(getClipPathSet(this.chart).length, 1,
'There are only references to one clipPath after animation');
done();
}
}
}]
});
});

0 comments on commit 6b993dd

Please sign in to comment.