Added layout hints config option to package diagrams

This commit is contained in:
Bartek Kryza
2022-02-14 22:51:29 +01:00
parent fd7d916e3e
commit 5835f230e4
4 changed files with 51 additions and 15 deletions

View File

@@ -409,6 +409,8 @@ template <> struct convert<package_diagram> {
if (!decode_diagram(node, rhs)) if (!decode_diagram(node, rhs))
return false; return false;
get_option(node, rhs.layout);
return true; return true;
} }
}; };

View File

@@ -135,6 +135,8 @@ struct package_diagram : public diagram {
virtual ~package_diagram() = default; virtual ~package_diagram() = default;
diagram_type type() const override; diagram_type type() const override;
option<layout_hints> layout{"layout"};
}; };
struct config : public inheritable_diagram_options { struct config : public inheritable_diagram_options {

View File

@@ -83,22 +83,39 @@ TEST_CASE("Test config layout", "[unit-test]")
{ {
auto cfg = clanguml::config::load("./test_config_data/layout.yml"); auto cfg = clanguml::config::load("./test_config_data/layout.yml");
CHECK(cfg.diagrams.size() == 1); CHECK(cfg.diagrams.size() == 2);
auto &def = static_cast<clanguml::config::class_diagram &>( auto &def = static_cast<clanguml::config::class_diagram &>(
*cfg.diagrams["class_main"]); *cfg.diagrams["class_main"]);
CHECK(def.type() == clanguml::config::diagram_type::class_diagram);
CHECK(def.layout().at("ABCD").size() == 2); auto check_layout = [](const auto &diagram,
CHECK(def.layout().at("ABCD")[0].hint == clanguml::config::hint_t::up); const clanguml::config::diagram_type type) {
CHECK(def.layout().at("ABCD")[0].entity == "ABCD_SUBCLASS"); CHECK(diagram.type() == type);
CHECK(def.layout().at("ABCD")[1].hint == clanguml::config::hint_t::left);
CHECK(def.layout().at("ABCD")[1].entity == "ABCD_SIBLING");
CHECK(def.layout().at("ABCD_SIBLING").size() == 2); CHECK(diagram.layout().at("ABCD").size() == 2);
CHECK(def.layout().at("ABCD_SIBLING")[0].hint == CHECK(diagram.layout().at("ABCD")[0].hint ==
clanguml::config::hint_t::right); clanguml::config::hint_t::up);
CHECK(def.layout().at("ABCD_SIBLING")[0].entity == "ABCD_OTHER_SIBLING"); CHECK(diagram.layout().at("ABCD")[0].entity == "ABCD_SUBCLASS");
CHECK(def.layout().at("ABCD_SIBLING")[1].hint == CHECK(diagram.layout().at("ABCD")[1].hint ==
clanguml::config::hint_t::down); clanguml::config::hint_t::left);
CHECK(def.layout().at("ABCD_SIBLING")[1].entity == "ABCD_SIBLING_SIBLING"); CHECK(diagram.layout().at("ABCD")[1].entity == "ABCD_SIBLING");
CHECK(diagram.layout().at("ABCD_SIBLING").size() == 2);
CHECK(diagram.layout().at("ABCD_SIBLING")[0].hint ==
clanguml::config::hint_t::right);
CHECK(diagram.layout().at("ABCD_SIBLING")[0].entity ==
"ABCD_OTHER_SIBLING");
CHECK(diagram.layout().at("ABCD_SIBLING")[1].hint ==
clanguml::config::hint_t::down);
CHECK(diagram.layout().at("ABCD_SIBLING")[1].entity ==
"ABCD_SIBLING_SIBLING");
};
check_layout(static_cast<clanguml::config::class_diagram &>(
*cfg.diagrams["class_main"]),
clanguml::config::diagram_type::class_diagram);
check_layout(static_cast<clanguml::config::package_diagram &>(
*cfg.diagrams["package_main"]),
clanguml::config::diagram_type::package_diagram);
} }

View File

@@ -19,4 +19,19 @@ diagrams:
include: include:
namespaces: namespaces:
- clanguml - clanguml
- ABCD - ABCD
package_main:
type: package
glob:
- src/**/*.cc
- src/**/*.h
using_namespace:
- clanguml
generate_method_arguments: full
layout:
ABCD:
- up: ABCD_SUBCLASS
- left: ABCD_SIBLING
ABCD_SIBLING:
- right: ABCD_OTHER_SIBLING
- down: ABCD_SIBLING_SIBLING