neo4j-viz 0.2.5__py3-none-any.whl → 0.2.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- neo4j_viz/visualization_graph.py +27 -3
- {neo4j_viz-0.2.5.dist-info → neo4j_viz-0.2.6.dist-info}/METADATA +1 -1
- {neo4j_viz-0.2.5.dist-info → neo4j_viz-0.2.6.dist-info}/RECORD +5 -5
- {neo4j_viz-0.2.5.dist-info → neo4j_viz-0.2.6.dist-info}/WHEEL +0 -0
- {neo4j_viz-0.2.5.dist-info → neo4j_viz-0.2.6.dist-info}/top_level.txt +0 -0
neo4j_viz/visualization_graph.py
CHANGED
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import warnings
|
|
4
4
|
from collections.abc import Iterable
|
|
5
|
-
from typing import Optional
|
|
5
|
+
from typing import Any, Hashable, Optional
|
|
6
6
|
|
|
7
7
|
from IPython.display import HTML
|
|
8
8
|
from pydantic_extra_types.color import Color, ColorType
|
|
@@ -201,7 +201,8 @@ class VisualizationGraph:
|
|
|
201
201
|
Parameters
|
|
202
202
|
----------
|
|
203
203
|
property:
|
|
204
|
-
The property of the nodes to use for coloring.
|
|
204
|
+
The property of the nodes to use for coloring. The type of this property must be hashable, or be a
|
|
205
|
+
list, set or dict containing only hashable types.
|
|
205
206
|
colors:
|
|
206
207
|
The colors to use for the nodes. If a dictionary is given, it should map from property to color.
|
|
207
208
|
If an iterable is given, the colors are used in order.
|
|
@@ -238,7 +239,11 @@ class VisualizationGraph:
|
|
|
238
239
|
prop_to_color = {}
|
|
239
240
|
colors_iter = iter(colors)
|
|
240
241
|
for node in self.nodes:
|
|
241
|
-
|
|
242
|
+
raw_prop = getattr(node, property)
|
|
243
|
+
try:
|
|
244
|
+
prop = self._make_hashable(raw_prop)
|
|
245
|
+
except ValueError:
|
|
246
|
+
raise ValueError(f"Unable to color nodes by unhashable property type '{type(raw_prop)}'")
|
|
242
247
|
|
|
243
248
|
if prop not in prop_to_color:
|
|
244
249
|
next_color = next(colors_iter, None)
|
|
@@ -263,3 +268,22 @@ class VisualizationGraph:
|
|
|
263
268
|
f"Ran out of colors for property '{property}'. {len(prop_to_color)} colors were needed, but only "
|
|
264
269
|
f"{len(set(prop_to_color.values()))} were given, so reused colors"
|
|
265
270
|
)
|
|
271
|
+
|
|
272
|
+
@staticmethod
|
|
273
|
+
def _make_hashable(raw_prop: Any) -> Hashable:
|
|
274
|
+
prop = raw_prop
|
|
275
|
+
if isinstance(raw_prop, list):
|
|
276
|
+
prop = tuple(raw_prop)
|
|
277
|
+
elif isinstance(raw_prop, set):
|
|
278
|
+
prop = frozenset(raw_prop)
|
|
279
|
+
elif isinstance(raw_prop, dict):
|
|
280
|
+
prop = tuple(sorted(raw_prop.items()))
|
|
281
|
+
|
|
282
|
+
try:
|
|
283
|
+
hash(prop)
|
|
284
|
+
except TypeError:
|
|
285
|
+
raise ValueError(f"Unable to convert property '{raw_prop}' of type {type(raw_prop)} to a hashable type")
|
|
286
|
+
|
|
287
|
+
assert isinstance(prop, Hashable)
|
|
288
|
+
|
|
289
|
+
return prop
|
|
@@ -9,9 +9,9 @@ neo4j_viz/options.py,sha256=QBeHLqHOJFtSCjzHvv-2A9TzTbnIaC6_onQq9fUlT_4,3079
|
|
|
9
9
|
neo4j_viz/pandas.py,sha256=180SEJGxT16OnXhd2KRisW2rHbrvyJAFZ6MNlhqfKco,1898
|
|
10
10
|
neo4j_viz/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
11
|
neo4j_viz/relationship.py,sha256=3Nz49UH3Ae6eTT9Lj6_eqO7nNANpuMGnGfSCL0DABHA,2751
|
|
12
|
-
neo4j_viz/visualization_graph.py,sha256=
|
|
12
|
+
neo4j_viz/visualization_graph.py,sha256=ys1gV3Me_1yFAqNknDqWTVZlX26KS_x2IF0dq9hy22Y,9932
|
|
13
13
|
neo4j_viz/resources/nvl_entrypoint/base.js,sha256=FPvDNl_DqFW72SqTrnY5NqIxfs6p66eqFoZJKoY6848,1800059
|
|
14
|
-
neo4j_viz-0.2.
|
|
15
|
-
neo4j_viz-0.2.
|
|
16
|
-
neo4j_viz-0.2.
|
|
17
|
-
neo4j_viz-0.2.
|
|
14
|
+
neo4j_viz-0.2.6.dist-info/METADATA,sha256=_-gENXULw6rLPwEJEmt3MqYjgrmj_epNJsJPjsG-dOk,7003
|
|
15
|
+
neo4j_viz-0.2.6.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
16
|
+
neo4j_viz-0.2.6.dist-info/top_level.txt,sha256=jPUM3z8MOtxqDanc2VzqkxG4HJn8aaq4S7rnCFNk_Vs,10
|
|
17
|
+
neo4j_viz-0.2.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|