From ab71bae08b650610bc675b708173eaddc6b4dced Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 11 Dec 2019 15:12:01 -0600 Subject: Added a parameter indicating how to align case attributes in the sample table on the trait page (so that numbers are aligned right) --- wqflask/wqflask/show_trait/SampleList.py | 12 ++++++++++++ wqflask/wqflask/templates/show_trait.html | 2 ++ 2 files changed, 14 insertions(+) diff --git a/wqflask/wqflask/show_trait/SampleList.py b/wqflask/wqflask/show_trait/SampleList.py index dc98eb2b..aa6ada5a 100644 --- a/wqflask/wqflask/show_trait/SampleList.py +++ b/wqflask/wqflask/show_trait/SampleList.py @@ -112,6 +112,18 @@ class SampleList(object): self.attributes[key].distinct_values = [item.Value for item in values] self.attributes[key].distinct_values.sort(key=natural_sort_key) + all_numbers = True + for value in self.attributes[key].distinct_values: + try: + val_as_float = float(value) + except: + all_numbers = False + + if all_numbers: + self.attributes[key].alignment = "right" + else: + self.attributes[key].alignment = "left" + def get_extra_attribute_values(self): if self.attributes: query = ''' diff --git a/wqflask/wqflask/templates/show_trait.html b/wqflask/wqflask/templates/show_trait.html index 0b4618f1..6719485a 100644 --- a/wqflask/wqflask/templates/show_trait.html +++ b/wqflask/wqflask/templates/show_trait.html @@ -260,6 +260,7 @@ {% if sample_groups[0].attributes|length > 0 %} {% for attribute in sample_groups[0].attributes|sort() %} $('td', row).eq(attribute_start_pos + {{ loop.index }}).addClass("column_name-{{ sample_groups[0].attributes[attribute].name }}") + $('td', row).eq(attribute_start_pos + {{ loop.index }}).attr("style", "text-align: {{ sample_groups[0].attributes[attribute].alignment }}; padding-top: 2px; padding-bottom: 0px;") {% endfor %} {% endif %} }, @@ -403,6 +404,7 @@ {% if sample_groups[1].attributes|length > 0 %} {% for attribute in sample_groups[1].attributes|sort() %} $('td', row).eq(attribute_start_pos + {{ loop.index }}).addClass("column_name-{{ sample_groups[1].attributes[attribute].name }}") + $('td', row).eq(attribute_start_pos + {{ loop.index }}).attr("style", "text-align: {{ sample_groups[1].attributes[attribute].alignment }}; padding-top: 2px; padding-bottom: 0px;") {% endfor %} {% endif %} }, -- cgit v1.2.3