-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
eb372b0
docs: add collections usage
lmeyerov b9f00ff
docs: add collections notebook and gfql ast example
lmeyerov b30a176
docs: link collections in overview guides
lmeyerov 7023f8c
docs: link color encodings from collections
lmeyerov 86f3b98
docs: replace absolute collections links
lmeyerov 59ba590
docs: expand collections guidance and validation
lmeyerov 76d86cb
docs: add quick collections tips
lmeyerov 6f125d5
docs: clarify when to use collections
lmeyerov 21ca5d0
docs: add collections overlap example
lmeyerov 29f3847
docs: mention collections helper constructors
lmeyerov 7f5555c
docs: note helpers wrap ast to gfql chain
lmeyerov 3d35f9f
docs: use collections helper constructors
lmeyerov 60d63be
docs: use collections helpers in examples
lmeyerov fc05db7
docs: add collections wire protocol note
lmeyerov 3cda05f
docs: note collections after gfql
lmeyerov ebf8f6e
docs: use helper imports in collections examples
lmeyerov 264bad0
docs: show graph-level collection chain
lmeyerov 2325c29
docs: add plot call in collections notebook
lmeyerov a1e0fa1
docs: use honeypot dataset in collections notebook
lmeyerov c6575ba
docs: clarify collections usage
lmeyerov 25c7bc5
docs: trigger ci
lmeyerov 874f367
docs: fix layout settings cross-reference for PDF build
lmeyerov 6731d37
docs: retrigger readthedocs build
lmeyerov 93f5ea2
docs: fix collections doc review follow-ups
lmeyerov a9980d6
docs: retrigger readthedocs status
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
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.