-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fixed bug in hover data #2544
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
fixed bug in hover data #2544
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -116,6 +116,18 @@ def get_label(args, column): | |||||||
return column | ||||||||
|
||||||||
|
||||||||
def invert_label(args, column): | ||||||||
"""Invert mapping. | ||||||||
Find key corresponding to value column in dict args["labels"]. | ||||||||
Returns `column` if the value does not exist. | ||||||||
""" | ||||||||
reversed_labels = {value: key for (key, value) in args["labels"].items()} | ||||||||
try: | ||||||||
return reversed_labels[column] | ||||||||
except Exception: | ||||||||
return column | ||||||||
|
||||||||
|
||||||||
def _is_continuous(df, col_name): | ||||||||
return df[col_name].dtype.kind in "ifc" | ||||||||
|
||||||||
|
@@ -434,11 +446,13 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref): | |||||||
mapping_labels_copy = OrderedDict(mapping_labels) | ||||||||
if args["hover_data"] and isinstance(args["hover_data"], dict): | ||||||||
for k, v in mapping_labels.items(): | ||||||||
if k in args["hover_data"]: | ||||||||
if args["hover_data"][k][0]: | ||||||||
if isinstance(args["hover_data"][k][0], str): | ||||||||
# We need to invert the mapping here | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
k_args = invert_label(args, k) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK so the problem is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might want to add a comment here explaining... it took me 4 tries and 10min to figure this one out :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok :-). Yes, that's what you said. |
||||||||
if k_args in args["hover_data"]: | ||||||||
if args["hover_data"][k_args][0]: | ||||||||
if isinstance(args["hover_data"][k_args][0], str): | ||||||||
mapping_labels_copy[k] = v.replace( | ||||||||
"}", "%s}" % args["hover_data"][k][0] | ||||||||
"}", "%s}" % args["hover_data"][k_args][0] | ||||||||
) | ||||||||
else: | ||||||||
_ = mapping_labels_copy.pop(k) | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works because the default for
args["labels"]
is set to{}
but probably we should useNone
instead, what do you think @nicolaskruchten ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we should stop using
{}
as defaults :)Here btw there's a potential issue if people use the same label for two things... this is a bad idea for a user to do but... ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created #2562 to talk about this issue since it already exists before this PR.