Skip to content

Commit

Permalink
Refactored VisualizationStyle class
Browse files Browse the repository at this point in the history
  • Loading branch information
nnnzs committed May 28, 2024
1 parent ea1bac2 commit 53a5eac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions viziphant/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def plot_patterns_hypergraph(patterns, pattern_size=None, num_neurons=None,\
hypergraphs.append(hg)
view = View(hypergraphs=hypergraphs, node_size=node_size,
node_color=node_color, node_linewidth=node_linewidth)
fig = view.show(subset_style=VisualizationStyle.COLOR,
triangulation_style=VisualizationStyle.INVISIBLE)
fig = view.show(subset_style=VisualizationStyle.styles['color'],
triangulation_style=VisualizationStyle.styles['invisible'])

return fig
37 changes: 20 additions & 17 deletions viziphant/patterns_src/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@


class VisualizationStyle:
INVISIBLE = 1
NOCOLOR = 2
COLOR = 3
styles = {
'invisible': 1,
'nocolor': 2,
'color': 3
}



class View:
Expand Down Expand Up @@ -219,8 +222,8 @@ def create_polygon(*args, **kwargs):
return dynamic_map, pipe

def show(self,
subset_style=VisualizationStyle.COLOR,
triangulation_style=VisualizationStyle.INVISIBLE):
subset_style=VisualizationStyle.styles['color'],
triangulation_style=VisualizationStyle.styles['invisible']):
"""
Set up the correct arrangement and combination of the
DynamicMap objects.
Expand All @@ -246,8 +249,8 @@ def show(self,
return fig

def draw_hyperedges(self, highlight_neuron=None,
subset_style=VisualizationStyle.COLOR,
triangulation_style=VisualizationStyle.INVISIBLE):
subset_style=VisualizationStyle.styles['color'],
triangulation_style=VisualizationStyle.styles['invisible']):
"""
Handler for drawing the hyperedges of the hypergraphs
in the given style
Expand All @@ -256,14 +259,14 @@ def draw_hyperedges(self, highlight_neuron=None,
----------
subset_style: enum VisualizationStyle
How to do the subset standard visualization of the hyperedges:
VisualizationStyle.INVISIBLE => not at all
VisualizationStyle.NOCOLOR => Only contours without color
VisualizationStyle.COLOR => Contours filled with color
VisualizationStyle.styles['invisible] => not at all
VisualizationStyle.styles['nocolor] => Only contours without color
VisualizationStyle.styles['color] => Contours filled with color
triangulation_style: enum VisualizationStyle
How to do the triangulation visualization of the hyperedges:
VisualizationStyle.INVISIBLE => not at all
VisualizationStyle.NOCOLOR => Only contours without color
VisualizationStyle.COLOR => Contours filled with color
VisualizationStyle.styles['invisible] => not at all
VisualizationStyle.styles['nocolor] => Only contours without color
VisualizationStyle.styles['color] => Contours filled with color
"""

# Collect all polygons to pass them to the visualization together
Expand All @@ -280,11 +283,11 @@ def draw_hyperedges(self, highlight_neuron=None,
# Options are: invisible, nocolor, color
# If invisible, the corresponding visualization does not need
# to be constructed
if subset_style != VisualizationStyle.INVISIBLE:
if subset_style != VisualizationStyle.styles['invisible']:
polygons_subset.append(create_subset(hyperedge,
self.positions,
self.node_radius))
if triangulation_style != VisualizationStyle.INVISIBLE:
if triangulation_style != VisualizationStyle.styles['invisible']:
polygons_triang.extend(
create_triangulation(hyperedge, self.positions))

Expand All @@ -310,10 +313,10 @@ def process_polygons(polygons, color=True):
# Call the postprocessing function, color added only if needed
polygons.extend(process_polygons(
polygons_subset,
subset_style == VisualizationStyle.COLOR))
subset_style == VisualizationStyle.styles['color']))
polygons.extend(process_polygons(
polygons_triang,
triangulation_style == VisualizationStyle.COLOR))
triangulation_style == VisualizationStyle.styles['color']))

# Save as instance attribute so widgets can work with the polygons
self.polygons = polygons
Expand Down

0 comments on commit 53a5eac

Please sign in to comment.