You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/customizing.rst
+26-23Lines changed: 26 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,24 +23,26 @@ If you have not yet created a ``VisualizationGraph`` object, please refer to one
23
23
Coloring nodes
24
24
--------------
25
25
26
-
Nodes can be colored directly by providing them with a color property, upon creation.
26
+
Nodes can be colored directly by providing them with a color field, upon creation.
27
27
This can for example be done by passing a color as a string to the ``color`` parameter of the
28
28
:doc:`Node <./api-reference/node>` object.
29
29
30
-
Alternatively, you can color nodes based on a property (field) of the nodes after a ``VisualizationGraph`` object has been
30
+
Alternatively, you can color nodes based on a field or property of the nodes after a ``VisualizationGraph`` object has been
31
31
created.
32
32
33
33
34
34
The ``color_nodes`` method
35
35
~~~~~~~~~~~~~~~~~~~~~~~~~~
36
36
37
37
By calling the :meth:`neo4j_viz.VisualizationGraph.color_nodes` method, you can color nodes based on a
38
-
node property (field).
39
-
It's possible to color the nodes based on a discrete or continuous property.
40
-
In the discrete case, a new color from the ``colors`` provided is assigned to each unique value of the node property.
41
-
In the continuous case, the ``colors`` should be a list of colors representing a range that are used to create a gradient of colors based on the values of the node property.
38
+
node field or property (members of the `Node.properties` map).
42
39
43
-
By default the Neo4j color palette that works for both light and dark mode will be used.
40
+
It's possible to color the nodes based on a discrete or continuous color space (see :doc:`ColorSpace <./api-reference/colors>`).
41
+
In the discrete case, a new color from the `colors` provided is assigned to each unique value of the node field/property.
42
+
In the continuous case, the `colors` should be a list of colors representing a range that are used to
43
+
create a gradient of colors based on the values of the node field/property.
44
+
45
+
By default the Neo4j color palette, that works for both light and dark mode, will be used.
44
46
If you want to use a different color palette, you can pass a dictionary or iterable of colors as the ``colors``
45
47
parameter.
46
48
A color value can for example be either strings like "blue", or hexadecimal color codes like "#FF0000", or even a tuple of RGB values like (255, 0, 255).
@@ -49,20 +51,20 @@ If some nodes already have a ``color`` set, you can choose whether or not to ove
49
51
parameter.
50
52
51
53
52
-
By discrete node property (field)
53
-
*********************************
54
+
By discrete color space
55
+
***********************
54
56
55
-
To not use the default colors, we can provide a list of custom colors based on the discrete node property (field) "caption" to the ``color_nodes`` method:
57
+
To not use the default colors, we can provide a list of custom colors based on the discrete node field "caption" to the ``color_nodes`` method:
The full set of allowed values for colors are listed `here <https://docs.pydantic.dev/2.0/usage/types/extra_types/color_types/>`_.
@@ -75,18 +77,18 @@ this snippet:
75
77
from palettable.wesanderson import Moonrise1_5
76
78
77
79
# VG is a VisualizationGraph object
78
-
VG.color_nodes("caption", Moonrise1_5.colors) # PropertyType.DISCRETE is default
80
+
VG.color_nodes(field="caption", Moonrise1_5.colors) # PropertyType.DISCRETE is default
79
81
80
-
In this case, all nodes with the same caption will get the same color.
82
+
In theses cases, all nodes with the same caption will get the same color.
81
83
82
-
If there are fewer colors that unique values for the node ``property`` provided, the colors will be reused in a cycle.
83
-
To avoid that, you could use another palette or extend one with additional colors. Please refer to the
84
+
If there are fewer colors than unique values for the node ``field`` or ``property`` provided, the colors will be reused in a cycle.
85
+
To avoid that, you could use a larger palette or extend one with additional colors. Please refer to the
84
86
:doc:`Visualizing Neo4j Graph Data Science (GDS) Graphs tutorial <./tutorials/gds-example>` for an example on how
85
87
to do the latter.
86
88
87
89
88
-
By continuous node property (field)
89
-
***********************************
90
+
By continuous color space
91
+
*************************
90
92
91
93
To not use the default colors, we can provide a list of custom colors representing a range to the ``color_nodes`` method:
92
94
@@ -96,9 +98,9 @@ To not use the default colors, we can provide a list of custom colors representi
96
98
97
99
# VG is a VisualizationGraph object
98
100
VG.color_nodes(
99
-
"centrality_score",
101
+
property="centrality_score",
100
102
[(255, 0, 0), (191, 64, 0), (128, 128, 0), (64, 191, 0), (0, 255, 0)] # From red to green
101
-
property_type=PropertyType.CONTINUOUS
103
+
color_space=ColorSpace.CONTINUOUS
102
104
)
103
105
104
106
In this case, the nodes will be colored based on the value of the "centrality_score" property, with the lowest values being colored red and the highest values being colored green.
@@ -110,7 +112,7 @@ Since we only provided five colors in the range, the granularity of the gradient
110
112
Sizing nodes
111
113
------------
112
114
113
-
Nodes can be given a size directly by providing them with a size property, upon creation.
115
+
Nodes can be given a size directly by providing them with a size field, upon creation.
114
116
This can for example be done by passing a size as an integer to the ``size`` parameter of the
115
117
:doc:`Node <./api-reference/node>` object.
116
118
@@ -178,7 +180,7 @@ In the following example, we pin the node with ID 1337 and unpin the node with I
178
180
Direct modification of nodes and relationships
179
181
----------------------------------------------
180
182
181
-
Nodes and relationships can also be modified directly by accessing the ``nodes`` and ``relationships`` attributes of an
183
+
Nodes and relationships can also be modified directly by accessing the ``nodes`` and ``relationships`` fields of an
182
184
existing ``VisualizationGraph`` object.
183
185
These attributes list of all the :doc:`Nodes <./api-reference/node>` and
184
186
:doc:`Relationships <./api-reference/relationship>` in the graph, respectively.
@@ -189,6 +191,7 @@ Each node and relationship has attributes that can be accessed and modified dire
189
191
190
192
# VG is a VisualizationGraph object
191
193
VG.nodes[0].size =10
194
+
VG.nodes[0].properties["height"] =170
192
195
VG.relationships[4].caption ="BUYS"
193
196
194
197
Any changes made to the nodes and relationships will be reflected in the next rendering of the graph.
0 commit comments