Added 'title' diagram property

This commit is contained in:
Bartek Kryza
2023-10-09 13:53:14 +02:00
parent 03bd5ada31
commit 8a6b497cc9
52 changed files with 173 additions and 66 deletions

View File

@@ -110,6 +110,9 @@ void generator<C, D>::generate(std::ostream &ostr) const
nlohmann::json j;
j["name"] = generators::generator<C, D>::model().name();
j["diagram_type"] = to_string(generators::generator<C, D>::model().type());
if (generators::generator<C, D>::config().title) {
j["title"] = generators::generator<C, D>::config().title();
}
generate_diagram(j);

View File

@@ -136,6 +136,16 @@ public:
*/
void generate_metadata(std::ostream &ostr) const;
/**
* @brief Generate diagram title
*
* Generates a MermaidJS diagram title directive if diagram title
* is provided in the diagram configuration.
*
* @param ostr Output stream
*/
void generate_title(std::ostream &ostr) const;
/**
* @brief Generate hyper link to element
*
@@ -238,6 +248,8 @@ void generator<C, D>::generate(std::ostream &ostr) const
update_context();
generate_title(ostr);
generate_diagram_type(ostr);
generate_mermaid_directives(ostr, config.mermaid().before);
@@ -399,6 +411,18 @@ void generator<C, D>::generate_metadata(std::ostream &ostr) const
}
}
template <typename C, typename D>
void generator<C, D>::generate_title(std::ostream &ostr) const
{
const auto &config = generators::generator<C, D>::config();
if (config.title) {
ostr << "---\n";
ostr << "title: " << config.title() << '\n';
ostr << "---\n";
}
}
template <typename C, typename D>
void generator<C, D>::print_debug(
const common::model::source_location &e, std::ostream &ostr) const

View File

@@ -131,6 +131,16 @@ public:
*/
void generate_metadata(std::ostream &ostr) const;
/**
* @brief Generate diagram title
*
* Generates a PlantUML diagram title directive if diagram title
* is provided in the diagram configuration.
*
* @param ostr Output stream
*/
void generate_title(std::ostream &ostr) const;
/**
* @brief Generate hyper link to element
*
@@ -241,6 +251,8 @@ void generator<C, D>::generate(std::ostream &ostr) const
ostr << "@startuml" << '\n';
generate_title(ostr);
generate_plantuml_directives(ostr, config.puml().before);
generate_diagram(ostr);
@@ -449,6 +461,16 @@ void generator<C, D>::generate_metadata(std::ostream &ostr) const
}
}
template <typename C, typename D>
void generator<C, D>::generate_title(std::ostream &ostr) const
{
const auto &config = generators::generator<C, D>::config();
if (config.title) {
ostr << "title " << config.title() << '\n';
}
}
template <typename C, typename D>
template <typename E>
void generator<C, D>::generate_link(std::ostream &ostr, const E &e) const

View File

@@ -537,6 +537,8 @@ struct diagram : public inheritable_diagram_options {
void initialize_type_aliases();
std::string name;
option<std::string> title{"title"};
};
/**

View File

@@ -156,6 +156,7 @@ types:
relative_to: !optional string
using_namespace: !optional [string, [string]]
generate_metadata: !optional bool
title: !optional string
#
# Class diagram specific options
#
@@ -192,6 +193,7 @@ types:
relative_to: !optional string
using_namespace: !optional [string, [string]]
generate_metadata: !optional bool
title: !optional string
#
# Sequence diagram specific options
#
@@ -226,6 +228,7 @@ types:
relative_to: !optional string
using_namespace: !optional [string, [string]]
generate_metadata: !optional bool
title: !optional string
#
# Package diagram specific options
#
@@ -254,6 +257,7 @@ types:
relative_to: !optional string
using_namespace: !optional [string, [string]]
generate_metadata: !optional bool
title: !optional string
#
# Include diagram specific options
#

View File

@@ -551,6 +551,7 @@ template <typename T> bool decode_diagram(const Node &node, T &rhs)
get_option(node, rhs.comment_parser);
get_option(node, rhs.debug_mode);
get_option(node, rhs.generate_metadata);
get_option(node, rhs.title);
return true;
}

View File

@@ -297,7 +297,9 @@ YAML::Emitter &operator<<(
out << c.using_namespace;
out << c.generate_metadata;
if (dynamic_cast<const class_diagram *>(&c) != nullptr) {
if (const auto *cd = dynamic_cast<const class_diagram *>(&c);
cd != nullptr) {
out << cd->title;
out << c.generate_method_arguments;
out << c.generate_packages;
out << c.include_relations_also_as_members;
@@ -315,18 +317,24 @@ YAML::Emitter &operator<<(
out << c.generate_template_argument_dependencies;
out << c.skip_redundant_dependencies;
}
else if (dynamic_cast<const sequence_diagram *>(&c) != nullptr) {
else if (const auto *sd = dynamic_cast<const sequence_diagram *>(&c);
sd != nullptr) {
out << sd->title;
out << c.combine_free_functions_into_file_participants;
out << c.generate_condition_statements;
out << c.generate_method_arguments;
out << c.generate_return_types;
out << c.participants_order;
}
else if (dynamic_cast<const package_diagram *>(&c) != nullptr) {
else if (const auto *pd = dynamic_cast<const package_diagram *>(&c);
pd != nullptr) {
out << pd->title;
out << c.generate_packages;
out << c.package_type;
}
else if (dynamic_cast<const include_diagram *>(&c) != nullptr) {
else if (const auto *id = dynamic_cast<const include_diagram *>(&c);
id != nullptr) {
out << id->title;
out << c.generate_system_headers;
}