API Reference¶
This section documents the internal API of sphinx-needs-tree-map for developers who want to extend or integrate with the extension.
Extension Setup¶
sphinx-needs-tree-map: StrictDoc-style tree map visualizations for sphinx-needs.
This extension provides the needtreemap directive to create interactive Plotly.js treemap visualizations of sphinx-needs documentation.
Directives¶
NeedTreeMap directive implementation.
- class sphinx_needs_tree_map.directives.needtreemap.NeedTreeMapNode[source]¶
Bases:
General,ElementCustom docutils node for needtreemap directive.
This node stores the directive options and is processed later in the doctree-resolved event when all needs data is available.
- class sphinx_needs_tree_map.directives.needtreemap.NeedTreeMapDirective[source]¶
Bases:
SphinxDirectiveDirective to create an interactive treemap visualization of needs.
Usage:
.. needtreemap:: :filter: type == 'req' or type == 'spec' :root: document :depth: 3 :size_by: count :color_by: type :show_values: :interactive: :height: 600px :width: 100%
-
option_spec:
ClassVar[dict[str,Any]] = {'color_by': <function unchanged>, 'depth': <function positive_int>, 'filter': <function unchanged>, 'height': <function unchanged>, 'hierarchy': <function unchanged>, 'interactive': <function flag>, 'root': <function unchanged>, 'show_values': <function flag>, 'size_by': <function unchanged>, 'status': <function unchanged>, 'tags': <function unchanged>, 'title': <function unchanged>, 'types': <function unchanged>, 'width': <function unchanged>}¶ Mapping of option names to validator functions.
-
option_spec:
Utilities¶
Hierarchy Builder¶
Classes for building hierarchical tree structures from sphinx-needs data.
- class sphinx_needs_tree_map.utils.hierarchy.TreeNode[source]
Bases:
objectA node in the treemap hierarchy tree.
- id
Unique identifier for this node.
- label
Display label for the node.
- parent_id
ID of parent node (empty string for root).
- value
Numeric value for sizing (e.g., count of needs).
- node_type
Type of node (root, document, section, need).
- need_type
For need nodes, the sphinx-needs type (req, spec, etc.).
- status
For need nodes, the status value.
- metadata
Additional metadata for the node.
- children
List of child nodes.
-
id:
str
-
label:
str
-
parent_id:
str= ''
-
value:
int= 1
-
node_type:
str= 'node'
-
children:
list[TreeNode]
- compute_values()[source]
Recursively compute values from leaf nodes up.
For branch nodes, value = sum of children values. For leaf nodes, value remains as set.
- Return type:
- Returns:
The computed value for this node.
- __init__(id, label, parent_id='', value=1, node_type='node', need_type=None, status=None, metadata=<factory>, children=<factory>)
- class sphinx_needs_tree_map.utils.hierarchy.HierarchyBuilder[source]¶
Bases:
objectBuilds a tree hierarchy from sphinx-needs data.
Supports multiple hierarchy strategies: - document: Group by document name, then sections - links: Build tree from parent-child link relationships - type: Group by need type, then by status
- Parameters:
Filters¶
Filter utilities for sphinx-needs data.
- sphinx_needs_tree_map.utils.filters.filter_needs(needs, _app, filter_string=None, types=None, status=None, tags=None)[source]¶
Filter needs based on various criteria.
- Parameters:
- Return type:
- Returns:
Filtered needs as a dictionary.
Plotly Renderer¶
Plotly.js treemap rendering utilities.
- class sphinx_needs_tree_map.utils.plotly_renderer.PlotlyTreemapRenderer[source]¶
Bases:
objectRenders a TreeNode hierarchy as a Plotly.js treemap.
Generates HTML/JavaScript code that creates an interactive treemap visualization using Plotly.js.
- Parameters:
tree (
TreeNode) – Root TreeNode of the hierarchy to render.treemap_id (
str) – Unique HTML ID for this treemap instance.color_by (
str) – How to determine node colors (type | status).color_map (
dict[str,str] |None) – Dictionary mapping values to colors.show_values (
bool) – Whether to show values in labels.interactive (
bool) – Whether to enable interactive features.height (
str) – CSS height value (e.g., ‘600px’).width (
str) – CSS width value (e.g., ‘100%’).title (
str) – Optional title for the treemap.plotly_cdn (
str) – CDN URL for Plotly.js.