Skip to content
Snippets Groups Projects
Commit e40d179f authored by Jim Hoekstra's avatar Jim Hoekstra :wave_tone1:
Browse files

central word is now green to distinguish it from the others, also fixed some...

central word is now green to distinguish it from the others, also fixed some issues related to adding and removing words
parent b8b1ec04
No related branches found
No related tags found
1 merge request!7MSX-28
......@@ -82,10 +82,12 @@ def graph_elements_callback(add_button_ts, remove_button_ts, submit_button_ts, g
if remove_button_ts > add_button_ts:
if graph_selected is not None:
graph.remove_node(graph_selected['label'])
selected_word = graph_selected['label']
if selected_word in graph.get_all_words() and selected_word != graph.get_base_word():
graph.remove_node(graph_selected['label'])
if add_button_ts > remove_button_ts:
if add_word is not None and add_word != '':
if add_word is not None and add_word != '' and add_word not in graph.get_all_words():
graph.add_node(add_word)
graph.add_edge(graph.get_base_word(), add_word)
......
......@@ -12,6 +12,10 @@ class Graph:
def get_base_word(self):
return self.associated_words.get_base_word()
def get_all_words(self):
all_words = [node_dict['data']['label'] for node_dict in self.nodes]
return all_words
def clear_graph_elements(self):
self.nodes = []
self.edges = []
......@@ -24,7 +28,7 @@ class Graph:
base_word = self.associated_words.get_base_word()
associated_words = self.associated_words.get_associated_words()
self.clear_graph_elements()
self.add_node(base_word)
self.add_node(base_word, is_base_node=1)
self.add_nodes(associated_words)
self.add_edges(base_word, associated_words)
......@@ -32,8 +36,11 @@ class Graph:
for node in nodes:
self.add_node(node)
def add_node(self, node):
node_dict = {'data': {'id': node, 'label': node}}
def add_node(self, node, is_base_node=0):
node_dict = {'data': {'id': node, 'label': node, 'is_base_node': is_base_node}}
if is_base_node:
node_dict['selectable'] = False
node_dict['grabbable'] = False
if node_dict not in self.nodes:
self.nodes.append(node_dict)
......@@ -79,4 +86,19 @@ class Graph:
elements=elements,
userZoomingEnabled=False,
userPanningEnabled=False,
stylesheet=[
{
'selector': '[is_base_node > 0.5]',
'style': {
'label': 'data(label)',
'background-color': 'green'
}
},
{
'selector': '[is_base_node < 0.5]',
'style': {
'label': 'data(label)',
}
}
]
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment