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 format or skip #2377

Merged
merged 23 commits into from
Apr 21, 2020
Merged

Hover format or skip #2377

merged 23 commits into from
Apr 21, 2020

Conversation

emmanuelle
Copy link
Contributor

Closes #1774

Still need to add doc (and probably more tests), but early feedback is welcome.

@emmanuelle
Copy link
Contributor Author

I'm a bit surprised by the test failure on python 2.7 (why would a hovertemplate be different with python 2.7 and python 3?)

@nicolaskruchten
Copy link
Contributor

The Python 2.7 error is just an ordering problem due to dict order (in)stability...

image

@emmanuelle
Copy link
Contributor Author

ahhh thank you :-). I'll change the test then. Python 3 users won't have the problem since dicts are insertion-ordered, and py2 users can always use an OrderedDict instead.

@nicolaskruchten
Copy link
Contributor

So this approach looks pretty good. I don't love the string manipulations, although they seem pretty safe!

One wrinkle: we support two different kinds of formatting... d3-format for numbers and d3-time-format for dates, and the delimiter between the attribute name and the formatting string is different (: vs |) ... how can we account for this? I think we should force the user to include the first character, at least in the d3-time-format case.

@nicolaskruchten
Copy link
Contributor

Example for date axes:

image

@emmanuelle
Copy link
Contributor Author

Sure, let's add the delimiter. As for string manipulations, maybe there's a cleaner way to do it, this was a first pass to see if it worked.

@emmanuelle emmanuelle changed the title [WIP] Hover format or skip Hover format or skip Apr 16, 2020
@emmanuelle
Copy link
Contributor Author

@nicolaskruchten I think this one is ready for review.

@nicolaskruchten
Copy link
Contributor

Can we also accept something like hover_data = dict(new_col=[1,2,3,4,5]), to be treated the same as hover_data=dict(new_col=(True, [1,2,3,4,5])) ?

@emmanuelle
Copy link
Contributor Author

Can we also accept something like hover_data = dict(new_col=[1,2,3,4,5]), to be treated the same as hover_data=dict(new_col=(True, [1,2,3,4,5])) ?

I could maybe be convinced, but I liked the idea that the value is a formatting information, except when it's a tuple, in which case it's (formatting, data). It's also the logics which I have used in the code, converting everything to tuples internally.

@nicolaskruchten
Copy link
Contributor

nicolaskruchten commented Apr 17, 2020

Right, but I feel like if we've already got a dict here (and we're already doing label manipulation), we might as well give the user a shortcut to hover_data=[ <list> ], labels=dict(hover_data_0="name") in the form of hover_data={"name": <list> }. We can internally convert <list> to (True, <list>) for them.

@nicolaskruchten
Copy link
Contributor

Not quite done the review, but it looks great so far! We need to merge this in before #2336, as I think I'll have an easier time rebasing :)

@nicolaskruchten
Copy link
Contributor

Huh, it took me a while to understand how the dataframe loop was working, and then I realized that this happens:

image

@nicolaskruchten
Copy link
Contributor

So when we iterate through an "array attrable" and it's a dict, it sort of "just works" :) nice!

short-circuit instead of bypass flag
@emmanuelle
Copy link
Contributor Author

So when we iterate through an "array attrable" and it's a dict, it sort of "just works" :) nice!

Yes when you iterate through a dict it iterates through its keys. Simple and elegant ;-).

@nicolaskruchten
Copy link
Contributor

OK, this is awesome :)

💃

@emmanuelle
Copy link
Contributor Author

Thanks for the 💃 let me just add the changelog entry and I'll merge.

@emmanuelle emmanuelle merged commit 5b0e8d3 into master Apr 21, 2020
@emmanuelle emmanuelle deleted the hover-format-or-skip branch April 25, 2020 08:39
@nicolaskruchten nicolaskruchten added this to the 4.7.0 milestone Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatting and hiding hover_data in PX
2 participants