vijithassar / d3-textwrap

painless cross-browser line wrapping for text passages in SVG projects built with D3.js
MIT License
154 stars 21 forks source link

cast fix #13

Closed nkint closed 4 years ago

nkint commented 8 years ago

Patch to fix this issue:

12

Due to json limitation I can't write a proper test.

jneuendorf commented 6 years ago

@nkint You probably meant jsdom (as in the issue), right? @vijithassar Please merge this PR. There's really no reason not to 😉

jneuendorf commented 6 years ago

Some minor optimizations could be:

// no padding -> leave attributes unchanged
if (padding > 0) {
    var cx = parseInt(text.attr('x'), 10) || 0;
    var cy = parseInt(text.attr('y'), 10) || 0;
    text
        .attr('y', cy + padding)
        .attr('x', cx + padding);
}

That should save unnecessary DOM manipulations and improve the performance of parseInt.