Beispiel #1
0
 def get_package_properties(self, obj: PackageEntity) -> NodeProperties:
     """Get label and shape for packages."""
     return NodeProperties(
         label=obj.title,
         color=self.get_shape_color(obj)
         if self.config.colorized else "black",
     )
Beispiel #2
0
    def emit_node(
        self,
        name: str,
        type_: NodeType,
        properties: Optional[NodeProperties] = None,
    ) -> None:
        """Create a new node.

        Nodes can be classes, packages, participants etc.
        """
        if properties is None:
            properties = NodeProperties(label=name)
        stereotype = "~~Interface~~" if type_ is NodeType.INTERFACE else ""
        nodetype = self.NODES[type_]
        body = []
        if properties.attrs:
            body.extend(properties.attrs)
        if properties.methods:
            for func in properties.methods:
                args = self._get_method_arguments(func)
                line = f"{func.name}({', '.join(args)})"
                if func.returns:
                    line += " -> " + get_annotation_label(func.returns)
                body.append(line)
        name = name.split(".")[-1]
        self.emit(f"{nodetype} {name}{stereotype} {{")
        self._inc_indent()
        for line in body:
            self.emit(line)
        self._dec_indent()
        self.emit("}")
Beispiel #3
0
 def emit_node(
     self,
     name: str,
     type_: NodeType,
     properties: Optional[NodeProperties] = None,
 ) -> None:
     """Create a new node. Nodes can be classes, packages, participants etc."""
     if properties is None:
         properties = NodeProperties(label=name)
     stereotype = " << interface >>" if type_ is NodeType.INTERFACE else ""
     nodetype = self.NODES[type_]
     if properties.color and properties.color != self.DEFAULT_COLOR:
         color = f" #{properties.color}"
     else:
         color = ""
     body = []
     if properties.attrs:
         body.extend(properties.attrs)
     if properties.methods:
         for func in properties.methods:
             args = self._get_method_arguments(func)
             line = f"{func.name}({', '.join(args)})"
             if func.returns:
                 line += " -> " + get_annotation_label(func.returns)
             body.append(line)
     label = properties.label if properties.label is not None else name
     if properties.fontcolor and properties.fontcolor != self.DEFAULT_COLOR:
         label = f"<color:{properties.fontcolor}>{label}</color>"
     self.emit(f'{nodetype} "{label}" as {name}{stereotype}{color} {{')
     self._inc_indent()
     for line in body:
         self.emit(line)
     self._dec_indent()
     self.emit("}")
Beispiel #4
0
 def get_class_properties(self, obj: ClassEntity) -> NodeProperties:
     """Get label and shape for classes."""
     properties = NodeProperties(
         label=obj.title,
         attrs=obj.attrs if not self.config.only_classnames else None,
         methods=obj.methods if not self.config.only_classnames else None,
         fontcolor="red" if is_exception(obj.node) else "black",
         color=self.get_shape_color(obj)
         if self.config.colorized else "black",
     )
     return properties
Beispiel #5
0
 def emit_node(
     self,
     name: str,
     type_: NodeType,
     properties: Optional[NodeProperties] = None,
 ) -> None:
     """Create a new node. Nodes can be classes, packages, participants etc."""
     if properties is None:
         properties = NodeProperties(label=name)
     shape = SHAPES[type_]
     color = properties.color if properties.color is not None else self.DEFAULT_COLOR
     style = "filled" if color != self.DEFAULT_COLOR else "solid"
     label = self._build_label_for_node(properties)
     label_part = f', label="{label}"' if label else ""
     fontcolor_part = (f', fontcolor="{properties.fontcolor}"'
                       if properties.fontcolor else "")
     self.emit(
         f'"{name}" [color="{color}"{fontcolor_part}{label_part}, shape="{shape}", style="{style}"];'
     )
Beispiel #6
0
    def emit_node(
        self,
        name: str,
        type_: NodeType,
        properties: Optional[NodeProperties] = None,
    ) -> None:
        """Create a new node.

        Nodes can be classes, packages, participants etc.
        """
        if properties is None:
            properties = NodeProperties(label=name)
        elif properties.label is None:
            properties.label = name
        self.emit(f'node: {{title:"{name}"', force_newline=False)
        self._write_attributes(
            NODE_ATTRS,
            label=self._build_label_for_node(properties),
            shape=SHAPES[type_],
        )
        self.emit("}")