Skip to content

Commit 8bee706

Browse files
committed
docs: clarify collections usage
1 parent fcd6dc2 commit 8bee706

File tree

6 files changed

+85
-88
lines changed

6 files changed

+85
-88
lines changed

demos/more_examples/graphistry_features/collections.ipynb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@
66
"source": [
77
"# Collections in PyGraphistry\n",
88
"\n",
9-
"Define collections (subsets) using GFQL AST helpers and apply visual encodings."
9+
"Collections define labeled subsets of a graph (nodes, edges, or subgraphs) using full GFQL. They enable advanced, layered styling that overrides base encodings when you need precise highlights.\n",
10+
"\n",
11+
"Use collections when you want:\n",
12+
"- baseline encodings (for example, by entity type) plus overlays for alerts or critical paths\n",
13+
"- multiple overlapping highlights with a priority order\n",
14+
"- a UI panel for toggling focused subsets on and off\n",
15+
"\n",
16+
"Collections are evaluated in priority order, with higher priority collections overriding lower ones for styling.\n"
1017
]
1118
},
1219
{
1320
"cell_type": "markdown",
1421
"metadata": {},
1522
"source": [
16-
"Collections use GFQL operations (like `graphistry.n(...)`) to define sets, and can be combined using intersections."
23+
"In this notebook, we build sets using GFQL AST helpers, combine them with intersections, and apply node and edge colors. Collections can be based on nodes, edges, or multi-step graph traversals (Chain).\n"
1724
]
1825
},
1926
{

docs/source/10min.rst

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,11 @@ Example visualization:
161161

162162
Now, edges are colored based on the type of vulnerability, helping you distinguish different attack types.
163163

164-
Adjusting Sizes, Labels, Icons, Badges, and More
165-
------------------------------------------------
166-
167-
You can adjust further node and edge settings using data. Sample calls include:
168-
169-
- ``bind(point_title=)``: Assign labels to nodes based on a column
170-
- ``encode_point_size()``: Adjust node sizes based on a column
171-
- ``encode_point_icon()``: Assign different icons to nodes based on a column
172-
- ``encode_point_badge()``: Add badges to nodes based on a column
173-
- ``encode_point_weight()``: Adjust node weights based on a column
174-
- Equivalent functions for edges: ``encode_edge_size()``, ``encode_edge_icon()``, ``encode_edge_badge()``
164+
Advanced: Collections for layered highlights
165+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
175166

176-
For advanced, subset-based coloring, use Collections with GFQL AST helpers:
167+
Use collections when you want GFQL-driven subsets (nodes, edges, or subgraphs) to override base encodings.
168+
This is useful for overlays like alerts or critical paths that take precedence over your normal color rules.
177169

178170
.. code-block:: python
179171
@@ -188,9 +180,20 @@ For advanced, subset-based coloring, use Collections with GFQL AST helpers:
188180
]
189181
g.collections(collections=collections, show_collections=True).plot()
190182
191-
See :ref:`Layout settings <layout-settings>` and the
192-
:doc:`Collections tutorial notebook </demos/more_examples/graphistry_features/collections>`.
193-
Tip: order matters (earlier collections override later ones) and intersections require set IDs.
183+
See the :doc:`Collections tutorial notebook </demos/more_examples/graphistry_features/collections>` and
184+
:doc:`GFQL docs </gfql/index>` for full details.
185+
186+
Adjusting Sizes, Labels, Icons, Badges, and More
187+
------------------------------------------------
188+
189+
You can adjust further node and edge settings using data. Sample calls include:
190+
191+
- ``bind(point_title=)``: Assign labels to nodes based on a column
192+
- ``encode_point_size()``: Adjust node sizes based on a column
193+
- ``encode_point_icon()``: Assign different icons to nodes based on a column
194+
- ``encode_point_badge()``: Add badges to nodes based on a column
195+
- ``encode_point_weight()``: Adjust node weights based on a column
196+
- Equivalent functions for edges: ``encode_edge_size()``, ``encode_edge_icon()``, ``encode_edge_badge()``
194197

195198
Additional settings, such as background colors and logo watermarks, can also be configured.
196199

docs/source/gfql/spec/wire_protocol.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,50 @@ null // null
376376

377377
**Note**: The `timezone` field is optional for DateTime values and defaults to "UTC" if omitted. This ensures consistent behavior across systems while allowing explicit timezone specification when needed.
378378

379+
## Collections Payloads
380+
381+
Collections are Graphistry visualization overlays that use GFQL wire protocol operations to define subsets
382+
of nodes, edges, or subgraphs. They are applied in priority order, with earlier collections overriding later
383+
ones for styling.
384+
385+
### Collection Set
386+
387+
Collection sets wrap GFQL operations in a `gfql_chain` object:
388+
389+
```json
390+
{
391+
"type": "set",
392+
"id": "purchasers",
393+
"name": "Purchasers",
394+
"node_color": "#00BFFF",
395+
"expr": {
396+
"type": "gfql_chain",
397+
"gfql": [
398+
{"type": "Node", "filter_dict": {"status": "purchased"}}
399+
]
400+
}
401+
}
402+
```
403+
404+
### Collection Intersection
405+
406+
Intersections reference previously defined set IDs:
407+
408+
```json
409+
{
410+
"type": "intersection",
411+
"name": "High Value Purchasers",
412+
"node_color": "#AA00AA",
413+
"expr": {
414+
"type": "intersection",
415+
"sets": ["purchasers", "vip"]
416+
}
417+
}
418+
```
419+
420+
For Python examples and helper constructors, see the
421+
:doc:`Collections tutorial notebook </demos/more_examples/graphistry_features/collections>`.
422+
379423
## Examples
380424

381425
### User 360 Query

docs/source/gfql/wire_protocol_examples.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -514,29 +514,3 @@ filter3 = n(filter_dict={"date": gt({"type": "datetime", "value": "2023-01-01T00
514514
- Timezone conversions are handled efficiently
515515
- For large datasets, ensure datetime columns are properly typed (not object dtype)
516516
- Use `pd.Timestamp` for best performance when creating many predicates programmatically
517-
518-
## Collections and Wire Protocol
519-
520-
Collections accept GFQL wire protocol dicts inside the `expr` field for set definitions.
521-
You can pass the dict directly or through the helper constructors:
522-
523-
```python
524-
from graphistry import collection_set
525-
526-
collections = [
527-
collection_set(
528-
expr={
529-
"type": "gfql_chain",
530-
"gfql": [
531-
{"type": "Node", "filter_dict": {"status": {"type": "EQ", "val": "purchased"}}}
532-
],
533-
},
534-
name="Purchasers",
535-
node_color="#00BFFF",
536-
)
537-
]
538-
g.collections(collections=collections)
539-
```
540-
541-
See the [Collections guide](../visualization/layout/settings.html) for full usage details and
542-
intersection examples.

docs/source/visualization/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Visualize
22
=============
33

44
We recommend getting started with :ref:`10 Minutes to PyGraphistry <10min>`, :ref:`10 Minutes to Graphistry Visualization<10min-viz>`, and the :ref:`layout guide <layout-guide>`.
5-
For advanced, subset-based coloring, see :ref:`Layout settings <layout-settings>` and the
5+
For advanced, subset-based coloring, see the
66
:doc:`Collections tutorial notebook </demos/more_examples/graphistry_features/collections>`.
77

88
For static image export (documentation, reports), see the `static rendering tutorial <../demos/demos_databases_apis/graphviz/static_rendering.ipynb>`_.

docs/source/visualization/layout/settings.rst

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,22 @@ Use :meth:`graphistry.PlotterBase.PlotterBase.scene_settings` to modify the appe
3636
- ``edge_opacity``: Range 0.0 to 1.0 (0.0 fully transparent, 1.0 fully opaque, displayed as 0-100 in UI)
3737
- ``point_opacity``: Range 0.0 to 1.0 (0.0 fully transparent, 1.0 fully opaque, displayed as 0-100 in UI)
3838

39+
Encodings (Color, Size, Icons)
40+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41+
42+
Use the ``encode_*`` methods to style nodes and edges based on columns (for example, color by entity type).
43+
See the :doc:`Color encodings notebook </demos/more_examples/graphistry_features/encodings-colors>` for full examples.
44+
3945
Collections
4046
~~~~~~~~~~~
4147

42-
Use :meth:`graphistry.PlotterBase.PlotterBase.collections` to define collections (subsets) with optional encodings:
48+
Collections define labeled subsets (nodes, edges, or subgraphs) using full GFQL and apply layered styling
49+
that overrides base encodings. Use them to call out alerts or critical paths on top of your standard color
50+
encodings, with priority-based overrides when subsets overlap.
51+
52+
For a full walkthrough, see the :doc:`Collections tutorial notebook </demos/more_examples/graphistry_features/collections>`.
53+
For GFQL syntax, see :doc:`GFQL documentation </gfql/index>`.
54+
For schema details, see `Collections URL options <https://hub.graphistry.com/docs/api/1/rest/url/#url-collections>`_.
4355

4456
.. code-block:: python
4557
@@ -62,49 +74,6 @@ Use :meth:`graphistry.PlotterBase.PlotterBase.collections` to define collections
6274
)
6375
g2.plot()
6476
65-
The collections list is JSON-minified and URL-encoded automatically. GFQL operations use the
66-
Python AST helpers; see :doc:`GFQL documentation </gfql/index>`.
67-
For full schema details, see `Collections URL options <https://hub.graphistry.com/docs/api/1/rest/url/#url-collections>`_.
68-
For a full walkthrough, see the :doc:`Collections tutorial notebook </demos/more_examples/graphistry_features/collections>`.
69-
For color encoding basics, see the :doc:`Color encodings notebook </demos/more_examples/graphistry_features/encodings-colors>`.
70-
71-
Notes and validation
72-
^^^^^^^^^^^^^^^^^^^^
73-
74-
- Order matters: earlier collections have higher priority and override later ones.
75-
- Use collections for priority-based subsets and overlaps; use encode_* for simple column-driven colors.
76-
- Helper constructors: ``graphistry.collection_set(...)`` and ``graphistry.collection_intersection(...)``
77-
return JSON-friendly dicts (AST inputs are wrapped into ``gfql_chain``) for ``collections=``.
78-
- Intersections reference set IDs; provide ``id`` for any set used in an intersection.
79-
- Omitting ``node_color`` or ``edge_color`` leaves encodings as passthrough.
80-
- ``collections_global_node_color`` and ``collections_global_edge_color`` apply to nodes/edges
81-
not in any collection (leading ``#`` is optional).
82-
- Accepted inputs for ``expr`` include GFQL AST helpers, ``Chain`` objects, and wire-protocol dicts.
83-
- Use ``validate='strict'`` to raise on invalid collections; the default ``autofix`` warns and
84-
drops invalid entries. Use ``warn=False`` to silence warnings.
85-
- If you already have an encoded collections string, pass ``encode=False``. When using
86-
``settings(url_params=...)`` directly, provide an encoded ``collections`` value.
87-
88-
Wire protocol example
89-
^^^^^^^^^^^^^^^^^^^^^
90-
91-
.. code-block:: python
92-
93-
collections_wire = [
94-
{
95-
"type": "set",
96-
"name": "Wire Protocol Example",
97-
"node_color": "#AA00AA",
98-
"expr": {
99-
"type": "gfql_chain",
100-
"gfql": [
101-
{"type": "Node", "filter_dict": {"status": "purchased"}}
102-
]
103-
}
104-
}
105-
]
106-
g.collections(collections=collections_wire)
107-
10877
10978
Styling the Background and Foreground
11079
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)