apply_time_ring_layout
Arrange graph nodes in circular rings based on timestamp data to visualize temporal patterns and relationships over time.
Instructions
Apply a time ring layout to the graph using Graphistry's time_ring_layout API.
Args:
graph_id (str): The ID of the graph to modify.
time_col (str): The node column to use for determining ring position (should be a datetime or timestamp attribute, e.g., 'created_at').
Returns:
dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL.
Example:
apply_time_ring_layout(graph_id, time_col='created_at')
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| graph_id | Yes | ||
| time_col | Yes |
Implementation Reference
- This is the main handler function for the 'apply_time_ring_layout' tool, decorated with @mcp.tool() which registers it in the MCP server. It applies a time ring layout to a graph using Graphistry's API, handling datetime coercion if necessary, and returns the updated graph ID and visualization URL.@mcp.tool() async def apply_time_ring_layout(graph_id: str, time_col: str) -> Dict[str, Any]: """ Apply a time ring layout to the graph using Graphistry's time_ring_layout API. Args: graph_id (str): The ID of the graph to modify. time_col (str): The node column to use for determining ring position (should be a datetime or timestamp attribute, e.g., 'created_at'). Returns: dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL. Example: apply_time_ring_layout(graph_id, time_col='created_at') """ if graph_id not in graph_cache: raise ValueError(f"Graph not found: {graph_id}") g = graph_cache[graph_id]["graph"] # Ensure the time_col is datetime64 for Graphistry nodes_df = graph_cache[graph_id].get("nodes_df") if nodes_df is not None and time_col in nodes_df.columns: if not pd.api.types.is_datetime64_any_dtype(nodes_df[time_col]): # Coerce to datetime64 nodes_df[time_col] = pd.to_datetime(nodes_df[time_col], errors="coerce") # Update the graph's nodes table g = g.nodes(nodes_df) g = g.time_ring_layout(time_col) graph_cache[graph_id]["graph"] = g return {"graph_id": graph_id, "url": g.plot(render=False)}
- src/graphistry_mcp_server/server.py:578-578 (registration)The @mcp.tool() decorator registers the apply_time_ring_layout function as an MCP tool with that name.@mcp.tool()
- The function signature and docstring define the input schema (graph_id: str, time_col: str) and output (Dict[str, Any] with graph_id and url).async def apply_time_ring_layout(graph_id: str, time_col: str) -> Dict[str, Any]: """ Apply a time ring layout to the graph using Graphistry's time_ring_layout API. Args: graph_id (str): The ID of the graph to modify. time_col (str): The node column to use for determining ring position (should be a datetime or timestamp attribute, e.g., 'created_at'). Returns: dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL. Example: apply_time_ring_layout(graph_id, time_col='created_at')