encode_point_badge
Customize graph node badges using a specific column for visual encoding. Define badge positions, map categories to icons, or display text directly. Supports continuous binning for dynamic visualizations and updates graph visuals in Graphistry.
Instructions
Set node badge encoding for a graph using Graphistry's encode_point_badge API.
Args:
graph_id (str): The ID of the graph to modify.
column (str): The node column to use for badge encoding (e.g., 'type', 'origin').
position (str, optional): Badge position on the node. Example: 'TopRight', 'BottomLeft', etc.
categorical_mapping (dict, optional): Map of category values to badge icons or images. Example: {'macbook': 'laptop', 'Canada': 'flag-icon-ca'}.
default_mapping (str, optional): Badge to use for values not in categorical_mapping. Example: 'question'.
as_text (bool, optional): If True, use text as the badge (for continuous binning or direct text display).
continuous_binning (list, optional): List of [threshold, badge] pairs for binning continuous values. Example: [[33, None], [66, 'info-circle'], [None, 'exclamation-triangle']].
Returns:
dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL.
Example:
encode_point_badge(graph_id, column='type', position='TopRight', categorical_mapping={'macbook': 'laptop'}, default_mapping='question')
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| as_text | No | ||
| categorical_mapping | No | ||
| column | Yes | ||
| continuous_binning | No | ||
| default_mapping | No | ||
| graph_id | Yes | ||
| position | No | TopRight |
Implementation Reference
- The handler function for the 'encode_point_badge' tool. Decorated with @mcp.tool() for registration in the FastMCP server. It retrieves the graph from cache, applies Graphistry's encode_point_badge method with provided parameters, updates the cache, and returns the updated graph URL. The docstring provides the input schema description.@mcp.tool() async def encode_point_badge( graph_id: str, column: str, position: str = "TopRight", categorical_mapping: Optional[dict] = None, default_mapping: Optional[str] = None, as_text: Optional[bool] = False, continuous_binning: Optional[list] = None ) -> Dict[str, Any]: """ Set node badge encoding for a graph using Graphistry's encode_point_badge API. Args: graph_id (str): The ID of the graph to modify. column (str): The node column to use for badge encoding (e.g., 'type', 'origin'). position (str, optional): Badge position on the node. Example: 'TopRight', 'BottomLeft', etc. categorical_mapping (dict, optional): Map of category values to badge icons or images. Example: {'macbook': 'laptop', 'Canada': 'flag-icon-ca'}. default_mapping (str, optional): Badge to use for values not in categorical_mapping. Example: 'question'. as_text (bool, optional): If True, use text as the badge (for continuous binning or direct text display). continuous_binning (list, optional): List of [threshold, badge] pairs for binning continuous values. Example: [[33, None], [66, 'info-circle'], [None, 'exclamation-triangle']]. Returns: dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL. Example: encode_point_badge(graph_id, column='type', position='TopRight', categorical_mapping={'macbook': 'laptop'}, default_mapping='question') """ if graph_id not in graph_cache: raise ValueError(f"Graph not found: {graph_id}") g = graph_cache[graph_id]["graph"] kwargs = {"column": column, "position": position} if categorical_mapping: kwargs["categorical_mapping"] = categorical_mapping if default_mapping: kwargs["default_mapping"] = default_mapping if as_text: kwargs["as_text"] = as_text if continuous_binning: kwargs["continuous_binning"] = continuous_binning g = g.encode_point_badge(**kwargs) graph_cache[graph_id]["graph"] = g return {"graph_id": graph_id, "url": g.plot(render=False)}