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

[FIX] scatterplot: limit number of points displayed in tooltip #2980

Merged
merged 2 commits into from
Mar 30, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Orange/widgets/visualize/owscatterplotgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

SELECTION_WIDTH = 5
MAX = 11 # maximum number of colors or shapes (including Other)
MAX_POINTS_IN_TOOLTIP = 20


class PaletteItemSample(ItemSample):
"""A color strip to insert into legends for discretized continuous values"""
Expand Down Expand Up @@ -1227,8 +1229,16 @@ def point_data(p):

act_pos = self.scatterplot_item.mapFromScene(event.scenePos())
points = self.scatterplot_item.pointsAt(act_pos)

if len(points):
text = "<hr/>".join(point_data(point) for point in points)
if len(points) > MAX_POINTS_IN_TOOLTIP:
text = "{} instances<hr/>{}<hr/>...".format(
len(points),
"<hr/>".join(point_data(point) for point in points[:5])
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the difference between the constant MAX_POINTS_IN_TOOLTIP above and the hard-coded 5 here intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes. Displaying 20 points is ugly, but might be desired in some cases. When there are more, 5 are shown as a teaser. IMHO the tooltip looks much nicer this way :)

)
else:
text = "<hr/>".join(point_data(point) for point in points)

QToolTip.showText(event.screenPos(), text, widget=self.plot_widget)
return True
else:
Expand Down