-
Notifications
You must be signed in to change notification settings - Fork 226
docs: add collections usage #875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lmeyerov
wants to merge
21
commits into
feat/collections-support
Choose a base branch
from
docs/collections-support
base: feat/collections-support
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c37d7a2
docs: add collections usage
lmeyerov eaa0b9c
docs: add collections notebook and gfql ast example
lmeyerov 6c9272e
docs: link collections in overview guides
lmeyerov dee5b9d
docs: link color encodings from collections
lmeyerov 2e947b7
docs: replace absolute collections links
lmeyerov 312eb4e
docs: expand collections guidance and validation
lmeyerov 08a760f
docs: add quick collections tips
lmeyerov e8574a1
docs: clarify when to use collections
lmeyerov 22346a2
docs: add collections overlap example
lmeyerov 64d1d35
docs: mention collections helper constructors
lmeyerov 274a479
docs: note helpers wrap ast to gfql chain
lmeyerov 742d8ce
docs: use collections helper constructors
lmeyerov edf2a0c
docs: use collections helpers in examples
lmeyerov 5853b62
docs: add collections wire protocol note
lmeyerov ad8acd0
docs: note collections after gfql
lmeyerov 0c7100c
docs: use helper imports in collections examples
lmeyerov 99ccba7
docs: show graph-level collection chain
lmeyerov b5575f5
docs: add plot call in collections notebook
lmeyerov 7f051ae
docs: use honeypot dataset in collections notebook
lmeyerov 8db4343
docs: clarify collections usage
lmeyerov fb58c44
docs: trigger ci
lmeyerov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
183 changes: 183 additions & 0 deletions
183
demos/more_examples/graphistry_features/collections.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Collections in PyGraphistry\n", | ||
| "\n", | ||
| "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", | ||
| "\n", | ||
| "Use collections when you want:\n", | ||
| "- baseline encodings (for example, by entity type) plus overlays for alerts or critical paths\n", | ||
| "- multiple overlapping highlights with a priority order\n", | ||
| "- a UI panel for toggling focused subsets on and off\n", | ||
| "\n", | ||
| "Collections are evaluated in priority order, with higher priority collections overriding lower ones for styling.\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "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" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "metadata": {}, | ||
| "execution_count": null, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from pathlib import Path\n", | ||
| "import pandas as pd\n", | ||
| "import graphistry\n", | ||
| "from graphistry import collection_set, collection_intersection, n, e_forward, Chain\n", | ||
| "\n", | ||
| "edges = pd.read_csv(Path('demos/data/honeypot.csv'))\n", | ||
| "g = graphistry.edges(edges, \"attackerIP\", \"victimIP\")\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "metadata": {}, | ||
| "execution_count": null, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Use Chain to select subgraphs (nodes + edges) by edge attributes\n", | ||
| "collections = [\n", | ||
| " collection_set(\n", | ||
| " expr=Chain([n(), e_forward({\"vulnName\": \"MS08067 (NetAPI)\"}), n()]),\n", | ||
| " id='netapi',\n", | ||
| " name='MS08067 (NetAPI)',\n", | ||
| " node_color='#00BFFF',\n", | ||
| " edge_color='#00BFFF',\n", | ||
| " ),\n", | ||
| " collection_set(\n", | ||
| " expr=Chain([n(), e_forward({\"victimPort\": 445.0}), n()]),\n", | ||
| " id='port445',\n", | ||
| " name='Port 445',\n", | ||
| " node_color='#32CD32',\n", | ||
| " edge_color='#32CD32',\n", | ||
| " ),\n", | ||
| " collection_intersection(\n", | ||
| " sets=['netapi', 'port445'],\n", | ||
| " name='NetAPI + 445',\n", | ||
| " node_color='#AABBCC',\n", | ||
| " edge_color='#AABBCC',\n", | ||
| " ),\n", | ||
| "]\n", | ||
| "\n", | ||
| "g2 = g.collections(\n", | ||
| " collections=collections,\n", | ||
| " show_collections=True,\n", | ||
| " collections_global_node_color='CCCCCC',\n", | ||
| " collections_global_edge_color='CCCCCC',\n", | ||
| ")\n", | ||
| "\n", | ||
| "g2._url_params\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "metadata": {}, | ||
| "execution_count": null, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Render (requires graphistry.register(...))\n", | ||
| "g2.plot()\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Notes and validation\n", | ||
| "\n", | ||
| "- Order matters: earlier collections override later ones.\n", | ||
| "- Use collections for priority-based subsets and overlaps; use encode_* for simple column-driven colors.\n", | ||
| "- Helper constructors: `graphistry.collection_set(...)` and `graphistry.collection_intersection(...)` return JSON-friendly dicts (AST inputs wrap to `gfql_chain`).\n", | ||
| "- Provide `id` for sets used by intersections.\n", | ||
| "- Global colors apply to nodes/edges not in any collection; `#` is optional.\n", | ||
| "- Use `validate='strict'` to raise, or `warn=False` to silence warnings.\n", | ||
| "\n", | ||
| "Wire protocol and pre-encoded strings:\n", | ||
| "\n", | ||
| "```python\n", | ||
| "collections_wire = [\n", | ||
| " {\n", | ||
| " \"type\": \"set\",\n", | ||
| " \"name\": \"Wire Protocol Example\",\n", | ||
| " \"node_color\": \"#AA00AA\",\n", | ||
| " \"expr\": {\n", | ||
| " \"type\": \"gfql_chain\",\n", | ||
| " \"gfql\": [\n", | ||
| " {\"type\": \"Node\", \"filter_dict\": {\"status\": \"purchased\"}}\n", | ||
| " ]\n", | ||
| " }\n", | ||
| " }\n", | ||
| "]\n", | ||
| "g.collections(collections=collections_wire)\n", | ||
| "\n", | ||
| "g.collections(collections=encoded_collections, encode=False)\n", | ||
| "```\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Run `g2.plot()` in a notebook session with valid credentials to render inline.\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Overlap priority example\n", | ||
| "\n", | ||
| "Earlier collections override later ones when they overlap.\n", | ||
| "\n", | ||
| "```python\n", | ||
| "collections_priority = [\n", | ||
| " collection_set(\n", | ||
| " expr=Chain([n(), e_forward({\"vulnName\": \"MS08067 (NetAPI)\"}), n()]),\n", | ||
| " id=\"netapi\",\n", | ||
| " name=\"MS08067 (NetAPI)\",\n", | ||
| " node_color=\"#FFAA00\",\n", | ||
| " edge_color=\"#FFAA00\",\n", | ||
| " ),\n", | ||
| " collection_set(\n", | ||
| " expr=Chain([n(), e_forward({\"victimPort\": 445.0}), n()]),\n", | ||
| " id=\"port445\",\n", | ||
| " name=\"Port 445\",\n", | ||
| " node_color=\"#00BFFF\",\n", | ||
| " edge_color=\"#00BFFF\",\n", | ||
| " ),\n", | ||
| "]\n", | ||
| "g.collections(collections=collections_priority)\n", | ||
| "```\n" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "For more on color encodings, see the [Color encodings notebook](encodings-colors.ipynb).\n" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "name": "python", | ||
| "version": "3.x" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,11 @@ Run chain remotely and fetch results | |
| g2 = g1.gfql_remote([n(), e(), n()]) | ||
| assert len(g2._nodes) <= len(g1._nodes) | ||
|
|
||
| .. note:: | ||
| Collections are visualization URL settings; apply them after GFQL results | ||
| (for example, ``g2.collections(...)``). The GFQL remote/upload APIs do not | ||
| accept collections payloads yet. | ||
|
Comment on lines
+20
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure why this note was needed but i dont see an issue in having it either |
||
|
|
||
| Method :meth:`chain_remote <graphistry.compute.ComputeMixin.ComputeMixin.chain_remote>` runs chain remotely and fetched the computed graph | ||
|
|
||
| - **chain**: Sequence of graph node and edge matchers (:class:`ASTObject <graphistry.compute.ast.ASTObject>` instances). | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file is not included in the repo, probably should be or a way to download the data should be provided?