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]Silhouette Plot: elide hover labels if labels are long #2278

Merged
merged 1 commit into from
May 26, 2017
Merged

[FIX]Silhouette Plot: elide hover labels if labels are long #2278

merged 1 commit into from
May 26, 2017

Conversation

jerneju
Copy link
Contributor

@jerneju jerneju commented May 5, 2017

Issue

Fixes #2162

Description of changes
Includes
  • Code changes
  • Tests
  • Documentation

@jerneju jerneju changed the title Silhouette Plot: elide hover labels if labels are log [WIP][FIX]Silhouette Plot: elide hover labels if labels are log May 5, 2017
@jerneju jerneju changed the title [WIP][FIX]Silhouette Plot: elide hover labels if labels are log [WIP][FIX]Silhouette Plot: elide hover labels if labels are long May 5, 2017
@codecov-io
Copy link

codecov-io commented May 5, 2017

Codecov Report

Merging #2278 into master will increase coverage by 0.05%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #2278      +/-   ##
==========================================
+ Coverage   73.27%   73.32%   +0.05%     
==========================================
  Files         317      317              
  Lines       55384    55382       -2     
==========================================
+ Hits        40581    40611      +30     
+ Misses      14803    14771      -32

@@ -507,7 +504,10 @@ def setRowNames(self, names):
item = layout.itemAt(i + 1, 3)

if grp.rownames is not None:
item.setItems(grp.rownames)
rownames = [rowname[0:12] + "..." if
Copy link
Contributor

Choose a reason for hiding this comment

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

Use ellipsis symbol instead:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@janezd janezd self-assigned this May 12, 2017
@janezd
Copy link
Contributor

janezd commented May 12, 2017

Is this still WIP?

@jerneju jerneju changed the title [WIP][FIX]Silhouette Plot: elide hover labels if labels are long [FIX]Silhouette Plot: elide hover labels if labels are long May 12, 2017
@@ -907,7 +907,7 @@ def event(self, event):
return super().event(event)

def sizeHint(self, which, constraint=QSizeF()):
spacing = max(self.__spacing * (self.count() - 1), 0)
spacing = max(self.__spacing * (self.count()), 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why extra parentheses?

Can self.__spacing * self.count() (legally) be negative? Why max then?

@@ -907,7 +907,7 @@ def event(self, event):
return super().event(event)

def sizeHint(self, which, constraint=QSizeF()):
spacing = max(self.__spacing * (self.count() - 1), 0)
spacing = max(self.__spacing * (self.count()), 0)
return QSizeF(300, self.__barsize * self.count() + spacing)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this (self.__barsize + self.__spacing) * self.count()?

@@ -507,7 +504,10 @@ def setRowNames(self, names):
item = layout.itemAt(i + 1, 3)

if grp.rownames is not None:
item.setItems(grp.rownames)
rownames = [rowname[0:12] + "…" if
Copy link
Contributor

Choose a reason for hiding this comment

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

rowname[:12] instead of rownames[0:12]

Copy link
Contributor

Choose a reason for hiding this comment

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

However, this is not the proper way to do it since it disregards the actual widths of characters. See if you can truncate the text with http://doc.qt.io/qt-4.8/qfontmetrics.html#elidedText instead. For this, you will have to decide for (instead of determining) the sensible maximal label width in advance.

rownames = [rowname[0:12] + "…" if
len(rowname) > 15 else rowname
for rowname in grp.rownames]
item.setItems(rownames)
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 put the untruncated (or less truncated) label in the tooltip?

@@ -1047,8 +1047,8 @@ def __naturalsh(self):
fm = QFontMetrics(self.font())
spacing = self.__spacing
N = len(self.__items)
width = max((fm.width(text) for text in self.__items),
default=0)
width = 1.5 * max((fm.width(text) for text in self.__items),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 1.5?

@@ -1111,8 +1111,10 @@ def remove(items, scene):
self.__textitems = []


def main(argv=sys.argv):
def main(argv=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd just skip the argument and always give an empty list to QApplication. Nobody calls this main except for this module itself.

@nikicc nikicc added the DH2017 label May 25, 2017
Copy link
Contributor

@janezd janezd left a comment

Choose a reason for hiding this comment

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

This is cool. Two really minor (potential) changes.

Plus, can you suggest a good data set to try this on?

@@ -494,6 +494,7 @@ def setScores(self, scores, labels, values, colors, rownames=None):
self.__setup()

def setRowNames(self, names):
ROW_NAMES_WIDTH = 200
Copy link
Contributor

Choose a reason for hiding this comment

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

Introducing a constant is OK since you explain what 200 is. But having it here is almost as if it just above the line where it's used. What about moving this constant to module- or class-level (https://www.python.org/dev/peps/pep-0008/#constants)?

Copy link
Contributor

Choose a reason for hiding this comment

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

So it's better to have code removed further away from where it's used, in this case in one single, particular place?

The ridicule is rhetorical.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are some widgets that have all their settings (like widths, various colors...) collected as constants at the top, which is convenient when you want to improve its design. Moving a single constant is the first step in this direction. :)

@@ -907,8 +911,8 @@ def event(self, event):
return super().event(event)

def sizeHint(self, which, constraint=QSizeF()):
spacing = max(self.__spacing * (self.count() - 1), 0)
return QSizeF(300, self.__barsize * self.count() + spacing)
spacing = max(self.__spacing, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why max(self.__spacing, 0)? Can self.__spacing be negative? I suspect this code was here because of (self.count() - 1).

@jerneju
Copy link
Contributor Author

jerneju commented May 26, 2017

@janezd
cyber-security-breaches.tab

@janezd janezd merged commit 77ed48b into biolab:master May 26, 2017
@jerneju jerneju deleted the gh-2162-silhouette-labels branch May 26, 2017 09:42
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.

5 participants