| 124418 | } // Bind a scenegraph item to an SVG DOM element. |
| 124419 | // Create new SVG elements as needed. |
| 124420 | function bind(item, el, sibling, tag, svg) { |
| 124421 | let node = item._svg, doc; // create a new dom node if needed |
| 124422 | if (!node) { |
| 124423 | doc = el.ownerDocument; |
| 124424 | node = domCreate(doc, tag, svgns); |
| 124425 | item._svg = node; |
| 124426 | if (item.mark) { |
| 124427 | node.__data__ = item; |
| 124428 | node.__values__ = { |
| 124429 | fill: "default" |
| 124430 | }; // if group, create background, content, and foreground elements |
| 124431 | if (tag === "g") { |
| 124432 | const bg = domCreate(doc, "path", svgns); |
| 124433 | node.appendChild(bg); |
| 124434 | bg.__data__ = item; |
| 124435 | const cg = domCreate(doc, "g", svgns); |
| 124436 | node.appendChild(cg); |
| 124437 | cg.__data__ = item; |
| 124438 | const fg = domCreate(doc, "path", svgns); |
| 124439 | node.appendChild(fg); |
| 124440 | fg.__data__ = item; |
| 124441 | fg.__values__ = { |
| 124442 | fill: "default" |
| 124443 | }; |
| 124444 | } |
| 124445 | } |
| 124446 | } // (re-)insert if (a) not contained in SVG or (b) sibling order has changed |
| 124447 | if (node.ownerSVGElement !== svg || siblingCheck(node, sibling)) el.insertBefore(node, sibling ? sibling.nextSibling : el.firstChild); |
| 124448 | return node; |
| 124449 | } // check if two nodes are ordered siblings |
| 124450 | function siblingCheck(node, sibling) { |
| 124451 | return node.parentNode && node.parentNode.childNodes.length > 1 && node.previousSibling != sibling; // treat null/undefined the same |
| 124452 | } // -- Set attributes & styles on SVG elements --- |