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

Implement (x|y)other hovertemplate to format differing positions in compare and unified modes #5690

Merged
merged 7 commits into from
Jun 1, 2021

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented May 28, 2021

Resolves #5555.

TODOs:

  • add tests

@plotly/plotly_js

@archmoj archmoj added this to the NEXT milestone May 28, 2021
@archmoj
Copy link
Contributor Author

archmoj commented May 29, 2021

How about renaming the key to other(x|y) or even simply other?

@nicolaskruchten
Copy link
Contributor

I like (x|y)other... what's the impetus for the rename?

One challenge I see with such a conditionally-displaying item is the spacing around it... It's OK if I put this at the end of a hovertemplate like %{y} %{xother} because most of the time the trailing space won't be visible, but I can't as easily put it at the beginning necessarily as then the leading space will be visible: %{xother} %{y}... Can we imagine some formatting directives like %{xother:<something>} the way we do number-formatting?

@archmoj
Copy link
Contributor Author

archmoj commented May 31, 2021

I like (x|y)other... what's the impetus for the rename?

We basically don't use xother and yother at the same time.
So I thought there might be a potential to simplify the name.

@nicolaskruchten
Copy link
Contributor

ah I see. I still think it's helpful to reason about and eventually find if it contains the letter :)

@archmoj
Copy link
Contributor Author

archmoj commented May 31, 2021

One challenge I see with such a conditionally-displaying item is the spacing around it... It's OK if I put this at the end of a hovertemplate like %{y} %{xother} because most of the time the trailing space won't be visible, but I can't as easily put it at the beginning necessarily as then the leading space will be visible: %{xother} %{y}... Can we imagine some formatting directives like %{xother:<something>} the way we do number-formatting?

The undesirable extra spacing won't be added after ad2ad74.

@nicolaskruchten
Copy link
Contributor

Yeah... but now you can't not-have the spacing around it if you don't want it, like if you want to have it at the beginning you'll always have a leading space when it's present.

I have a slight preference for the way it was before, I was just trying to think of a way to do even better :)

src/lib/index.js Outdated
}

if(isOther) {
value = ' (' + value + ') ';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line reminds me of ¯\_(ツ)_/¯

@archmoj
Copy link
Contributor Author

archmoj commented May 31, 2021

Yeah... but now you can't not-have the spacing around it if you don't want it, like if you want to have it at the beginning you'll always have a leading space when it's present.

I have a slight preference for the way it was before, I was just trying to think of a way to do even better :)

OK. Now with the underscore variants added in f8c8451, one could achieve desirable behaviour depending on the context.

@nicolaskruchten
Copy link
Contributor

Clever! I like it :)

it('should format differing position using *xother* `hovertemplate` and in respect to `xhoverformat`', function(done) {
Plotly.newPlot(gd, [{
type: 'bar',
hovertemplate: '%{y}%{_xother:.2f}',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
hovertemplate: '%{y}%{_xother:.2f}',
hovertemplate: 'y(_x):%{y}%{_xother:.2f}',

Just to make it easier to read the test output - likewise I'd suggest including the underscores in traces 3 and 4

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

💃 Clever indeed, I like it. Just one description comment and a thought about making the tests easier to read, then this is good to go!

@archmoj archmoj merged commit 18e512c into master Jun 1, 2021
@archmoj archmoj deleted the other-hovertemplate branch June 1, 2021 16:03
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.

Hovertemplate display of X value of points in hoverset that differ from that of the winning point
3 participants