Skip to content
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

Annotation size & text alignment #1551

Merged
merged 8 commits into from
Apr 6, 2017
Merged

Annotation size & text alignment #1551

merged 8 commits into from
Apr 6, 2017

Conversation

alexcjohnson
Copy link
Collaborator

Explicit width and height for annotations, along with vertical alignment to complement the existing (horizontal) alignment.

@etpinard a couple of decisions could use 👍 /👎 :

  • The attribute name valign, and its default value of 'middle' - we already have default align: 'center', so now if you make a giant annotation the text will end up in the center (as in the bottom left annotation I added to https://github.com/plotly/plotly.js/compare/note-sizing?expand=1#diff-038299cfa4b6b29a6fad48dc78a8c1d0)
  • Text is clipped such that the borderpad region is always blank - see the bottom center annotation added in that same baseline image. You could argue for allowing it all the way to the border, but to me it looks better this way, and I think this overrides letting the user see another half a letter or whatever. It has a quirk though, that even if I'm clipping the text in principle exactly to its own bounding box, sometimes you lose a tiny bit. I mostly fixed this problem by not clipping at all if you don't set an explicit width or height (when clipping shouldn't do anything anyway) but it might still pop up on the in-principle-not-clipped sides of clipped text. I suppose there could be a solution to this involving stretching the clip rectangle on the non-clipped sides, based on whether width and/or height are set and the values of align and valign but to me that sounds more complicated than it's worth. You can see what I'm talking about if you look at my intermediate commit efe8345 - the "j"s in justified and the "y" in y-int lost a tiny bit of the left and bottom respectively of their tails.

width: {
valType: 'number',
min: 0,
dflt: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously the default value isn't 0, it's computed from the input text. I believe in plotly.js lingo that means the dflt value should be set to null (similar to e.g. contours.start and xbins.start)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call -> e01a765

},
valign: {
valType: 'enumerated',
values: ['top', 'middle', 'bottom'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it 👍

.classed('annclip', true)
.attr('id', annClipID)
.append('rect');
annTextClip.exit().remove();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a jasmine test, checking that the clip paths are removed when removing an annotation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact they're not removed - they don't proliferate, ie if you repeatedly make 100 annotations and delete them, you'll never get more than 100 clip paths, but I didn't bother deleting clip paths corresponding to annotations past the end of the new array after removing some. I can revisit that though...

Copy link
Contributor

@etpinard etpinard Apr 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha I see. We can revisit this when we shift to a more d3-idiomatic pattern in annotation draw. Then, we could easily remove those <clipPath> inside the exit() selection similar to how updatemenu buttons are removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually was easy to remove the unneeded clip paths after all -> b21154b

@etpinard
Copy link
Contributor

etpinard commented Apr 5, 2017

Text is clipped such that the borderpad region is always blank - see the bottom center annotation added in that same baseline image. You could argue for allowing it all the way to the border, but to me it looks better this way, and I think this overrides letting the user see another half a letter or whatever. It has a quirk though, that even if I'm clipping the text in principle exactly to its own bounding box, sometimes you lose a tiny bit.

Hmm. I guess what we really need is some auto-textwrapping routine. I can expect some users not liking having to add <br> to their annotations text fields to see them in full.

coerce('width');
coerce('height');
coerce('align');
coerce('valign');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't need to coerce valign is height isn't set?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 -> 2e132bd

@alexcjohnson
Copy link
Collaborator Author

Hmm. I guess what we really need is some auto-textwrapping routine.

At some point that'd be a nice feature, but not now, it's going to be annoying. For now I just put a note about this in the description of width:
There is no automatic wrapping; use <br> to start a new line.

@etpinard
Copy link
Contributor

etpinard commented Apr 6, 2017

There is no automatic wrapping; use
to start a new line.

Nice. Good enough for now!

if(!optionsIn || options.visible === false) return;
if(!optionsIn || options.visible === false) {
d3.selectAll('#' + annClipID).remove();
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easy.

@etpinard
Copy link
Contributor

etpinard commented Apr 6, 2017

Nicely done 💃

This will be part of 1.26.0 (thanks to my nw.js upgrade nightmare 😡 )

@etpinard etpinard added this to the v1.26.0 milestone Apr 6, 2017
@alexcjohnson alexcjohnson merged commit b4318ad into master Apr 6, 2017
@alexcjohnson alexcjohnson deleted the note-sizing branch April 6, 2017 15:27
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

Successfully merging this pull request may close these issues.

2 participants