encode_point_badge
Set visual badges on graph nodes to highlight categories or values using column data, improving data interpretation in Graphistry visualizations.
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 |
|---|---|---|---|
| graph_id | Yes | ||
| column | Yes | ||
| position | No | TopRight | |
| categorical_mapping | No | ||
| default_mapping | No | ||
| as_text | No | ||
| continuous_binning | No |
Implementation Reference
- The encode_point_badge tool handler: registers the tool via @mcp.tool(), defines input parameters with type hints and comprehensive docstring schema, and implements the logic by calling Graphistry's encode_point_badge method on the cached graph object.@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)}