1334 else: |
1334 else: |
1335 self.select.add_relation(var, self.rtype, self.filtered_variable) |
1335 self.select.add_relation(var, self.rtype, self.filtered_variable) |
1336 |
1336 |
1337 |
1337 |
1338 ## html widets ################################################################ |
1338 ## html widets ################################################################ |
|
1339 _DEFAULT_CONSTANT_VOCAB_WIDGET_HEIGHT = 9 |
|
1340 |
|
1341 @cached |
|
1342 def _css_height_to_line_count(vreg): |
|
1343 cssprop = vreg.config.uiprops['facet_overflowedHeight'].lower().strip() |
|
1344 # let's talk a bit ... |
|
1345 # we try to deduce a number of displayed lines from a css property |
|
1346 # there is a linear (rough empiric coefficient == 0.73) relation between |
|
1347 # css _em_ value and line qty |
|
1348 # if we get another unit we're out of luck and resort to one constant |
|
1349 # hence, it is strongly advised not to specify but ems for this css prop |
|
1350 if cssprop.endswith('em'): |
|
1351 try: |
|
1352 return int(cssprop[:-2]) * .73 |
|
1353 except Exception: |
|
1354 vreg.warning('css property facet_overflowedHeight looks malformed (%r)', |
|
1355 cssprop) |
|
1356 return _DEFAULT_CONSTANT_VOCAB_WIDGET_HEIGHT |
1339 |
1357 |
1340 class FacetVocabularyWidget(htmlwidgets.HTMLWidget): |
1358 class FacetVocabularyWidget(htmlwidgets.HTMLWidget): |
1341 |
1359 |
1342 def __init__(self, facet): |
1360 def __init__(self, facet): |
1343 self.facet = facet |
1361 self.facet = facet |
1344 self.items = [] |
1362 self.items = [] |
1345 |
1363 |
|
1364 @cached |
1346 def height(self): |
1365 def height(self): |
1347 return len(self.items) + 1 |
1366 maxheight = _css_height_to_line_count(self.facet._cw.vreg) |
|
1367 return 1 + min(len(self.items), maxheight) + int(self.facet._support_and_compat()) |
1348 |
1368 |
1349 def append(self, item): |
1369 def append(self, item): |
1350 self.items.append(item) |
1370 self.items.append(item) |
1351 |
1371 |
1352 def _render(self): |
1372 def _render(self): |