This gallery example demonstrates creating an interactive hierarchical treemap using Plotly.cpp to visualize corporate organizational structures. Treemaps excel at showing hierarchical data with proportional area representation, making it ideal for organizational analysis and resource allocation visualization.
The treemap provides immediate visual understanding of organizational structure, team sizes, and departmental resource distribution, making it valuable for HR analytics and organizational planning.
#include <string>
#include <vector>
auto main(
int argc,
char *argv[]) ->
int {
std::vector<std::string> labels = {
"Company", "Engineering", "Sales", "Marketing", "HR",
"Frontend", "Backend", "DevOps", "QA", "Enterprise",
"SMB", "International", "Digital", "Content", "PR",
"Recruiting", "Training", "Compliance"};
std::vector<std::string> parents = {"",
"Company",
"Company",
"Company",
"Company",
"Engineering",
"Engineering",
"Engineering",
"Engineering",
"Sales",
"Sales",
"Sales",
"Marketing",
"Marketing",
"Marketing",
"HR",
"HR",
"HR"};
std::vector<double> values = {
275,
120, 80, 45, 30,
35, 45, 25, 15,
30, 35, 15,
20, 15, 10,
12, 10, 8
};
std::vector<std::string> descriptions = {
"Total Organization", "Software Development", "Revenue Generation",
"Brand & Growth", "People Operations", "UI/UX Development",
"Server & Database", "Infrastructure", "Quality Assurance",
"Large Enterprise", "Small-Medium Business", "Global Markets",
"Online Marketing", "Content Creation", "Public Relations",
"Talent Acquisition", "Employee Development", "Legal & Policy"};
{"type", "treemap"},
{"labels", labels},
{"parents", parents},
{"values", values},
{"text", descriptions},
{"textinfo", "label+value+percent parent+percent entry"},
{"textfont", {{"size", 12}}},
{"marker",
{{"colorscale", "Viridis"},
{"colorbar", {{"title", "Team Size"}, {"titleside", "right"}}},
{"line", {{"width", 2}}}}},
{"hovertemplate", "<b>%{label}</b><br>" +
std::string("Team Size: %{value} people<br>") +
"%{text}<br>" + "<extra></extra>"},
{"maxdepth", 3},
{"branchvalues", "total"},
{"pathbar", {{"visible", false}}}};
{"title",
{{"text",
"Corporate Organization Structure<br>" +
std::string("<sub>Hierarchical Treemap by Team Size</sub>")},
{"font", {{"size", 18}}}}},
{"width", 1000},
{"height", 700},
{"margin", {{"l", 10}, {"r", 10}, {"t", 80}, {"b", 10}}},
{"annotations",
{{{"text", "Click on segments to drill down into departments"},
{"x", 0.5},
{"y", -0.05},
{"xref", "paper"},
{"yref", "paper"},
{"showarrow", false},
{"font", {{"size", 12}}}}}}};
std::vector<plotly::Object> data = {trace};
if (!args.headless) {
} else {
{"width", 1000},
{"height", 700},
{"filename", "treemap_hierarchy"}};
}
return 0;
}
auto parseGalleryArgs(int argc, char *argv[]) -> GalleryArgs
Parse command line arguments for gallery examples.
Definition arg_parser.cpp:4
auto main() -> int
Definition gallery_animate_sin_wave.cpp:48
nlohmann::json Object
Definition plotly.hpp:26
Public Plotly C++ API header.