Added link generation in mermaid diagram generator

This commit is contained in:
Bartek Kryza
2023-09-09 18:41:31 +02:00
parent cfc0a42320
commit 0a542a954b
4 changed files with 65 additions and 33 deletions

View File

@@ -121,6 +121,10 @@ void generator::generate(const class_ &c, std::ostream &ostr) const
ostr << indent(1) << "}" << '\n';
if (config().generate_links) {
common_generator<diagram_config, diagram_model>::generate_link(ostr, c);
}
generate_notes(ostr, c);
for (const auto &member : c.members())
@@ -279,6 +283,10 @@ void generator::generate(const concept_ &c, std::ostream &ostr) const
}
ostr << indent(1) << "}" << '\n';
if (config().generate_links) {
common_generator<diagram_config, diagram_model>::generate_link(ostr, c);
}
}
void generator::generate_member_notes(std::ostream &ostr,
@@ -584,6 +592,10 @@ void generator::generate(const enum_ &e, std::ostream &ostr) const
ostr << indent(1) << "}" << '\n';
if (config().generate_links) {
common_generator<diagram_config, diagram_model>::generate_link(ostr, e);
}
generate_notes(ostr, e);
}

View File

@@ -94,16 +94,6 @@ public:
*/
virtual void generate_diagram(std::ostream &ostr) const = 0;
/**
* @brief Generate diagram layout hints
*
* This method adds to the diagram any layout hints that were provided
* in the configuration file.
*
* @param ostr Output stream
*/
void generate_config_layout_hints(std::ostream &ostr) const;
/**
* @brief Generate MermaidJS directives from config file.
*
@@ -250,34 +240,56 @@ void generator<C, D>::generate(std::ostream &ostr) const
}
template <typename C, typename D>
void generator<C, D>::generate_config_layout_hints(std::ostream &ostr) const
template <typename E>
void generator<C, D>::generate_link(std::ostream &ostr, const E &e) const
{
using namespace clanguml::util;
const auto &config = generators::generator<C, D>::config();
// Generate layout hints
for (const auto &[entity_name, hints] : config.layout()) {
for (const auto &hint : hints) {
try {
if (hint.hint == config::hint_t::together) {
// 'together' layout hint is handled separately
}
else if (hint.hint == config::hint_t::row ||
hint.hint == config::hint_t::column) {
generate_row_column_hints(ostr, entity_name, hint);
}
else {
generate_position_hints(ostr, entity_name, hint);
}
}
catch (clanguml::error::uml_alias_missing &e) {
LOG_DBG("=== Skipping layout hint '{}' from {} due "
"to: {}",
to_string(hint.hint), entity_name, e.what());
}
if (e.file().empty())
return;
if (config.generate_links().link.empty() &&
config.generate_links().tooltip.empty())
return;
ostr << indent(1) << "click " << e.alias() << " href \"";
try {
if (!config.generate_links().link.empty()) {
ostr << env().render(std::string_view{config.generate_links().link},
element_context(e));
}
}
catch (const inja::json::parse_error &e) {
LOG_ERROR(
"Failed to parse Jinja template: {}", config.generate_links().link);
}
catch (const inja::json::exception &e) {
LOG_ERROR("Failed to render PlantUML directive: \n{}\n due to: {}",
config.generate_links().link, e.what());
}
ostr << "\"";
if (!config.generate_links().tooltip.empty()) {
ostr << " \"";
try {
auto tooltip_text =
env().render(std::string_view{config.generate_links().tooltip},
element_context(e));
util::replace_all(tooltip_text, "\"", "&bdquo;");
ostr << tooltip_text;
}
catch (const inja::json::parse_error &e) {
LOG_ERROR("Failed to parse Jinja template: {}",
config.generate_links().link);
}
catch (const inja::json::exception &e) {
LOG_ERROR("Failed to render PlantUML directive: \n{}\n due to: {}",
config.generate_links().link, e.what());
}
ostr << "\"";
}
ostr << "\n";
}
template <typename C, typename D>

View File

@@ -89,6 +89,10 @@ void generator::generate(const source_file &f, std::ostream &ostr) const
m_generated_aliases.emplace(f.alias());
}
}
if (config().generate_links) {
common_generator<diagram_config, diagram_model>::generate_link(ostr, f);
}
}
void generator::generate_notes(

View File

@@ -100,6 +100,10 @@ void generator::generate(const package &p, std::ostream &ostr) const
ostr << indent(1) << "end" << '\n';
}
if (config().generate_links) {
common_generator<diagram_config, diagram_model>::generate_link(ostr, p);
}
generate_notes(ostr, p);
together_group_stack_.leave();