Skip to content

Commit

Permalink
multicol fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
interrogator committed Mar 21, 2020
1 parent 5f6bda6 commit 8a200c1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
20 changes: 10 additions & 10 deletions explorer/parts/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
buzzword explorer: callbacks
"""

import dash
import pandas as pd
from buzz.exceptions import DataTypeError
from dash import no_update
Expand Down Expand Up @@ -34,7 +33,7 @@ def _correct_placeholder(value, **kwargs):
mapped = {
"t": "Enter Tgrep2 query...",
"d": "Enter depgrep query",
"describe": 'Enter depgrep query (e.g. l"man")',
"describe": 'Enter depgrep query (e.g. l"man" = f"nsubj")',
}
disable_gram = value in mapped
return mapped.get(value, default), disable_gram
Expand Down Expand Up @@ -242,9 +241,10 @@ def _new_search(
if cleared and cleared != session_clicks_clear:
session_search.clear()
corpus = CORPORA[slug]
corpus_size = len(corpus)
corpus = corpus.iloc[:max_row, :max_col]
cols, data = _update_conll(corpus, False, drop_govs=add_governor)
name = _make_search_name(conf["corpus_name"], len(corpus), session_search)
name = _make_search_name(conf["corpus_name"], corpus_size, session_search)
search_from = [dict(value=0, label=name)]
# set number of clicks at last moment
session_clicks_clear = cleared
Expand Down Expand Up @@ -303,7 +303,7 @@ def _new_search(
name = _make_search_name(this_search, len(corpus), session_search)
new_option = dict(value=new_value, label=name)
index_for_option = next(i for i, s in enumerate(search_from_options) if s["value"] == search_from)
search_from_options.insert(index_for_option+1, new_option)
search_from_options.insert(index_for_option + 1, new_option)
elif exists:
new_value = exists[-3]
else:
Expand Down Expand Up @@ -568,11 +568,11 @@ def _matching_not_matching(on, **kwargs):


@app.expanded_callback(
[Output("multiindex-text", "children"), Output("multiindex-switch", "disabled")],
[Input("multiindex-switch", "on"), Input("show-for-table", "value")],
[Output("multiindex-switch", "disabled"), Output("multiindex-switch", "on")],
[Input("multiindex-switch", "n_clicks"), Input("show-for-table", "value")],
[State("multiindex-switch", "on")]
)
def _multiindex(on, show, **kwargs):
def _multiindex(_, show, on, **kwargs):
if not show or len(show) < 2:
return "", True
text = "Join columns" if not on else "Multiple column levels"
return text, False
return True, False
return False, on
2 changes: 1 addition & 1 deletion explorer/parts/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _update_conll(df, deletable, drop_govs):
col_order = ["file", "s", "i"] + list(df.columns)
df = df.reset_index()
# do not show file extension
df["file"] = df["file"].str.replace(".txt.conll", "", regex=False)
df["file"] = df["file"].str.replace(".txt.conllu", "", regex=False)
df = df[[i for i in col_order if i is not None]]
cannot_delete = {"s", "i"}
columns = [
Expand Down
7 changes: 4 additions & 3 deletions explorer/parts/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ def _table_error(show, subcorpora, updating):
errors.append("No choice made for feature to use as columns.")
# this is now allowed ... can probably remove this function if
# we don't do any extra validations.
# if not subcorpora:
# errors.append("No choice made for feature to use as index")
if not subcorpora:
errors.append("No choice made for feature to use as index.")
if not errors:
return ""
return "* " + "\n* ".join(errors)
plural = "s" if len(errors) > 1 else ""
return f"Error{plural}\n* " + "\n* ".join(errors)


def _capitalize_first(s):
Expand Down
13 changes: 10 additions & 3 deletions explorer/parts/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _build_dataset_space(df, config):
df = _drop_cols_for_datatable(df, config["add_governor"])
df = df.reset_index()
# no file extensions
df["file"] = df["file"].str.replace(".txt.conll", "", regex=False)
df["file"] = df["file"].str.replace(".txt.conllu", "", regex=False)
max_row, max_col = config["table_size"]
df = df.iloc[:max_row, :max_col]
pieces = [
Expand Down Expand Up @@ -257,7 +257,12 @@ def _build_frequencies_space(corpus, table, config):
style={**style.MARGIN_5_MONO, **style.TSTYLE},
),
html.Div(
id="multiindex-text", style={**style.MARGIN_5_MONO, **style.TSTYLE}
children="Multicolumn mode",
id="multiindex-text",
style={**style.MARGIN_5_MONO,
**style.TSTYLE,
**{"whiteSpace": "nowrap"}
}
),
],
style={**style.CELL_MIDDLE_35, **style.TSTYLE},
Expand Down Expand Up @@ -299,7 +304,7 @@ def _build_concordance_space(df, config):
placeholder="Features to show",
id="show-for-conc",
options=cols,
style={**style.MARGIN_5_MONO, **style.FRONT},
style={**style.MARGIN_5_MONO, **style.NEAR_FRONT},
)
update = html.Button("Update", id="update-conc", style=style.MARGIN_5_MONO)
tstyle = dict(width="100%", **style.CELL_MIDDLE_35)
Expand Down Expand Up @@ -475,7 +480,9 @@ def make_explore_page(corpus, table, config, configs):
label = _make_search_name(config["corpus_name"], config["length"], dict())
search_from = [dict(value=0, label=label)]
show = html.Button("Show", id="show-this-dataset", style={**style.MARGIN_5_MONO, **style.FRONT})
show.title = "Show the selected corpus or search result in the Dataset tab"
clear = html.Button("Clear history", id="clear-history", style=style.MARGIN_5_MONO)
clear.title = "Delete all searches and frequency tables"

dropdown = dcc.Dropdown(
id="search-from", options=search_from, value=0, disabled=True
Expand Down

0 comments on commit 8a200c1

Please sign in to comment.