Skip to content

Commit 557d21f

Browse files
authored
Merge pull request #248 from neo4j/copilot/change-default-override-parameter
Change default for override parameter in color_nodes from False to True
2 parents 984f841 + 7628c55 commit 557d21f

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Breaking changes
44

55
* Removed `table` property from nodes and relationships returned from `from_snowflake`, the table is represented by the `caption` field.
6+
* 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`.
67

78
## New features
89

python-wrapper/src/neo4j_viz/visualization_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def color_nodes(
294294
property: Optional[str] = None,
295295
colors: Optional[ColorsType] = None,
296296
color_space: ColorSpace = ColorSpace.DISCRETE,
297-
override: bool = False,
297+
override: bool = True,
298298
) -> None:
299299
"""
300300
Color the nodes in the graph based on either a node field, or a node property.

python-wrapper/tests/test_colors.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,39 @@ def test_color_nodes_unhashable() -> None:
254254
VG = VisualizationGraph(nodes=nodes, relationships=[])
255255
with pytest.raises(ValueError, match="Unable to color nodes by unhashable property type '<class 'list'>'"):
256256
VG.color_nodes(property="list_of_lists", colors=["#000000"])
257+
258+
259+
def test_color_nodes_default_override() -> None:
260+
"""Test that the default value of override is True (colors are overridden by default)."""
261+
nodes = [
262+
Node(id="4:d09f48a4-5fca-421d-921d-a30a896c604d:0", caption="Person", color="#FF0000"),
263+
Node(id="4:d09f48a4-5fca-421d-921d-a30a896c604d:6", caption="Product", color="#FF0000"),
264+
Node(id="4:d09f48a4-5fca-421d-921d-a30a896c604d:11", caption="Product", color="#FF0000"),
265+
]
266+
267+
VG = VisualizationGraph(nodes=nodes, relationships=[])
268+
269+
# Call without specifying override - should use default (True) and override existing colors
270+
VG.color_nodes(field="caption", colors={"Person": "#000000", "Product": "#00FF00"})
271+
272+
assert VG.nodes[0].color == Color("#000000")
273+
assert VG.nodes[1].color == Color("#00ff00")
274+
assert VG.nodes[2].color == Color("#00ff00") # Should be overridden to #00ff00
275+
276+
277+
def test_color_nodes_override_false() -> None:
278+
"""Test that override=False preserves existing colors."""
279+
nodes = [
280+
Node(id="4:d09f48a4-5fca-421d-921d-a30a896c604d:0", caption="Person", color="#FF0000"),
281+
Node(id="4:d09f48a4-5fca-421d-921d-a30a896c604d:6", caption="Product", color="#FF0000"),
282+
Node(id="4:d09f48a4-5fca-421d-921d-a30a896c604d:11", caption="Product"),
283+
]
284+
285+
VG = VisualizationGraph(nodes=nodes, relationships=[])
286+
287+
# Call with override=False - should preserve existing colors
288+
VG.color_nodes(field="caption", colors={"Person": "#000000", "Product": "#00FF00"}, override=False)
289+
290+
assert VG.nodes[0].color == Color("#ff0000") # Should keep existing color
291+
assert VG.nodes[1].color == Color("#ff0000") # Should keep existing color
292+
assert VG.nodes[2].color == Color("#00ff00") # Should get new color (no existing color)

0 commit comments

Comments
 (0)