Selection Handlers
- class datamapplot.selection_handlers.SelectionHandlerBase(**kwargs)
Base class for selection handlers. Selection handlers are used to define custom behavior when text items are selected on the plot. This can include displaying additional information about the selected text items, generating visualizations based on the selected text items, or interacting with external APIs to process the selected text items.
- Parameters:
- dependencieslist, optional
A list of URLs for external dependencies required by the selection handler. Default is an empty list.
- class datamapplot.selection_handlers.DisplaySample(**kwargs)
A selection handler that displays a sample of the selected text items in a container on the page. The sample will be randomly selected from the full selection of text items, and the number of samples can be controlled by the n_samples parameter.
A resample button is also provided to generate a new sample of text items from the selection.
- Parameters:
- n_samplesint, optional
The number of samples to display. Default is 256.
- font_familystr, optional
The font family to use for the displayed text. Default is None.
- **kwargs
Additional keyword arguments to pass to the SelectionHandlerBase constructor.
- class datamapplot.selection_handlers.WordCloud(**kwargs)
A selection handler that generates a word cloud from the selected text items. The word cloud is displayed in a container on the page, and the number of words in the cloud can be controlled by the n_words parameter.
The word cloud is generated using the d3-cloud library, and the appearance of the word cloud can be customized using the width, height, font_family, stop_words, n_rotations, and color_scale parameters.
- Parameters:
- n_wordsint, optional
The number of words to display in the word cloud. Default is 256.
- widthint, optional
The width of the word cloud container. Default is 500.
- heightint, optional
The height of the word cloud container. Default is 500.
- font_familystr, optional
The font family to use for the word cloud. Default is None.
- stop_wordslist, optional
A list of stop words to exclude from the word cloud. Default is the English stop words from scikit-learn.
- n_rotationsint, optional
The number of rotations to use for the words in the word cloud. Default is 0. More rotations can make the word cloud more visually interesting, at the cost of readability.
- color_scalestr, optional
The color scale to use for the word cloud. Default is “YlGnBu”. The color scale can be any d3 color scale name, with an optional “_r” suffix to reverse the color scale.
- locationstr, optional
The location of the word cloud container on the page. Default is “bottom-right”. Should be one of “top-left”, “top-right”, “bottom-left”, or “bottom-right”.
- **kwargs
Additional keyword arguments to pass to the SelectionHandlerBase constructor.
- class datamapplot.selection_handlers.CohereSummary(**kwargs)
A selection handler that uses the Cohere API to generate a summary of selected text items. The handler requires an API key to be provided by the end-user in the resulting HTML page. The handler will generate a prompt based on the selected text items and keywords extracted from the text items, and get a Cohere model to summarize this. The summary will be displayed in a container on the page.
This handler can likely be adapted to other API services that provide text summarization.
Note that the API key handling here is secure enough for private or small-scale use, but is not suitable for enterprise or production use.
- Parameters:
- modelstr, optional
The Cohere model to use for summarization. Default is “command-r”. See the Cohere docs for more information on available models.
- stop_wordslist, optional
A list of stop words to exclude from the keyword extraction. Default is the English stop words from scikit-learn.
- n_keywordsint, optional
The number of keywords to extract from the text items. Default is 128.
- n_samplesint, optional
The number of samples to use for the summary. Default is 64.
- widthint, optional
The width of the summary container. Default is 500.
- locationstr, optional
The location of the summary container on the page. Default is “top-right”. Should be one of “top-left”, “top-right”, “bottom-left”, or “bottom-right”.
- **kwargs
Additional keyword arguments to pass to the SelectionHandlerBase constructor.
- class datamapplot.selection_handlers.TagSelection(tag_colors=None, location='top-right', width=308, max_height='80vh', other_triggers=None, **kwargs)
A selection handler that allows users to create and save tags for selected items. The handler provides a container for displaying existing tags, a button to create a new tag, and a button to save the tags to a JSON file.
The handler also provides a visual indicator for selected items that have been tagged, and allows users to add selected items to existing tags.
- Parameters:
- tag_colorslist, optional
A list of colors to use for the tags. Default is a set of default colors extending the tab10 palette.
- locationstr, optional
The location of the tag container on the page. Default is “top-right”. Should be one of “top-left”, “top-right”, “bottom-left”, or “bottom-right”.
- max_heightstr, optional
The maximum height of the tag container as a CSS descriptor string. Default is “95%”.