0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
clanguml::package_diagram::generators::mermaid::generator Class Reference

Package diagram MermaidJS generator. More...

Detailed Description

Package diagram MermaidJS generator.

Definition at line 53 of file package_diagram_generator.h.

#include <package_diagram_generator.h>

Public Member Functions

 generator (diagram_config &config, diagram_model &model)
 
void generate_diagram (std::ostream &ostr) const override
 Main generator method.
 
void generate_diagram_type (std::ostream &ostr) const override
 Generate the diagram type.
 
void generate_relationships (const package &p, std::ostream &ostr) const
 Generate relationships originating from package p
 
void generate (const package &e, std::ostream &ostr) const
 Generate diagram package element.
 
void generate_groups (std::ostream &ostr) const
 Generate package elements grouped using together MermaidJS tag.
 
void generate_notes (std::ostream &ostr, const common::model::diagram_element &element) const override
 Generate notes attached to packages.
 
- Public Member Functions inherited from clanguml::common::generators::mermaid::generator< ConfigType, DiagramType >
 generator (ConfigType &config, DiagramType &model)
 Constructor.
 
 ~generator () override=default
 
void generate (std::ostream &ostr) const override
 Generate diagram.
 
virtual void generate_diagram (std::ostream &ostr) const =0
 Generate diagram specific part.
 
void generate_mermaid_directives (std::ostream &ostr, const std::vector< std::string > &directives) const
 Generate MermaidJS directives from config file.
 
virtual void generate_diagram_type (std::ostream &ostr) const =0
 Generate the diagram type.
 
virtual void generate_notes (std::ostream &ostr, const model::diagram_element &element) const
 Generate diagram notes.
 
void generate_metadata (std::ostream &ostr) const
 Generate comment with diagram metadata.
 
void generate_title (std::ostream &ostr) const
 Generate diagram title.
 
template<typename E >
void generate_link (std::ostream &ostr, const E &e) const
 Generate hyper link to element.
 
void print_debug (const common::model::source_location &e, std::ostream &ostr) const
 Print debug information in diagram comments.
 
- Public Member Functions inherited from clanguml::common::generators::generator< ConfigType, DiagramType >
 generator (ConfigType &config, DiagramType &model)
 Constructor.
 
virtual ~generator ()=default
 
virtual void generate (std::ostream &ostr) const =0
 Generate diagram.
 
const ConfigType & config () const
 Get reference to diagram config.
 
const DiagramType & model () const
 Get reference to diagram model.
 
std::optional< std::pair< std::string, std::string > > get_link_pattern (const common::model::source_location &sl) const
 
std::optional< std::pair< std::string, std::string > > get_tooltip_pattern (const common::model::source_location &sl) const
 
std::optional< std::string > render_link (const common::model::diagram_element &e) const
 
std::optional< std::string > render_link (const common::model::relationship &e) const
 
std::optional< std::string > render_tooltip (const common::model::diagram_element &e) const
 
std::optional< std::string > render_tooltip (const common::model::relationship &e) const
 
void init_context ()
 Initialize diagram Jinja context.
 
void update_context () const
 Update diagram Jinja context.
 
void init_env ()
 
const inja::json & context () const
 
inja::Environment & env () const
 

Private Attributes

uint64_t note_id_ {0UL}
 
common::generators::nested_element_stack< common::model::packagetogether_group_stack_
 

Additional Inherited Members

- Protected Attributes inherited from clanguml::common::generators::mermaid::generator< ConfigType, DiagramType >
std::set< std::string > m_generated_aliases
 
- Protected Attributes inherited from clanguml::common::generators::generator< ConfigType, DiagramType >
inja::json m_context
 
inja::Environment m_env
 

Constructor & Destructor Documentation

◆ generator()

clanguml::package_diagram::generators::mermaid::generator::generator ( diagram_config config,
diagram_model model 
)

Definition at line 28 of file package_diagram_generator.cc.

29 : common_generator<diagram_config, diagram_model>{config, model}
31{
32}

Member Function Documentation

◆ generate()

void clanguml::package_diagram::generators::mermaid::generator::generate ( const package e,
std::ostream &  ostr 
) const

Generate diagram package element.

Parameters
pPackage diagram element
parentOutput stream

Definition at line 76 of file package_diagram_generator.cc.

77{
79
80 LOG_DBG("Generating package {}", p.name());
81
83
84 const auto &uns = config().using_namespace();
85
86 // Don't generate packages from namespaces filtered out by
87 // using_namespace
88 if (!uns.starts_with({p.full_name(false)})) {
89 ostr << indent(1) << "subgraph " << p.alias() << "["
90 << display_name_adapter(p).with_packages().name() << "]\n";
91
92 if (p.is_deprecated())
93 ostr << indent(1) << "%% <<deprecated>>\n";
94 }
95
96 for (const auto &subpackage : p) {
97 auto &pkg = dynamic_cast<package &>(*subpackage);
98 auto together_group = config().get_together_group(pkg.full_name(false));
99 if (together_group) {
100 together_group_stack_.group_together(together_group.value(), &pkg);
101 }
102 else {
103 generate(pkg, ostr);
104 }
105 }
106
107 generate_groups(ostr);
108
109 if (!uns.starts_with({p.full_name(false)})) {
110 ostr << indent(1) << "end" << '\n';
111 }
112
113 if (config().generate_links) {
115 }
116
117 generate_notes(ostr, p);
118
119 together_group_stack_.leave();
120}

◆ generate_diagram()

void clanguml::package_diagram::generators::mermaid::generator::generate_diagram ( std::ostream &  ostr) const
overridevirtual

Main generator method.

This method is called first and coordinates the entire diagram generation.

Parameters
ostrOutput stream.

Implements clanguml::common::generators::mermaid::generator< ConfigType, DiagramType >.

Definition at line 155 of file package_diagram_generator.cc.

156{
157 for (const auto &p : model()) {
158 auto &pkg = dynamic_cast<package &>(*p);
159 auto together_group = config().get_together_group(pkg.full_name(false));
160 if (together_group) {
161 together_group_stack_.group_together(together_group.value(), &pkg);
162 }
163 else {
164 generate(pkg, ostr);
165 }
166 }
167
168 generate_groups(ostr);
169
170 // Process package relationships
171 for (const auto &p : model()) {
172 generate_relationships(dynamic_cast<package &>(*p), ostr);
173 }
174}

◆ generate_diagram_type()

void clanguml::package_diagram::generators::mermaid::generator::generate_diagram_type ( std::ostream &  ostr) const
overridevirtual

Generate the diagram type.

Parameters
ostrOutput stream

Implements clanguml::common::generators::mermaid::generator< ConfigType, DiagramType >.

Definition at line 34 of file package_diagram_generator.cc.

35{
36 ostr << "flowchart\n";
37}

◆ generate_groups()

void clanguml::package_diagram::generators::mermaid::generator::generate_groups ( std::ostream &  ostr) const

Generate package elements grouped using together MermaidJS tag.

Parameters
ostrOutput stream

Definition at line 122 of file package_diagram_generator.cc.

123{
124 for (const auto &[group_name, group_elements] :
125 together_group_stack_.get_current_groups()) {
126 ostr << indent(1) << "%% together group - not rendered in MermaidJS \n";
127
128 for (auto *pkg : group_elements) {
129 generate(*pkg, ostr);
130 }
131
132 ostr << indent(1) << "%% end together group\n";
133 }
134}

◆ generate_notes()

void clanguml::package_diagram::generators::mermaid::generator::generate_notes ( std::ostream &  ostr,
const common::model::diagram_element element 
) const
overridevirtual

Generate notes attached to packages.

Parameters
ostrOutput stream
elementElement with a note

Reimplemented from clanguml::common::generators::mermaid::generator< ConfigType, DiagramType >.

Definition at line 136 of file package_diagram_generator.cc.

138{
139 const auto &config =
141
142 for (const auto &decorator : element.decorators()) {
143 auto note = std::dynamic_pointer_cast<decorators::note>(decorator);
144 if (note && note->applies_to_diagram(config.name)) {
145 auto note_id_str = fmt::format("N_{}", note_id_++);
146
147 ostr << indent(1) << note_id_str << "(" << note->text << ")\n";
148
149 ostr << indent(1) << note_id_str << "-.-" << element.alias()
150 << '\n';
151 }
152 }
153}

◆ generate_relationships()

void clanguml::package_diagram::generators::mermaid::generator::generate_relationships ( const package p,
std::ostream &  ostr 
) const

Generate relationships originating from package p

Parameters
pDiagram element
parentOutput stream

Definition at line 39 of file package_diagram_generator.cc.

41{
42 LOG_DBG("Generating relationships for package {}", p.full_name(true));
43
44 // Generate this packages relationship
45 if (model().should_include(relationship_t::kDependency)) {
46 for (const auto &r : p.relationships()) {
47 std::stringstream relstr;
48 try {
49 auto destination_package = model().get(r.destination());
50
51 if (!destination_package)
52 continue;
53
54 auto destination_alias = model().to_alias(r.destination());
55 if (!destination_alias.empty()) {
56 relstr << p.alias() << " -.-> " << destination_alias
57 << '\n';
58 ostr << indent(1) << relstr.str();
59 }
60 }
61 catch (error::uml_alias_missing &e) {
62 LOG_DBG("=== Skipping dependency relation from {} to {} due "
63 "to: {}",
64 p.full_name(false), r.destination(), e.what());
65 }
66 }
67 }
68
69 // Process it's subpackages relationships
70 for (const auto &subpackage : p) {
72 dynamic_cast<const package &>(*subpackage), ostr);
73 }
74}

Member Data Documentation

◆ note_id_

uint64_t clanguml::package_diagram::generators::mermaid::generator::note_id_ {0UL}
mutableprivate

Definition at line 109 of file package_diagram_generator.h.

◆ together_group_stack_

common::generators::nested_element_stack<common::model::package> clanguml::package_diagram::generators::mermaid::generator::together_group_stack_
mutableprivate

Definition at line 111 of file package_diagram_generator.h.


The documentation for this class was generated from the following files: