Skip to content

Commit

Permalink
Code refactoring for PEP8 compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzocaputo committed Mar 31, 2024
1 parent 0f1e1e1 commit 473982e
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions pystixview/pystixview.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ class PySTIXView:
}

__STYLES = ['square-flat',
'square-dark',
'square-lite',
'noback-dark',
'noback-flat',
'round-flat']
'square-dark',
'square-lite',
'noback-dark',
'noback-flat',
'round-flat']

def __init__(self, height: str, width: str, notebook: bool = False,
select_menu: bool = False, filter_menu: bool = False,
Expand All @@ -111,7 +111,6 @@ def __init__(self, height: str, width: str, notebook: bool = False,
filter_menu=filter_menu)
self.__icons_path = Path(os.path.dirname(__file__)) / 'icons'


if style in self.__STYLES:
self.__style = style
else:
Expand Down Expand Up @@ -407,10 +406,9 @@ def add_relationship(self, relationship: Relationship |
relationship.target_ref,
relationship.relationship_type)


def _generate_graph(self, show_physics_buttons: bool = False,
show_node_buttons: bool = False,
show_edge_buttons: bool = False) -> str:
show_node_buttons: bool = False,
show_edge_buttons: bool = False) -> str:
"""Generate and return HTML code to render the graph.
In case of Jupyter Notebook, the graph is rendered
via IPython.display.HTML.
Expand Down Expand Up @@ -470,17 +468,17 @@ def _generate_graph(self, show_physics_buttons: bool = False,
const selectedNode = network.getSelectedNodes()[0];
if (allNodes[selectedNode]) {
document.querySelector("#code_section").style.display="block";
document.querySelector("#code_section pre").textContent =
JSON.stringify(JSON.parse(allNodes[selectedNode].stix), null, 2);
document.querySelector("#code_section pre").textContent =
JSON.stringify(JSON.parse(
allNodes[selectedNode].stix), null, 2);
}
}
}
})
"""
bhtml.find('body').append(script_tag)

return str(bhtml)


def show_graph(self, show_physics_buttons: bool = False,
show_node_buttons: bool = False,
show_edge_buttons: bool = False) -> str:
Expand All @@ -500,8 +498,8 @@ def show_graph(self, show_physics_buttons: bool = False,
"""

html_graph = self._generate_graph(show_physics_buttons,
show_node_buttons,
show_edge_buttons)
show_node_buttons,
show_edge_buttons)
if self.__notebook:
return HTML(html_graph)
return html_graph
Expand All @@ -521,8 +519,8 @@ def save_graph(self, name, show_physics_buttons: bool = False,
"""

html_code = self._generate_graph(show_physics_buttons,
show_node_buttons,
show_edge_buttons)
show_node_buttons,
show_edge_buttons)
with open(name, 'w', encoding="utf-8") as fd:
fd.write(html_code)

Expand Down

0 comments on commit 473982e

Please sign in to comment.