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

Hover label namelength #1822

Merged
merged 6 commits into from
Jul 19, 2017
Merged

Conversation

ckiss
Copy link
Contributor

@ckiss ckiss commented Jun 27, 2017

resolves #1777

@ckiss ckiss changed the title Hover label namelength [WIP]Hover label namelength Jun 27, 2017
@ckiss ckiss changed the title [WIP]Hover label namelength Hover label namelength Jun 27, 2017
@ckiss
Copy link
Contributor Author

ckiss commented Jun 27, 2017

@etpinard as I said I'll do, I opened a new PR, with fixed tests. Let me know what you think. I still have some concerns that I might need to do some updates to the documentation or something. Not sure how that goes here :)

valType: 'number',
min: 0,
dflt: 15,
role: 'style',
Copy link
Contributor

Choose a reason for hiding this comment

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

We should try adding arrayOk support here, so that

trace = {
  x: [1, 2, 3],
  y: [2, 1, 2],
  namelength: [15, 10, 40]
}

would work.

Copy link
Contributor

Choose a reason for hiding this comment

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

see #1761 for an example on how to proceed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should try adding arrayOk support here

good call - at first I was worried that this would just be confusing to look at ("I thought this was the same trace, why does it have a different name?") but it could actually come in handy for example if you vary the hover label font size, a bigger one may need more truncation of the name 👍

@@ -689,7 +689,7 @@ function createHoverText(hoverData, opts, gd) {
// strip out our pseudo-html elements from d.name (if it exists at all)
name = svgTextUtils.plainText(d.name || '');

if(name.length > 15) name = name.substr(0, 12) + '...';
if(name.length > commonLabelOpts.namelength && commonLabelOpts.namelength > 0) name = name.substr(0, commonLabelOpts.namelength - 3) + '...';
Copy link
Contributor

@etpinard etpinard Jun 27, 2017

Choose a reason for hiding this comment

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

Does this take care of namelength = 0 case which should hide the name text node completely?

Copy link
Contributor

Choose a reason for hiding this comment

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

++ can you rewrite this as

if(/* */) {

}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etpinard my understanding from this comment is that when namelength = 0 there should be no trimming happening, instead display the whole text... Am I wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

Too bad the JS token Infinity isn't JSON serializable. I'm ok with making namelength: 0 means no truncation, even though it feels contradictory to me.

Perhaps we should instead add support for an Infinity-like value in valType: 'number' attributes. For example, we could make namelength: null correspond to namelength === Infinity. Though, I can't think of any other attributes that could benefit from it, so I'm not sure it's worth the time.

cc @alexcjohnson

Copy link
Contributor

Choose a reason for hiding this comment

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

namelength: -1? In the style of indexOf, that says "does not apply" to me. Sort of.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rreusser solid suggestion, I like it 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

-1 sounds good for "no truncation." I'm not sure why someone would want to use namelength=0 to completely hide the name, rather than using hoverinfo but I bet someone will come up with a clever reason for it!

@etpinard
Copy link
Contributor

@ckiss are you planning on addressing the comments above?

I might have time to wrap this one up on Monday.

@ckiss
Copy link
Contributor Author

ckiss commented Jul 14, 2017

@etpinard I'll address them Monday morning! Have a great weekend and sorry for the delay!

- -1 for no constraint
- more complete description
- complete arrayOk support
- tests
@etpinard etpinard added this to the 1.29.0 milestone Jul 19, 2017
@alexcjohnson
Copy link
Collaborator

@ckiss I hope you don't mind, I took the liberty of finishing this up so we can get it in the next minor release. I switched to -1 for "no truncation", fleshed out the arrayOk support, and added a test of all these behaviors. Also, I realized that lengths 1-3 would have been meaningless as we had them, as it would be only ellipsis, so for those short lengths I omit the ellipsis and just show the leading characters. Sound reasonable?

@etpinard any comments?

@etpinard
Copy link
Contributor

etpinard commented Jul 19, 2017

@etpinard any comments?

94f660a looks good 👍 . You'll need to add 'arrayOk' to this list to get the plot-schema tests to pass.

@alexcjohnson
Copy link
Collaborator

You'll need to add 'arrayOk' to this list to get the plot-schema tests to pass.

hah, first place we have an integer array, really? 😎 e937519

@etpinard
Copy link
Contributor

💃

valType: 'number',
min: 0,
valType: 'integer',
min: -1,
dflt: 15,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

don't you need to remove dflt here too?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I kept only the global default, because the trace-level default inherits from the global so doesn't use a default of its own.

You're right that we want a default - in fact, we need a default of 15 to preserve backward compatibility - this is just how that default gets propagated.

@ckiss
Copy link
Contributor Author

ckiss commented Jul 19, 2017

@alexcjohnson @etpinard sorry I didn't had time to complete this :( I was back from holidays monday and had lots on my plate... thanks for your help @alexcjohnson. I added a comment to your commit. Otherwise I'm happy, although where this was initially discussed a default value was mentioned.

@alexcjohnson alexcjohnson merged commit bc5726c into plotly:master Jul 19, 2017
@ckiss
Copy link
Contributor Author

ckiss commented Jul 19, 2017

cool, thanks!

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

Successfully merging this pull request may close these issues.

Allow to choose whether to trim trace names in hover info
4 participants