Package epydoc :: Package docwriter :: Module dotgraph :: Class DotGraphUmlClassNode |
[hide private]
[frames] | no frames]

# Class DotGraphUmlClassNode

source code

A specialized dot graph node used to display ClassDocs using UML notation. The node is rendered as a table with three cells: the top cell contains the class name; the middle cell contains a list of attributes; and the bottom cell contains a list of operations:

    +-------------+
    |  ClassName  |
    +-------------+
    | x: int      |
    |     ...     |
    +-------------+
    | f(self, x)  |
    |     ...     |
    +-------------+

DotGraphUmlClassNodes may be collapsed, in which case they are drawn as a simple box containing the class name:

    +-------------+
    |  ClassName  |
    +-------------+

Attributes with types corresponding to documented classes can optionally be converted into edges, using link_attributes().

To Do: Add more options? - show/hide operation signature - show/hide operation signature types - show/hide operation signature return type - show/hide attribute types - use qualifiers

Instance Methods | [hide private]
__init__(self, class_doc, linker, context, collapsed=False, bgcolor=`'``#d8ffe8``'`, **options) Create a new DotGraphUmlClassNode based on the class class_doc. | source code call graph
Call Graph
Inherited from `DotGraphNode`: `__getitem__`, `__setitem__`
Attribute Linking
link_attributes(self, nodes) Convert any attributes with type descriptions corresponding to documented classes to edges. | source code call graph
Call Graph
_link_attribute(self, var, nodes) Helper for link_attributes(): try to convert the attribute variable `var` into an edge, and add that edge to self.edges. | source code call graph
Call Graph
_add_attribute_edge(self, var, nodes, type_str, **attribs) Helper for link_attributes(): try to add an edge for the given attribute variable `var`. | source code call graph
Call Graph
Helper Methods
_type_descr(self, api_doc) Return a plaintext type description for `api_doc` | source code call graph
Call Graph
_tooltip(self, var_doc) Return a tooltip for `var_doc`. | source code call graph
Call Graph
Rendering
_attribute_cell(self, var_doc) | source code call graph
Call Graph
_operation_cell(self, var_doc) | source code call graph
Call Graph
_operation_arg(self, name, default, func_doc) | source code call graph
Call Graph
_qualifier_cell(self, key_label, port) | source code call graph
Call Graph
_get_html_label(self) | source code call graph
Call Graph
to_dotfile(self) Return the dot commands that should be used to render this node. | source code call graph
Call Graph

Class Methods | [hide private]
Helper Methods
_summary(self, api_doc) Return a plaintext summary for `api_doc` | source code call graph
Call Graph

Class Variables | [hide private]
Inherited from `DotGraphNode` (private): `_next_id`
Attribute Linking
| SIMPLE_TYPE_RE = `re.compile(r'^`(``[`\w\.`]``+``)`$')` A regular expression that matches descriptions of simple types.
| COLLECTION_TYPE_RE = `re.compile(r'^`(`list`|`set`|`sequence`|`tuple`|`co`...`` A regular expression that matches descriptions of collection types.
| MAPPING_TYPE_RE = `re.compile(r'^`(`dict`|`dictionary`|`map`|`mapping`)` `...`` A regular expression that matches descriptions of mapping types.
| MAPPING_TO_COLLECTION_TYPE_RE = `re.compile(r'^`(`dict`|`dictionary`...`` A regular expression that matches descriptions of mapping types whose value type is a collection.
| OPTIONAL_TYPE_RE = `re.compile(r'^`(`None or`|`optional`)` `(``[`\w\.`]``+``)`$`...`` A regular expression that matches descriptions of optional types.
Rendering
| _ATTRIBUTE_CELL = ``'``\n <TR><TD ALIGN="LEFT" HREF="%s" TOOLTI``...`` args: (url, tooltip, label)
| _OPERATION_CELL = ``'``\n <TR><TD ALIGN="LEFT" HREF="%s" TOOLTI``...`` args: (url, tooltip, label)
| _QUALIFIER_CELL = ``'``\n <TR><TD VALIGN="BOTTOM" PORT="%s" BGC``...`` args: (port, bgcolor, label)
| _QUALIFIER_DIV = ``'``\n <TR><TD VALIGN="BOTTOM" HEIGHT="10" WI``...``
| _LABEL = ``'``\n <TABLE BORDER="0" CELLBORDER="0" CELLSPACING="``...`` Args: (rowspan, bgcolor, classname, attributes, operations, qualifiers)
| _COLLAPSED_LABEL = ``'``\n <TABLE CELLBORDER="0" BGCOLOR="%s" P``...``

Instance Variables | [hide private]
| class_doc The class represented by this node.
| linker Used to look up URLs for classes.
| context The context in which the node will be drawn.
| bgcolor The background color of the node.
| options Options used to control how the node is displayed.
| collapsed If true, then draw this node as a simple box.
| attributes The list of VariableDocs for attributes
| operations The list of VariableDocs for operations
| qualifiers List of (key_label, port) tuples.
| edges List of edges used to represent this node's attributes.

Method Details | [hide private]

### __init__(self, class_doc, linker, context, collapsed=False, bgcolor=`'``#d8ffe8``'`, **options) (Constructor) | source code call graph
Call Graph
Create a new DotGraphUmlClassNode based on the class class_doc. Parameters: `linker` (markup.DocstringLinker) - Used to look up URLs for classes. `context` (APIDoc) - The context in which this node will be drawn; dotted names will be contextualized to this context. `collapsed` (`bool`) - If true, then display this node as a simple box. `bgcolor` (``str``) - The background color for this node. `options` (`dict`) - A set of options used to control how the node should be displayed. `show_private_vars` - If false, then private variables are filtered out of the attributes & operations lists. (Default: False) `show_magic_vars` - If false, then magic variables (such as `__init__` and `__add__`) are filtered out of the attributes & operations lists. (Default: True) `show_inherited_vars` - If false, then inherited variables are filtered out of the attributes & operations lists. (Default: False) `max_attributes` - The maximum number of attributes that should be listed in the attribute box. If the class has more than this number of attributes, some will be ellided. Ellipsis is marked with `'...'`. `max_operations` - The maximum number of operations that should be listed in the operation box. `add_nodes_for_linked_attributes` - If true, then link_attributes() will create new a collapsed node for the types of a linked attributes if no node yet exists for that type. Overrides: DotGraphNode.__init__

### link_attributes(self, nodes) | source code call graph
Call Graph
Convert any attributes with type descriptions corresponding to documented classes to edges. The following type descriptions are currently handled: Dotted names: Create an attribute edge to the named type, labelled with the variable name. Collections: Create an attribute edge to the named type, labelled with the variable name, and marked with '*' at the type end of the edge. Mappings: Create an attribute edge to the named type, labelled with the variable name, connected to the class by a qualifier box that contains the key type description. Optional: Create an attribute edge to the named type, labelled with the variable name, and marked with '0..1' at the type end of the edge. The edges created by link_attributes() are handled internally by DotGraphUmlClassNode; they should not be added directly to the DotGraph. Parameters: `nodes` - A dictionary mapping from ClassDocs to DotGraphUmlClassNodes, used to look up the nodes for attribute types. If the `add_nodes_for_linked_attributes` option is used, then new nodes will be added to this dictionary for any types that are not already listed. These added nodes must be added to the DotGraph.

### _link_attribute(self, var, nodes) | source code call graph
Call Graph
Helper for link_attributes(): try to convert the attribute variable `var` into an edge, and add that edge to self.edges. Return `True` iff the variable was successfully converted to an edge (in which case, it should be removed from the attributes list).

### _add_attribute_edge(self, var, nodes, type_str, **attribs) | source code call graph
Call Graph
Helper for link_attributes(): try to add an edge for the given attribute variable `var`. Return `True` if successful.

### _operation_cell(self, var_doc) | source code call graph
Call Graph
To Do: do 'word wrapping' on the signature, by starting a new row in the table, if necessary. How to indent the new line? Maybe use align=right? I don't think dot has a &nbsp;. Optionally add return type info?

### _operation_arg(self, name, default, func_doc) | source code call graph
Call Graph
To Do: Handle tuple args better Optionally add type info?

### to_dotfile(self) | source code call graph
Call Graph
Return the dot commands that should be used to render this node. Overrides: DotGraphNode.to_dotfile (inherited documentation)

Class Variable Details | [hide private]

  ### COLLECTION_TYPE_RE A regular expression that matches descriptions of collection types. Value:
      re.compile(r'^(list|set|sequence|tuple|collection) of ([\w\.]+)$')

  ### MAPPING_TYPE_RE A regular expression that matches descriptions of mapping types. Value:
      re.compile(r'^(dict|dictionary|map|mapping) from ([\w\.]+) to ([\w\.]+
      )$')

  ### MAPPING_TO_COLLECTION_TYPE_RE A regular expression that matches descriptions of mapping types whose value type is a collection. Value:
      re.compile(r'^(dict|dictionary|map|mapping) from ([\w\.]+) to (list|se
      t|sequence|tuple|collection) of ([\w\.]+)$')

  ### OPTIONAL_TYPE_RE A regular expression that matches descriptions of optional types. Value:
      re.compile(r'^(None or|optional) ([\w\.]+)$|([\w\.]+) or None$')

  ### _ATTRIBUTE_CELL args: (url, tooltip, label) Value:
      '''
          <TR><TD ALIGN="LEFT" HREF="%s" TOOLTIP="%s">%s</TD></TR>
          '''

  ### _OPERATION_CELL args: (url, tooltip, label) Value:
      '''
          <TR><TD ALIGN="LEFT" HREF="%s" TOOLTIP="%s">%s</TD></TR>
          '''

  ### _QUALIFIER_CELL args: (port, bgcolor, label) Value:
      '''
          <TR><TD VALIGN="BOTTOM" PORT="%s" BGCOLOR="%s" BORDER="1">%s</TD><
      /TR>
          '''

  ### _QUALIFIER_DIV Value:
      '''
          <TR><TD VALIGN="BOTTOM" HEIGHT="10" WIDTH="10" FIXEDSIZE="TRUE"></
      TD></TR>
          '''

  ### _LABEL Args: (rowspan, bgcolor, classname, attributes, operations, qualifiers) Value:
      '''
          <TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0" CELLPADDING="0">
            <TR><TD ROWSPAN="%s">
              <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"
                     CELLPADDING="0" PORT="body" BGCOLOR="%s">
                <TR><TD>%s</TD></TR>
                <TR><TD><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0">
                  %s</TABLE></TD></TR>
      ...

  ### _COLLAPSED_LABEL Value:
      '''
          <TABLE CELLBORDER="0" BGCOLOR="%s" PORT="body">
            <TR><TD>%s</TD></TR>
          </TABLE>'''

Instance Variable Details | [hide private]

### edges List of edges used to represent this node's attributes. These should not be added to the DotGraph; this node will generate their dotfile code directly.