# HG changeset patch # User Aurelien Campeas # Date 1316783109 -7200 # Node ID 7937cf60f2cef81415c57bb17bde1237abca915c # Parent 7be550fb337bb8f3ee9b9311485bd640da331928 [facets] fix height computation (incorporates and/or element if present, use css value to compute likely maximum height, kill wdg_stack_size) (closes #1954077) diff -r 7be550fb337b -r 7937cf60f2ce web/data/cubicweb.facets.css --- 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; } diff -r 7be550fb337b -r 7937cf60f2ce web/data/uiprops.py --- 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' + + diff -r 7be550fb337b -r 7937cf60f2ce web/facet.py --- 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) diff -r 7be550fb337b -r 7937cf60f2ce web/views/facets.py --- 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'\n') widget_queue = [] queue_height = 0 + wdg_stack_size = max(wdgs, key=lambda wdg:wdg.height()).height() w(u'\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