d3plus / d3plus-text

A smart SVG text box with line wrapping and automatic font size scaling.
MIT License
105 stars 19 forks source link

advanced overflow options #1

Open Hypercubed opened 8 years ago

Hypercubed commented 8 years ago

Thank you for making this a standalone module. It took me some time to figure out the new API so perhaps I am missing something.

What I am seeing is that if a word is too long for the bounding box it is omitted completely. I believe this is happening here: https://github.com/d3plus/d3plus-text/blob/master/src/box.js#L189 . If I comment out this line the labels that are too long for the bounding box overflow. Not sure if this is by design, perhaps it should be an option at least.

I'm using the module like this:

      const box = d3plusText.box()
        .textAnchor('middle')
        .fontSize(14)
        .width(d => d.values.length * boxWidth + 5)
        .text(d => d.key.replace(/_/g, ' '))
        .height(45);

      subplot.append('g')
        .attr('class', 'boxLabelText')
        .attr('transform', 'translate(-5,0)')
        .each(function (d) {
          box
            .data([d])
            .select(this)();
        });
davelandry commented 8 years ago

That was the intended behavior. I've always just enabled the fontResize and this took care of shrinking the text to fit.

That being said, I have no problem adding in a "overflow" boolean.

Hypercubed commented 8 years ago

I was going to do a PR but see it is already done. Have you considered instead of just a boolean, add a few options like 'clip', 'resize', 'hidden', 'overflow'?

davelandry commented 8 years ago

hmm interesting, can you describe the difference between "clip" and "hidden", and how "resize" differs from the fontResize method?

definitely wouldn't mind you taking a crack at it if you feel comfortable

Hypercubed commented 8 years ago

My idea was the following:

'hidden' - hide the entire text that overflows, this is the current default. I guess this name can be easily confused with clip.

'visible' - just show it.

'clip' - draw a binding box (defined a clip path?) and hide the overflow.

'resize' - force resize when text overflows. I realized later this is the same as setting fontMin === font Size.