Commit e70d30cc authored by Jim Hoekstra's avatar Jim Hoekstra 👋🏻
Browse files

Merge branch 'issue/lower-input-words' into 'develop'

lower input words & small layout and styling changes

See merge request !19
parents 459a5818 d3179f12
......@@ -8,4 +8,4 @@ if os.getenv('MSX_URL_PREFIX', False):
URL_PREFIX = os.environ['MSX_URL_PREFIX']
app = dash.Dash(name=__name__, external_stylesheets=external_stylesheets, url_base_pathname=URL_PREFIX,
suppress_callback_exceptions=True)
suppress_callback_exceptions=True, title='TALK Tool')
body {
background-color: whitesmoke;
}
.header {
height: 7vh;
margin-top: 3vh;
}
.graph {
height: 80vh;
}
.footer {
height: 7vh;
margin-bottom: 3vh;
}
.content {
width: 90%;
margin: auto;
}
......@@ -27,7 +27,14 @@ def update_graph_div(submit_word_button):
State(component_id='base-word-input', component_property='value'),
)
def update_base_word(submit_word_button, base_word_input):
return base_word_input
if base_word_input is not None:
base_word_input_lowercase = base_word_input.lower()
if base_word_input_lowercase != '':
return base_word_input_lowercase
else:
raise PreventUpdate
else:
raise PreventUpdate
@app.callback(
......@@ -52,17 +59,26 @@ def update_graph_elements(submit_word_button, add_word_button, extend_graph_butt
graph = Graph()
if button_id == 'submit-word-button':
graph.fill_with_associations(word2vec_model, base_word_input)
new_nodes_and_edges = graph.get_nodes_and_edges()
return json.dumps(new_nodes_and_edges)
if base_word_input is not None:
if base_word_input != '':
graph.fill_with_associations(word2vec_model, base_word_input)
new_nodes_and_edges = graph.get_nodes_and_edges()
return json.dumps(new_nodes_and_edges)
else:
raise PreventUpdate
raise PreventUpdate
if button_id == 'add-word-button':
graph.set_nodes_and_edges(json.loads(nodes_and_edges))
if add_word_input is not None and add_word_input != '' and add_word_input not in graph.get_all_words():
graph.add_node(add_word_input)
graph.add_edge(base_word_state, add_word_input)
new_nodes_and_edges = json.dumps(graph.get_nodes_and_edges())
return new_nodes_and_edges
if add_word_input is not None:
add_word_input_lowercase = add_word_input.lower()
if add_word_input_lowercase != '' and add_word_input_lowercase not in graph.get_all_words():
graph.add_node(add_word_input_lowercase)
graph.add_edge(base_word_state, add_word_input_lowercase)
new_nodes_and_edges = json.dumps(graph.get_nodes_and_edges())
return new_nodes_and_edges
else:
raise PreventUpdate
else:
raise PreventUpdate
......
......@@ -22,11 +22,12 @@ class Graph:
self.edges = []
def fill_with_associations(self, word2vec_model, base_word):
associated_words = word2vec_model.get_associated_words(base_word)
base_word_lower = base_word.lower()
associated_words = word2vec_model.get_associated_words(base_word_lower)
self.clear_graph_elements()
self.add_node(base_word, is_base_node=1)
self.add_node(base_word_lower, is_base_node=1)
self.add_nodes(associated_words)
self.add_edges(base_word, associated_words)
self.add_edges(base_word_lower, associated_words)
def add_nodes(self, nodes):
for node in nodes:
......@@ -85,7 +86,7 @@ class Graph:
return cyto.Cytoscape(id=component_id,
autoRefreshLayout=True,
layout={'name': 'cose', 'animate': True},
style={'width': '100%', 'height': '550px'},
style={'width': '100%', 'height': '100%'},
elements=elements,
userZoomingEnabled=False,
userPanningEnabled=False,
......
......@@ -13,11 +13,9 @@ external_stylesheets = [
layout = html.Div(children=[
html.Div(className='container', children=[
html.Br(),
html.Br(),
html.Div(className='content', children=[
html.Div(children=[
html.Div(className='row', children=[
html.Div(className='row header', children=[
html.Div(className='col-1', children=[
html.H2(children='Term:'),
]),
......@@ -28,30 +26,27 @@ layout = html.Div(children=[
html.Button(id='submit-word-button', n_clicks_timestamp=0, children='Submit Term', className='btn btn-success btn-lg')]),
])
]),
html.Br(),
html.Div(id='base-word-div',
style={'display': 'none'},
),
html.Div(id='graph-elements-div',
style={'display': 'none'},
),
html.Div(id='msx-graph-div', children=[]),
html.Div(children=[
html.Div(className='row', children=[
html.Div(className='col-3', children=[
dcc.Input(id='add-word-input', value='', type='text', className='form-control form-control-lg'),
]),
html.Div(className='col-2', children=[
html.Button(id='add-word-button', n_clicks_timestamp=0, children='Add Association', className='btn btn-success btn-lg'),
]),
html.Div(className='col-2', children=[
html.Button(id='extend-graph-button', n_clicks_timestamp=0, children='Extend Graph', className='btn btn-success btn-lg'),
]),
html.Div(className='col-2', children=[
]),
html.Div(className='col-3', children=[
html.Button(id='remove-word-button', n_clicks_timestamp=0, children='Remove Selected Association', className='btn btn-danger btn-lg')]),
]),
html.Div(className='graph', id='msx-graph-div', children=[]),
html.Div(className='row footer', children=[
html.Div(className='col-3', children=[
dcc.Input(id='add-word-input', value='', type='text', className='form-control form-control-lg'),
]),
html.Div(className='col-2', children=[
html.Button(id='add-word-button', n_clicks_timestamp=0, children='Add Association', className='btn btn-success btn-lg'),
]),
html.Div(className='col-2', children=[
html.Button(id='extend-graph-button', n_clicks_timestamp=0, children='Extend Graph', className='btn btn-success btn-lg'),
]),
html.Div(className='col-2', children=[
]),
html.Div(className='col-3', children=[
html.Button(id='remove-word-button', n_clicks_timestamp=0, children='Remove Selected Association', className='btn btn-danger btn-lg')]),
]),
]),
])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment