Skip to main content
Glama

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
NameRequiredDescriptionDefault
graph_idYes
columnYes
positionNoTopRight
categorical_mappingNo
default_mappingNo
as_textNo
continuous_binningNo

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)}

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/graphistry/graphistry-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server