-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgallery_polar_radar_chart.cpp
More file actions
151 lines (133 loc) 路 4.9 KB
/
Copy pathgallery_polar_radar_chart.cpp
File metadata and controls
151 lines (133 loc) 路 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* @file gallery_polar_radar_chart.cpp
* @brief Multi-Product Performance Comparison Radar Chart
* @author plotly.cpp contributors
* @date 2025
*
* @example gallery_polar_radar_chart.cpp
* This gallery example demonstrates creating an interactive radar (spider)
chart
* using Plotly.cpp's polar coordinate system. It compares multiple products
across
* various performance dimensions, making it ideal for competitive analysis and
* multi-criteria decision making.
*
* Features demonstrated:
* - Polar coordinate system with radial and angular axis configuration
* - Multiple overlapping filled polygons for product comparison
* - Custom color scheme with transparency for overlapping areas
* - Interactive legend with product selection/deselection
* - Radial axis with custom range, tick intervals, and grid styling
* - Angular axis rotation and direction control
* - Detailed hover templates showing performance metrics
* - Responsive layout with annotations and custom margins
*
* Performance dimensions analyzed:
* - Performance, Reliability, Security, Usability
* - Scalability, Maintainability, Documentation, Support
*
* The radar chart enables quick visual comparison of strengths and weaknesses
* across different products, making patterns and trade-offs easily
identifiable.
*
* @image html polar_radar_chart.png "Multi-Product Performance Radar Chart"
*
* @date 2024
*/
#include "plotly/plotly.hpp"
#include "utils/arg_parser.hpp"
#include <cstddef>
#include <string>
#include <vector>
auto main(int argc, char *argv[]) -> int {
// Parse command line arguments
auto args = parseGalleryArgs(argc, argv);
plotly::Figure fig;
fig.openBrowser(args.headless);
// Define performance categories
std::vector<std::string> categories = {
"Performance", "Reliability", "Security", "Usability",
"Scalability", "Maintainability", "Documentation", "Support"};
// Performance data for different products/systems
std::vector<std::vector<double>> performanceData = {
{8.5, 9.2, 7.8, 8.9, 7.5, 8.1, 6.8, 8.7}, // Product A
{7.2, 8.1, 9.5, 7.6, 8.8, 7.9, 8.5, 7.3}, // Product B
{9.1, 7.8, 8.4, 9.3, 6.9, 9.2, 9.0, 8.2}, // Product C
{6.8, 8.9, 7.2, 8.5, 9.1, 7.4, 7.8, 9.0} // Product D
};
std::vector<std::string> productNames = {"Product A", "Product B",
"Product C", "Product D"};
std::vector<std::string> colors = {
"rgba(255, 0, 0, 0.6)", // Red
"rgba(0, 255, 0, 0.6)", // Green
"rgba(0, 0, 255, 0.6)", // Blue
"rgba(255, 165, 0, 0.6)" // Orange
};
std::vector<std::string> lineColors = {"red", "green", "blue", "orange"};
// Create traces for each product
std::vector<plotly::Object> traces;
for (size_t i = 0; i < performanceData.size(); i++) {
// Close the polygon by adding first point at the end
std::vector<double> values = performanceData[i];
std::vector<std::string> theta = categories;
values.push_back(values[0]);
theta.push_back(categories[0]);
plotly::Object trace = {
{"type", "scatterpolar"},
{"r", values},
{"theta", theta},
{"fill", "toself"},
{"name", productNames[i]},
{"line", {{"color", lineColors[i]}, {"width", 3}}},
{"marker", {{"color", colors[i]}, {"size", 8}}},
{"fillcolor", colors[i]},
{"hovertemplate",
productNames[i] + "<br>%{theta}: %{r:.1f}<extra></extra>"}};
traces.push_back(trace);
}
// Create layout with polar configuration
plotly::Object layout = {
{"title",
{{"text", "Product Performance Comparison<br>" +
std::string("<sub>Multi-dimensional Radar Chart</sub>")},
{"font", {{"size", 18}}}}},
{"polar",
{{"radialaxis",
{{"visible", true},
{"range", {0, 10}},
{"tickmode", "linear"},
{"tick0", 0},
{"dtick", 2},
{"showticklabels", true},
{"tickfont", {{"size", 12}}},
{"gridcolor", "lightgray"}}},
{"angularaxis",
{{"tickfont", {{"size", 14}}},
{"rotation", 90},
{"direction", "counterclockwise"}}}}},
{"width", 800},
{"height", 700},
{"showlegend", true},
{"legend", {{"x", 1.05}, {"y", 1.0}}},
{"annotations",
{{{"text", "Scale: 0 (Poor) to 10 (Excellent)"},
{"x", 0.5},
{"y", -0.1},
{"xref", "paper"},
{"yref", "paper"},
{"showarrow", false},
{"font", {{"size", 12}}}}}}};
// Create the plot
fig.newPlot(traces, layout);
if (!args.headless) {
fig.waitClose();
} else {
// Save image instead of opening browser
plotly::Object imageOpts = {{"format", "png"},
{"width", 800},
{"height", 700},
{"filename", "polar_radar_chart"}};
fig.downloadImage(imageOpts);
}
return 0;
}