Filters¶
list of all filters¶
Filters can be used to filter a graph.
This is used to create a more special and specific view, making it more viewer friendly.
-
exclude_classes
(graph: codoc.domain.model.Graph) → codoc.domain.model.Graph¶ Returns a graph that doesn’t have any classes
-
exclude_functions
(graph: codoc.domain.model.Graph) → codoc.domain.model.Graph¶ Returns a graph that doesn’t have any functions
-
exclude_modules
(graph: codoc.domain.model.Graph) → codoc.domain.model.Graph¶ Returns a graph that doesn’t have any modules
-
exclude_exceptions
(graph: codoc.domain.model.Graph) → codoc.domain.model.Graph¶ Returns a graph that doesn’t have any exceptions
-
include_only_classes
(graph: codoc.domain.model.Graph) → codoc.domain.model.Graph¶ Returns a graph that only has classes
-
include_only_functions
(graph: codoc.domain.model.Graph) → codoc.domain.model.Graph¶ Returns a graph that only has functions
-
include_only_modules
(graph: codoc.domain.model.Graph) → codoc.domain.model.Graph¶ Returns a graph that only has modules
-
include_only_exceptions
(graph: codoc.domain.model.Graph) → codoc.domain.model.Graph¶ Returns a graph that only has exceptions
-
content_of
(node: Union[str, object, codoc.domain.model.Node], keep_external_nodes: bool = False, keep_parents: bool = False) → Callable[[codoc.domain.model.Graph], codoc.domain.model.Graph]¶ - Parameters
node – The node, object or string identifier of what to filter based on
keep_external_nodes – Whether to keep external dependencies of children
- Returns
A filter function that excludes non-children
- Return type
GraphFilter
Returns a filter that only returns children of the node given via the identifier.
The returned filter (function) can then be called with a given graph.
Important: Children are NOT dependencies, they are things defined inside the current node. I.e if a class, Foo, defined in FooModule, then FooModule is the parent of Foo.
Example that returns all modules/classes/exceptions/functions defined inside myproject.subproject. .. code-block:: python
filter_function = filters.content_of(myproject.subproject)
filtered_graph = filter_function(graph)
-
get_depth_based_filter
(depth: int) → Callable[[codoc.domain.model.Graph], codoc.domain.model.Graph]¶
-
class_diagram_filter
(graph: codoc.domain.model.Graph) → codoc.domain.model.Graph¶ - Parameters
graph – Graph to filter
- Returns
A graph that only contains classes and methods (functions inside classes)
The Class Diagram filter is useful if you want a traditional class diagram, as it will remove all functions (which aren’t inside classes - functions inside classes, are often called methods).
-
filter_by_regex
(pattern: str, flags=0) → Callable[[codoc.domain.model.Graph], codoc.domain.model.Graph]¶ This allows you to filter nodes based on whether they fulfill some regex query. This is ideal if you, for instance, want to remove all test related things.
The regex is done solely on the name attribute.
The following example removes all instances that don’t include “test”. Example:
graph = filters.filter_by_regex("test", flags=re.IGNORECASE)(graph)
To understand how to use regex, please consult the python documentation:
-
exclude_by_regex
(pattern: str, flags=0) → Callable[[codoc.domain.model.Graph], codoc.domain.model.Graph]¶ This allows you to filter nodes based on whether they fulfill some regex query. This is ideal if you, for instance, want to remove all test related things.
The regex is done solely on the name attribute.
The following example removes all instances with a name that contains “test”. Example:
graph = filters.exclude_by_regex("test", flags=re.IGNORECASE)(graph)
To understand how to use regex, please consult the python documentation:
Customization¶
Filters are, from a implementation perspective, simply a function that takes a graph and returns a new graph, making it very easy to implement custom filters.
An example where one creates a filter that removes all edges:
def remove_edges(graph):
return Graph(
nodes=graph.nodes,
edges=set()
)
We recommend you put all your custom filters in your codoc_views folder, in a file called custom_filters or similar, however this is completly optional.