52 std::vector<double>
const& values,
53 std::vector<Color>
const& colors,
60 if( values.size() == 0 ) {
61 throw std::runtime_error(
"No values given to make svg pie chart" );
63 if( colors.size() == 0 ) {
64 throw std::runtime_error(
"No colors given to make svg pie chart" );
66 if( colors.size() < values.size() ) {
67 throw std::runtime_error(
68 "No enough colors given to make svg pie chart. Given " +
73 auto const all_good = std::all_of( values.cbegin(), values.cend(), [](
double v ){
74 return std::isfinite(v) && v >= 0.0;
77 throw std::runtime_error(
78 "Invalid negative or non-finite values given to make svg pie chart"
84 double const total = std::accumulate( values.begin(), values.end(), 0.0 );
85 double const dir = clockwise ? 1.0 : -1.0;
89 for(
size_t i = 0; i < values.size(); ++i ) {
90 if( values[i] == 0.0 ) {
97 auto const angle = 2.0 *
utils::PI * values[i] / total;
98 auto start_a = start_angle + dir *
sum;
99 auto end_a = start_angle + dir * (
sum + angle );
107 assert( i < colors.size() );
109 {{
svg_arc( 0, 0, radius, start_a, end_a,
true ) }},