From 53a5eac15fe4b14df0650a6869b69fe35f37f83f Mon Sep 17 00:00:00 2001 From: tm4185s Date: Tue, 28 May 2024 12:31:39 +0200 Subject: [PATCH] Refactored VisualizationStyle class --- viziphant/patterns.py | 4 ++-- viziphant/patterns_src/view.py | 37 ++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/viziphant/patterns.py b/viziphant/patterns.py index 926beee..3ebc734 100644 --- a/viziphant/patterns.py +++ b/viziphant/patterns.py @@ -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 diff --git a/viziphant/patterns_src/view.py b/viziphant/patterns_src/view.py index f9e5358..9e0cb30 100644 --- a/viziphant/patterns_src/view.py +++ b/viziphant/patterns_src/view.py @@ -19,9 +19,12 @@ class VisualizationStyle: - INVISIBLE = 1 - NOCOLOR = 2 - COLOR = 3 + styles = { + 'invisible': 1, + 'nocolor': 2, + 'color': 3 + } + class View: @@ -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. @@ -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 @@ -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 @@ -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)) @@ -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