Skip to content

Fixed-width hover labels with hoverlabel.width #3800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
seaders opened this issue Apr 23, 2019 · 3 comments
Closed

Fixed-width hover labels with hoverlabel.width #3800

seaders opened this issue Apr 23, 2019 · 3 comments
Labels
feature something new

Comments

@seaders
Copy link

seaders commented Apr 23, 2019

So I've set up my graph to have a fixed width for hover labels, and it was a real PITA to get to this now,

Screen Shot 2019-04-23 at 03 03 40

Screen Shot 2019-04-23 at 03 03 47

I'm using the angular library, but basically, I set a manual tbbwidth in createHoverText, changing

    var tbb = tx.node().getBoundingClientRect();
    var htx = d.xa._offset + (d.x0 + d.x1) / 2;
    var hty = d.ya._offset + (d.y0 + d.y1) / 2;
    var dx = Math.abs(d.x1 - d.x0);
    var dy = Math.abs(d.y1 - d.y0);
    var txTotalWidth = tbb.width + HOVERARROWSIZE + HOVERTEXTPAD + tx2width;
    var anchorStartOK, anchorEndOK;

    d.ty0 = outerTop - tbb.top;
    d.bx = tbb.width + 2 * HOVERTEXTPAD;
    d.by = Math.max(tbb.height + 2 * HOVERTEXTPAD, tx2height);
    d.anchor = 'start';
    d.txwidth = tbb.width;
    d.tx2width = tx2width;
    d.offset = 0;

To,

    var tbb = tx.node().getBoundingClientRect();
    var htx = d.xa._offset + (d.x0 + d.x1) / 2;
    var hty = d.ya._offset + (d.y0 + d.y1) / 2;
    var dx = Math.abs(d.x1 - d.x0);
    var dy = Math.abs(d.y1 - d.y0);
    var tbbwidth = 385;
    var txTotalWidth = tbbwidth + HOVERARROWSIZE + HOVERTEXTPAD + tx2width;
    var anchorStartOK, anchorEndOK;

    d.tbbwidth = tbb.width;
    d.ty0 = outerTop - tbb.top;
    d.bx = tbbwidth + 2 * HOVERTEXTPAD;
    d.by = Math.max(tbb.height + 2 * HOVERTEXTPAD, tx2height);
    d.anchor = 'start';
    d.txwidth = tbbwidth;
    d.tx2width = tx2width;
    d.offset = 0;

And in alignHoverText (my local version is 1.45.3),

    tx.call(svgTextUtils.positionText,
        txx + offsetX, offsetY + d.ty0 - d.by / 2 + HOVERTEXTPAD);

To,

    tx.call(svgTextUtils.positionText,
        (txx < 0 ? -(d.bx - d.tbbwidth) : txx) + offsetX, 
        offsetY + d.ty0 - d.by / 2 + HOVERTEXTPAD);

I'd love to have this feature myself for graphs like this, and more - and would really appreciate some advice as to what would be the best method to submit a PR.

@etpinard
Copy link
Contributor

What you're describing appears similar to the width annotation attribute:

width: {
valType: 'number',
min: 1,
dflt: null,
role: 'style',
editType: 'calc+arraydraw',
description: [
'Sets an explicit width for the text box. null (default) lets the',
'text set the box width. Wider text will be clipped.',
'There is no automatic wrapping; use <br> to start a new line.'
].join(' ')
},

So, adding a new attribute hoverlabel.width (with values in pixels) sounds like a nice addition to the library.

About making a PR (thanks!), I suggest you first read our PR guidelines. Looking at past PRs adding similar features (e.g. #3753) should help also.


cc #2342

@etpinard etpinard added the feature something new label Apr 24, 2019
@etpinard etpinard changed the title Best way to set a fixed width to a hover label, via set options? Fixed-width hover labels with hoverlabel.width Apr 24, 2019
@pdfabbro
Copy link

Did width get implemented? Doesn't seem to be working

@gvwilson
Copy link
Contributor

Hi - we are currently trying to tidy up Plotly's public repositories to help us focus our efforts on things that will help users most. Since this issue has been sitting for several years, I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our backlog. Thanks for your help - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

No branches or pull requests

4 participants