[facets] fix height computation (incorporates and/or element if present, use css value to compute likely maximum height, kill wdg_stack_size) (closes #1954077) stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Fri, 23 Sep 2011 15:05:09 +0200
branchstable
changeset 7849 7937cf60f2ce
parent 7847 7be550fb337b
child 7850 d14b77c42b06
[facets] fix height computation (incorporates and/or element if present, use css value to compute likely maximum height, kill wdg_stack_size) (closes #1954077)
web/data/cubicweb.facets.css
web/data/uiprops.py
web/facet.py
web/views/facets.py
--- a/web/data/cubicweb.facets.css	Fri Sep 23 14:56:13 2011 +0200
+++ b/web/data/cubicweb.facets.css	Fri Sep 23 15:05:09 2011 +0200
@@ -15,7 +15,7 @@
  color: #000;
  margin-bottom: 2px;
  cursor: pointer;
- font: bold 100% Georgia;
+ font: %(facet_titleFont)s;
 }
 
 div.facetTitle a {
@@ -30,8 +30,8 @@
  color: #000 !important;
 }
 
-div.overflowed{
-  height: 12em;
+div.overflowed {
+  height: %(facet_overflowedHeight)s;
   overflow-y: auto;
 }
 
--- a/web/data/uiprops.py	Fri Sep 23 14:56:13 2011 +0200
+++ b/web/data/uiprops.py	Fri Sep 23 15:05:09 2011 +0200
@@ -165,3 +165,9 @@
 infoMsgBgImg = 'url("information.png") 5px center no-repeat'
 errorMsgBgImg = 'url("error.png") 100% 50% no-repeat'
 errorMsgColor = '#ed0d0d'
+
+# facets
+facet_titleFont = 'bold 100% Georgia'
+facet_overflowedHeight = '12em'
+
+
--- a/web/facet.py	Fri Sep 23 14:56:13 2011 +0200
+++ b/web/facet.py	Fri Sep 23 15:05:09 2011 +0200
@@ -1336,6 +1336,24 @@
 
 
 ## html widets ################################################################
+_DEFAULT_CONSTANT_VOCAB_WIDGET_HEIGHT = 9
+
+@cached
+def _css_height_to_line_count(vreg):
+    cssprop = vreg.config.uiprops['facet_overflowedHeight'].lower().strip()
+    # let's talk a bit ...
+    # we try to deduce a number of displayed lines from a css property
+    # there is a linear (rough empiric coefficient == 0.73) relation between
+    # css _em_ value and line qty
+    # if we get another unit we're out of luck and resort to one constant
+    # hence, it is strongly advised not to specify but ems for this css prop
+    if cssprop.endswith('em'):
+        try:
+            return int(cssprop[:-2]) * .73
+        except Exception:
+            vreg.warning('css property facet_overflowedHeight looks malformed (%r)',
+                         cssprop)
+    return _DEFAULT_CONSTANT_VOCAB_WIDGET_HEIGHT
 
 class FacetVocabularyWidget(htmlwidgets.HTMLWidget):
 
@@ -1343,8 +1361,10 @@
         self.facet = facet
         self.items = []
 
+    @cached
     def height(self):
-        return len(self.items) + 1
+        maxheight = _css_height_to_line_count(self.facet._cw.vreg)
+        return 1 + min(len(self.items), maxheight) + int(self.facet._support_and_compat())
 
     def append(self, item):
         self.items.append(item)
--- a/web/views/facets.py	Fri Sep 23 14:56:13 2011 +0200
+++ b/web/views/facets.py	Fri Sep 23 15:05:09 2011 +0200
@@ -206,7 +206,6 @@
 class FilterTable(FacetFilterMixIn, AnyRsetView):
     __regid__ = 'facet.filtertable'
     __select__ = has_facets()
-    wdg_stack_size = 8
     compact_layout_threshold = 5
 
     def call(self, vid, divid, vidargs, cssclass=''):
@@ -235,10 +234,11 @@
         w(u'<table class="filter">\n')
         widget_queue = []
         queue_height = 0
+        wdg_stack_size = max(wdgs, key=lambda wdg:wdg.height()).height()
         w(u'<tr>\n')
         for wdg in wdgs:
             height = wdg.height()
-            if queue_height + height <= self.wdg_stack_size:
+            if queue_height + height <= wdg_stack_size:
                 widget_queue.append(wdg)
                 queue_height += height
                 continue