Skip to content

Commit

Permalink
Graph: set max slices in Categories pie chart
Browse files Browse the repository at this point in the history
When there is a large number of Categories defined in the system, the
By Category pie chart is cramped and difficult to read.

This sets a (hardcoded for now) limit on the number of slices, and
regroups all the remaining categories under an "others" slice.

Fixes #25522
  • Loading branch information
dregad committed Mar 2, 2019
1 parent b7d7eca commit c106454
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/MantisGraph/lang/strings_english.txt
Expand Up @@ -88,3 +88,4 @@ $s_plugin_MantisGraph_graph_page = 'Graph Issue History';
$s_plugin_MantisGraph_graph_topdev = 'Top Developers by Fixed Issues';
$s_plugin_MantisGraph_graph_opendev = 'Developers by Open Issues';
$s_plugin_MantisGraph_graph_topreporter_fixed = 'Top Reporters by Fixed Issues';
$s_plugin_MantisGraph_other_categories = 'other categories (%d)';
24 changes: 23 additions & 1 deletion plugins/MantisGraph/pages/category_graph.php
Expand Up @@ -38,6 +38,28 @@

# Dynamically set width ratio between 1 and 0.25 based on number of categories
$t_wfactor = 1 - min( max( count( $t_metrics ), 25 ) - 25, 75 ) / 100;

# Set the maximum number of pie slices displayed and aggregate the rest into
# an "others" category if needed. The number of slices should not be higher
# than the number of available colors in the palette.
$t_num_slices = 20;
$t_pie_metrics = array_slice( $t_metrics, 0, $t_num_slices );
if( count( $t_metrics ) > $t_num_slices ) {
$t_num_slices--;

# Remove last element and replace it with "others"
array_pop( $t_pie_metrics );
$t_others = sprintf(
plugin_lang_get( 'other_categories' ),
count( $t_metrics ) - $t_num_slices
);
$t_pie_metrics[$t_others] = 0;

# Sum remaining categories into "others" slice
foreach( array_slice( $t_metrics, $t_num_slices ) as $t_value ) {
$t_pie_metrics[$t_others] += $t_value;
}
}
?>

<div class="col-md-12 col-xs-12">
Expand All @@ -56,7 +78,7 @@
</div>

<div class="col-md-6 col-xs-12">
<?php graph_pie( $t_metrics ); ?>
<?php graph_pie( $t_pie_metrics ); ?>
</div>
</div>
</div>
Expand Down

0 comments on commit c106454

Please sign in to comment.