Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Breaking changes

* Removed `table` property from nodes and relationships returned from `from_snowflake`, the table is represented by the `caption` field.
* Changed default value of `override` parameter in `VisualizationGraph.color_nodes()` from `False` to `True`. The method now overrides existing node colors by default. To preserve existing colors, explicitly pass `override=False`.

## New features

Expand Down
2 changes: 1 addition & 1 deletion python-wrapper/src/neo4j_viz/visualization_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def color_nodes(
property: Optional[str] = None,
colors: Optional[ColorsType] = None,
color_space: ColorSpace = ColorSpace.DISCRETE,
override: bool = False,
override: bool = True,
) -> None:
"""
Color the nodes in the graph based on either a node field, or a node property.
Expand Down
36 changes: 36 additions & 0 deletions python-wrapper/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,39 @@ def test_color_nodes_unhashable() -> None:
VG = VisualizationGraph(nodes=nodes, relationships=[])
with pytest.raises(ValueError, match="Unable to color nodes by unhashable property type '<class 'list'>'"):
VG.color_nodes(property="list_of_lists", colors=["#000000"])


def test_color_nodes_default_override() -> None:
"""Test that the default value of override is True (colors are overridden by default)."""
nodes = [
Node(id="4:d09f48a4-5fca-421d-921d-a30a896c604d:0", caption="Person", color="#FF0000"),
Node(id="4:d09f48a4-5fca-421d-921d-a30a896c604d:6", caption="Product", color="#FF0000"),
Node(id="4:d09f48a4-5fca-421d-921d-a30a896c604d:11", caption="Product", color="#FF0000"),
]

VG = VisualizationGraph(nodes=nodes, relationships=[])

# Call without specifying override - should use default (True) and override existing colors
VG.color_nodes(field="caption", colors={"Person": "#000000", "Product": "#00FF00"})

assert VG.nodes[0].color == Color("#000000")
assert VG.nodes[1].color == Color("#00ff00")
assert VG.nodes[2].color == Color("#00ff00") # Should be overridden to #00ff00


def test_color_nodes_override_false() -> None:
"""Test that override=False preserves existing colors."""
nodes = [
Node(id="4:d09f48a4-5fca-421d-921d-a30a896c604d:0", caption="Person", color="#FF0000"),
Node(id="4:d09f48a4-5fca-421d-921d-a30a896c604d:6", caption="Product", color="#FF0000"),
Node(id="4:d09f48a4-5fca-421d-921d-a30a896c604d:11", caption="Product"),
]

VG = VisualizationGraph(nodes=nodes, relationships=[])

# Call with override=False - should preserve existing colors
VG.color_nodes(field="caption", colors={"Person": "#000000", "Product": "#00FF00"}, override=False)

assert VG.nodes[0].color == Color("#ff0000") # Should keep existing color
assert VG.nodes[1].color == Color("#ff0000") # Should keep existing color
assert VG.nodes[2].color == Color("#00ff00") # Should get new color (no existing color)