Skip to content

Commit

Permalink
Added initial support for MermaidJS sequence diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
bkryza committed Sep 7, 2023
1 parent 084bb20 commit 32fda88
Show file tree
Hide file tree
Showing 43 changed files with 956 additions and 23 deletions.
14 changes: 1 addition & 13 deletions src/class_diagram/generators/mermaid/class_diagram_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,14 @@
namespace clanguml::class_diagram::generators::mermaid {

using clanguml::common::generators::mermaid::indent;
using clanguml::common::generators::mermaid::render_name;

generator::generator(diagram_config &config, diagram_model &model)
: common_generator<diagram_config, diagram_model>{config, model}
, together_group_stack_{true}
{
}

std::string generator::render_name(std::string name) const
{
util::replace_all(name, "<", "&lt;");
util::replace_all(name, ">", "&gt;");
util::replace_all(name, "(", "&lpar;");
util::replace_all(name, ")", "&rpar;");
util::replace_all(name, "##", "::");
util::replace_all(name, "{", "&lbrace;");
util::replace_all(name, "}", "&rbrace;");

return name;
}

void generator::generate_alias(
const common::model::element &c, std::ostream &ostr) const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ class generator : public common_generator<diagram_config, diagram_model> {
const std::vector<std::string> method_groups_{
"constructors", "assignment", "operators", "other"};

std::string render_name(std::string name) const;

template <typename T>
void sort_class_elements(std::vector<T> &elements) const
{
Expand Down
11 changes: 6 additions & 5 deletions src/common/generators/generators.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "package_diagram/generators/json/package_diagram_generator.h"
#include "package_diagram/generators/plantuml/package_diagram_generator.h"
#include "sequence_diagram/generators/json/sequence_diagram_generator.h"
#include "sequence_diagram/generators/mermaid/sequence_diagram_generator.h"
#include "sequence_diagram/generators/plantuml/sequence_diagram_generator.h"
#include "util/util.h"
#include "version.h"
Expand Down Expand Up @@ -168,11 +169,11 @@ struct diagram_generator_t<clanguml::config::class_diagram,
mermaid_generator_tag> {
using type = clanguml::class_diagram::generators::mermaid::generator;
};
// template <>
// struct diagram_generator_t<clanguml::config::sequence_diagram,
// mermaid_generator_tag> {
// using type = clanguml::sequence_diagram::generators::mermaid::generator;
// };
template <>
struct diagram_generator_t<clanguml::config::sequence_diagram,
mermaid_generator_tag> {
using type = clanguml::sequence_diagram::generators::mermaid::generator;
};
// template <>
// struct diagram_generator_t<clanguml::config::package_diagram,
// mermaid_generator_tag> {
Expand Down
16 changes: 14 additions & 2 deletions src/common/generators/mermaid/generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ std::string to_mermaid(message_t r)
{
switch (r) {
case message_t::kCall:
return "->";
return "->>";
case message_t::kReturn:
return "-->";
return "-->>";
default:
return "";
}
Expand All @@ -78,4 +78,16 @@ std::string indent(const unsigned level)
return std::string(level * kIndentWidth, ' ');
}

std::string render_name(std::string name)
{
util::replace_all(name, "<", "&lt;");
util::replace_all(name, ">", "&gt;");
util::replace_all(name, "(", "&lpar;");
util::replace_all(name, ")", "&rpar;");
util::replace_all(name, "##", "::");
util::replace_all(name, "{", "&lbrace;");
util::replace_all(name, "}", "&rbrace;");

return name;
}
} // namespace clanguml::common::generators::mermaid
2 changes: 2 additions & 0 deletions src/common/generators/mermaid/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ std::string to_mermaid(message_t r);

std::string indent(const unsigned level);

std::string render_name(std::string name);

/**
* @brief Base class for diagram generators
*
Expand Down
Loading

0 comments on commit 32fda88

Please sign in to comment.