Skip to content

Commit

Permalink
fix: bug when Text and shape using same clipPath
Browse files Browse the repository at this point in the history
fix and close apache/echarts#6989
Mostly because `appendChild` the same DOM element to different parents, making the previous appending invalid
  • Loading branch information
Ovilia committed Nov 13, 2017
1 parent 69e16cf commit c05ac82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/svg/Painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ SVGPainter.prototype = {
if (!displayable.invisible) {
if (displayable.__dirty) {
svgProxy && svgProxy.brush(displayable);
var el = getSvgElement(displayable)
|| getTextSvgElement(displayable);

// Update clipPath
this.clipPathManager.update(displayable, el);
this.clipPathManager.update(displayable);

// Update gradient
if (displayable.style) {
Expand Down
7 changes: 5 additions & 2 deletions src/svg/graphic.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,13 @@ var svgTextDrawRectText = function (el, rect, textRect) {

var text = style.text;
// Convert to string
text != null && (text += '');
if (!text) {
if (text == null) {
// Draw no text only when text is set to null, but not ''
return;
}
else {
text += '';
}

var textSvgEl = el.__textSvgEl;
if (! textSvgEl) {
Expand Down
16 changes: 12 additions & 4 deletions src/svg/helper/ClippathManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ zrUtil.inherits(ClippathManager, Definable);
* Update clipPath.
*
* @param {Displayable} displayable displayable element
* @param {SVGElement} svgElement SVG element of displayable
*/
ClippathManager.prototype.update = function (displayable, svgElement) {
this.updateDom(svgElement, displayable.__clipPaths, false);
ClippathManager.prototype.update = function (displayable) {
var svgEl = this.getSvgElement(displayable);
if (svgEl) {
this.updateDom(svgEl, displayable.__clipPaths, false);
}

var textEl = this.getTextSvgElement(displayable);
if (textEl) {
Expand Down Expand Up @@ -121,7 +123,13 @@ ClippathManager.prototype.updateDom = function (
}

var pathEl = this.getSvgElement(clipPath);
clipPathEl.appendChild(pathEl);
/**
* Use `cloneNode()` here to appendChild to multiple parents,
* which may happend when Text and other shapes are using the same
* clipPath. Since Text will create an extra clipPath DOM due to
* different transform rules.
*/
clipPathEl.appendChild(pathEl.cloneNode());

parentEl.setAttribute('clip-path', 'url(#' + id + ')');

Expand Down

0 comments on commit c05ac82

Please sign in to comment.