ragraph.analysis.sequence._axis
#
Sort nodes in a typical axis-ready format.
Module Contents#
Classes#
Cast for parameters. |
Functions#
|
Get nodes in a plot-axis-ready order. |
|
Get root node of a node. |
|
Get list of root nodes corresponding to some collection of nodes. |
|
Get node kinds in order of occurrence. |
|
Get leaf nodes from a linked-list style child_cache (e.g. parent to children). |
|
Get width of a node and update width cache in-place. |
|
Calculate a sorting score for root nodes. |
|
Calculate a sorting score for sibling nodes. Lower scores go first. |
|
Attributes#
- class ragraph.analysis.sequence._axis.KindsCast(**kwargs)#
Bases:
ragraph.analysis._classes.Cast
Cast for parameters.
- __call__(value: Any) Optional[List[str]] #
Cast a value.
- ragraph.analysis.sequence._axis.axis_sequencing_analysis#
- ragraph.analysis.sequence._axis.get_axis_sequence(nodes: Iterable[ragraph.node.Node], kinds: Optional[List[str]] = None, sort_by_bus: bool = True, sort_by_width: bool = True, root_cache: Optional[Dict[ragraph.node.Node, ragraph.node.Node]] = None, child_cache: Optional[Dict[ragraph.node.Node, List[ragraph.node.Node]]] = None, width_cache: Optional[Dict[ragraph.node.Node, int]] = None) List[ragraph.node.Node] #
Get nodes in a plot-axis-ready order.
- Parameters:
nodes – Axis nodes to order.
kinds – Optional order of node kinds.
sort_by_bus – Whether to put bus nodes first.
sort_by_width – Whether to sort nodes by width in terms of leaf nodes.
root_cache – Node to resulting root node cache. Any supplied dictionary will be updated in-place.
child_cache – Node to child nodes that have been seen cache.
width_cache – Node to node width cache.
- Returns:
Ordered nodes.
Note
Axis ready means ordered by kind and buses nodes first where possible. Any supplied cache dictionary will be updated in-place.
Warning
When supplying node kinds it’s your own responsibility to make sure that each node’s kind actually is included in that node kind order.
- ragraph.analysis.sequence._axis.get_root(node: ragraph.node.Node, root_cache: Optional[Dict[ragraph.node.Node, ragraph.node.Node]] = None, child_cache: Optional[Dict[ragraph.node.Node, List[ragraph.node.Node]]] = None) ragraph.node.Node #
Get root node of a node.
- Parameters:
node – Nodes to find corresponding root nodes for.
root_cache – Node to resulting root node cache. Any supplied dictionary will be updated in-place.
child_cache – Node to child nodes that have been seen cache. Any supplied dictionary will be updated in-place.
- Returns:
Root node.
Note
Supply cache dictionaries to store intermediate results.
- ragraph.analysis.sequence._axis.get_roots(nodes: Iterable[ragraph.node.Node], root_cache: Optional[Dict[ragraph.node.Node, ragraph.node.Node]] = None, child_cache: Optional[Dict[ragraph.node.Node, List[ragraph.node.Node]]] = None) List[ragraph.node.Node] #
Get list of root nodes corresponding to some collection of nodes.
- Parameters:
nodes – Collection of nodes to find corresponding root nodes for.
root_cache – Node to resulting root node cache. Any supplied dictionary will be updated in-place.
child_cache – Node to child nodes that have been seen cache. Any supplied dictionary will be updated in-place.
- Returns:
Root nodes.
Note
Supply cache dictionaries to store intermediate results.
- ragraph.analysis.sequence._axis.get_kinds(nodes: Iterable[ragraph.node.Node]) List[str] #
Get node kinds in order of occurrence.
- Parameters:
nodes – Nodes to iterate over.
- Returns:
List of Node kinds.
- ragraph.analysis.sequence._axis.get_leafs(parent: ragraph.node.Node, child_cache: Dict[ragraph.node.Node, List[ragraph.node.Node]]) List[ragraph.node.Node] #
Get leaf nodes from a linked-list style child_cache (e.g. parent to children).
- Parameters:
parent – Parent node.
child_cache – Linked-list style parent-children dictionary.
- Returns:
Displayed leaf nodes as they occur under this parent.
- ragraph.analysis.sequence._axis.get_width(node: ragraph.node.Node, width_cache: Optional[Dict[ragraph.node.Node, int]] = None) int #
Get width of a node and update width cache in-place.
- Parameters:
node – Node to get the width of.
width_cache – Node to node width cache.
- Returns:
Node width.
- ragraph.analysis.sequence._axis.get_root_key(node: ragraph.node.Node, kind_order: Dict[str, int], sort_by_width: bool, width_cache: Optional[Dict[ragraph.node.Node, int]] = None) Union[int, Tuple[int, int]] #
Calculate a sorting score for root nodes.
- Parameters:
node – Root node to obtain a score for.
kind_order – Node kind to position dictionary.
sort_by_width – Whether to sort nodes by width in terms of leaf nodes.
width_cache – Node to node width cache.
- Returns:
Root node sorting key.
Note
Sort by kinds first, width in terms of actual (not display) leaf nodes second.
- ragraph.analysis.sequence._axis.get_sibling_key(node: ragraph.node.Node, sort_by_bus: bool, sort_by_width: bool, width_cache: Optional[Dict[ragraph.node.Node, int]] = None) Union[int, Tuple[int, int]] #
Calculate a sorting score for sibling nodes. Lower scores go first.
- Parameters:
node – Node to score.
sort_by_bus – Whether to put bus nodes first.
sort_by_width – Whether to sort nodes by width in terms of leaf nodes.
width_cache – Dictionary of nodes to displayed children.
- Returns:
Sibling node sorting score.
Note
Bus nodes first, width in terms of actual (not display) leaf nodes second.
- ragraph.analysis.sequence._axis.axis_sequencing(graph: ragraph.graph.Graph, root: Optional[Union[str, ragraph.node.Node]] = None, nodes: Optional[Union[List[ragraph.node.Node], List[str]]] = None, kinds: Optional[List[str]] = None, sort_by_bus: bool = True, sort_by_width: bool = True, edge_weights: Optional[List[str]] = None, inherit: bool = True, loops: bool = False, inplace: bool = True, names: bool = False, safe: bool = True, **kwargs)#