Skip to content

Commit

Permalink
fix(point): Check for node.childNodes existance for IE / Edge
Browse files Browse the repository at this point in the history
Check if node.childNodes is defined before trying to access its length property
and use node append when node doesn't have innerHTML prop.

Fix #601
Close #602
  • Loading branch information
bogdan-iuga authored and netil committed Oct 18, 2018
1 parent 95db4c5 commit 59a5a05
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Expand Up @@ -18,3 +18,4 @@ Tony Quetano <tony.quetano@planttheidea.com>
EunChan Park <pec9399@naver.com>
Ina Ryu <ina.ryu@navercorp.com>
Lennert Claeys <lennert.claeys@coscale.com>
Bogdan Iuga <bogdan.iuga@yardi.com>

This comment has been minimized.

Copy link
@bogdan-iuga

bogdan-iuga Oct 18, 2018

Author Contributor

Hey @netil , thanks for adding me to the authors list, but my opinion is I didn't really earned that inclusion yet. My initial changes didn't make it in the final version, and I had some days off so I didn't really helped you out with the rest of the PR.
I'll try and contribute whenever I feel like I can help, but in the meantime, my name up there doesn't really reflect reality

This comment has been minimized.

Copy link
@netil

netil Oct 18, 2018

Member

@bogdan-iuga, well actually not applied as it was, but from the PR you gave an initial knowledge to considering this issue.
Hope to be an starting point to make another contribution from this!

44 changes: 25 additions & 19 deletions src/shape/point.js
Expand Up @@ -23,26 +23,35 @@ extend(ChartInternal.prototype, {

insertPointInfoDefs(point, id) {
const $$ = this;
const parser = new DOMParser();
const doc = parser.parseFromString(point, "image/svg+xml");
const node = doc.firstChild;
const clone = document.createElementNS(d3Namespaces.svg, node.nodeName.toLowerCase());
const attribs = node.attributes;
const copyAttr = (from, target) => {
const attribs = from.attributes;

for (let i = 0, name; (name = attribs[i]); i++) {
name = name.name;
clone.setAttribute(name, node.getAttribute(name));
}
for (let i = 0, name; (name = attribs[i]); i++) {
name = name.name;
target.setAttribute(name, from.getAttribute(name));
}
};

const doc = new DOMParser().parseFromString(point, "image/svg+xml");
const node = doc.documentElement;
const clone = document.createElementNS(d3Namespaces.svg, node.nodeName.toLowerCase());

clone.id = id;
clone.style.fill = "inherit";
clone.style.stroke = "inherit";

// when has child nodes
if (node.children.length) {
clone.innerHTML = toArray(node.children)
.map(v => v.outerHTML)
.join("");
copyAttr(node, clone);

if (node.childNodes && node.childNodes.length) {
const parent = d3Select(clone);

if ("innerHTML" in clone) {
parent.html(node.innerHTML);
} else {
toArray(node.childNodes).forEach(v => {
copyAttr(v, parent.append(v.tagName).node());
});
}
}

$$.defs.node().appendChild(clone);
Expand Down Expand Up @@ -109,11 +118,8 @@ extend(ChartInternal.prototype, {
const $$ = this;
const box = element.node().getBBox();

box.width /= 2;
box.height /= 2;

const xPosFn2 = d => xPosFn(d) - box.width;
const yPosFn2 = d => yPosFn(d) - box.height;
const xPosFn2 = d => xPosFn(d) - box.width / 2;
const yPosFn2 = d => yPosFn(d) - box.height / 2;
let mainCircles = element;

if (withTransition) {
Expand Down

0 comments on commit 59a5a05

Please sign in to comment.