Skip to content

Commit

Permalink
Merge pull request #53 from nimh-dsst/dashboard
Browse files Browse the repository at this point in the history
Nbr of papers in filters + UI improvements
  • Loading branch information
leej3 authored Aug 28, 2024
2 parents 1d32ddf + 02283b3 commit 11368fb
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 23 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
38 changes: 20 additions & 18 deletions web/dashboard/main_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,18 @@ def __init__(self, datasets, **params):

self.journal_select_picker = SelectPicker.from_param(
self.param.filter_journal,
annotations={
row[0]: row[1]
for row in self.raw_data.journal.value_counts().reset_index().values
},
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 +161,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 @@ -226,12 +233,16 @@ def did_change_extraction_tool(self):
self.filter_pubdate = (self.raw_data.year.min(), self.raw_data.year.max())

## filter_journal
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
self.param.filter_journal.objects = (
self.raw_data.journal.value_counts().index.to_list()
)
# If we don't want to sort the journals by number of paper,
# but by alphabetical order, we can use this instead:
# self.param.filter_journal.objects = self.raw_data.journal.unique()

## affiliation country
countries_with_count = self.get_col_values_with_count("affiliation_country")

def country_sorter(c):
return countries_with_count[c]
Expand All @@ -241,9 +252,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 +262,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 +276,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 +311,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 +340,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 11368fb

Please sign in to comment.