Skip to content

Commit

Permalink
Nbr of papers in filters + UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrotsmnrd committed Aug 28, 2024
1 parent 5bb9155 commit 84704b0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
35 changes: 31 additions & 4 deletions web/dashboard/components/select_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class SelectPicker(ReactiveHTML, Widget):
)
value = param.List(doc="The actual list of selected values", default=[])

annotations = param.Dict(default={})

filter_str = param.String(default="")

trigger_rendering = param.Integer(default=0)
Expand Down Expand Up @@ -197,7 +199,7 @@ def filtered_options_did_change(self):
rgba(0, 0, 0, 0.12) 0px 3px 14px 2px;
position: absolute;
z-index: 1001;
width: 270px;
width: 300px;
top: 30%;
left: 15%;
}
Expand Down Expand Up @@ -271,6 +273,15 @@ def filtered_options_did_change(self):
overflow: hidden;
}
.sp_options_list_container label span.label {
width: 60%;
}
.sp_options_list_container label span.annotation {
width: 25%;
text-align:right;
}
.sp_filter_clear_btn {
padding-top: 4px;
padding-right: 4px;
Expand Down Expand Up @@ -364,16 +375,26 @@ def filtered_options_did_change(self):
""",
"input_change": """
/*console.log("input_change", data, model, state, view);
console.log(model.checkboxes_list);*/
/* console.log("input_change") , data, model, state, view);*/
console.log(model.checkboxes_list); */
let new_value = [];
let removed_values = [];
model.checkboxes_list.forEach((cb, idx) => {
if (cb.checked) {
new_value.push(cb.value);
} else if (!cb.checked && data.value.includes(cb.value)) {
removed_values.push(cb.value);
}
});
data.value = new_value;
if ( filter_text_input.value.length > 0) {
/* When a filter is applied ... */
data.value = data.value.concat(new_value).filter((v) => !removed_values.includes(v));
} else {
data.value = new_value;
}
setTimeout(function() {
Expand Down Expand Up @@ -446,10 +467,16 @@ def filtered_options_did_change(self):
lbl.htmlFor = `cb${idx}`;
let lblspan = document.createElement("span");
lblspan.classList.add("label");
lblspan.innerHTML = opt;
let lblannotation = document.createElement("span");
lblannotation.classList.add("annotation");
lblannotation.innerHTML = data.annotations[opt];
lbl.appendChild(cb);
lbl.appendChild(lblspan);
lbl.appendChild(lblannotation);
checkboxes_container.appendChild(lbl);
/* checkboxes_container.appendChild(document.createElement("br"));
Expand Down
27 changes: 10 additions & 17 deletions web/dashboard/main_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ def __init__(self, datasets, **params):

self.journal_select_picker = SelectPicker.from_param(
self.param.filter_journal,
annotations=self.get_col_values_with_count("journal"),
update_title_callback=lambda select_picker,
values,
options: self.new_picker_title("journals", select_picker, values, options),
)

self.affiliation_country_select_picker = SelectPicker.from_param(
self.param.filter_affiliation_country,
annotations=self.get_col_values_with_count("affiliation_country"),
update_title_callback=lambda select_picker,
values,
options: self.new_picker_title(
Expand All @@ -156,13 +158,15 @@ def __init__(self, datasets, **params):

self.funder_select_picker = SelectPicker.from_param(
self.param.filter_funder,
annotations=self.get_col_values_with_count("funder"),
update_title_callback=lambda select_picker,
values,
options: self.new_picker_title("funders", select_picker, values, options),
)

self.tags_select_picker = SelectPicker.from_param(
self.param.filter_tags,
annotations=self.get_col_values_with_count("data_tags"),
update_title_callback=lambda select_picker,
values,
options: self.new_picker_title("tags", select_picker, values, options),
Expand Down Expand Up @@ -229,9 +233,7 @@ def did_change_extraction_tool(self):
self.param.filter_journal.objects = self.raw_data.journal.unique()

## affiliation country
countries_with_count = self.get_col_values_with_count(
"affiliation_country", lambda x: "None" in x
)
countries_with_count = self.get_col_values_with_count("affiliation_country")

def country_sorter(c):
return countries_with_count[c]
Expand All @@ -241,9 +243,7 @@ def country_sorter(c):
)

## funder
funders_with_count = self.get_col_values_with_count(
"funder", lambda x: "None" in x
)
funders_with_count = self.get_col_values_with_count("funder")

def funder_sorter(c):
return funders_with_count[c]
Expand All @@ -253,9 +253,7 @@ def funder_sorter(c):
)

## Tags
tags_with_count = self.get_col_values_with_count(
"data_tags", lambda x: "None" in x
)
tags_with_count = self.get_col_values_with_count("data_tags")

def tags_sorter(c):
return tags_with_count[c]
Expand All @@ -269,7 +267,7 @@ def tags_sorter(c):
self.splitting_var = self.param.splitting_var.objects[0]

@lru_cache
def get_col_values_with_count(self, col, none_test):
def get_col_values_with_count(self, col, none_test=lambda row: "None" in row):
values = {}
for row in self.raw_data[col].values:
if none_test(row):
Expand Down Expand Up @@ -304,10 +302,7 @@ def did_change_splitting_var(self):

if splitting_var == "affiliation_country":
# We want to show all countries, but pre-select only the top 10
countries_with_count = self.get_col_values_with_count(
"affiliation_country",
lambda x: "None" in x,
)
countries_with_count = self.get_col_values_with_count("affiliation_country")

# pre-filter the countries because there are a lot
countries_with_count = {
Expand Down Expand Up @@ -336,9 +331,7 @@ def did_change_splitting_var(self):

if splitting_var == "funder":
# We want to show all funders, but pre-select only the top 10
funders_with_count = self.get_col_values_with_count(
"funder", lambda x: "None" in x
)
funders_with_count = self.get_col_values_with_count("funder")

top_5_min = sorted(
[
Expand Down
8 changes: 7 additions & 1 deletion web/dashboard/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ def css(selector: Union[str, Iterable[str]], declarations: dict[str, str]) -> st
},
)

CSS_GLOBAL = css("#header.shadow", {"box-shadow": "unset"})
CSS_GLOBAL = "\n".join(
[
css("#header.shadow", {"box-shadow": "unset"}),
css("#sidebar", {"overflow-y": "visible !important"}),
css("*", {"font-family": "'Roboto' !important"}),
]
)

"""
the structure of css_modifiers is as follows:
Expand Down

0 comments on commit 84704b0

Please sign in to comment.