diff --git a/changelog.md b/changelog.md index 5d02439..36f223a 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/python-wrapper/src/neo4j_viz/visualization_graph.py b/python-wrapper/src/neo4j_viz/visualization_graph.py index ecc40ab..49efcdf 100644 --- a/python-wrapper/src/neo4j_viz/visualization_graph.py +++ b/python-wrapper/src/neo4j_viz/visualization_graph.py @@ -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. diff --git a/python-wrapper/tests/test_colors.py b/python-wrapper/tests/test_colors.py index adc1395..dff4d2c 100644 --- a/python-wrapper/tests/test_colors.py +++ b/python-wrapper/tests/test_colors.py @@ -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 ''"): 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)