Skip to content

Commit

Permalink
MantisGraph, adjust width of some graphs.
Browse files Browse the repository at this point in the history
Some graphs pages only display one graph. When they are displayed in the
full page width, the 5:4 aspect ratio doesn't fit in the usual screen
sizes.
Make them double wide, but keep the height, to mantain the constant fill
area similar to those pages with side by side graphs.
  • Loading branch information
cproensa authored and dregad committed Feb 14, 2019
1 parent 8ca3afc commit fad38bb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
28 changes: 24 additions & 4 deletions plugins/MantisGraph/core/graph_api.php
Expand Up @@ -128,20 +128,32 @@ function graph_status_colors_to_colors() {
* @param string $p_title Title.
* @param string $p_series_name The name of the data series.
* @param string $p_color The bar color.
* @param integer $p_wfactor Width factor for graph chart. Eg: 2 to make it double wide
* @return void
*/
function graph_bar( array $p_metrics, $p_title = '', $p_series_name, $p_color = '#fcbdbd' ) {
function graph_bar( array $p_metrics, $p_title = '', $p_series_name, $p_color = null, $p_wfactor = null ) {
static $s_id = 0;

# set defaults
if( !$p_color ) {
$p_color = '#fcbdbd';
}
if( !$p_wfactor ) {
$p_wfactor = 1;
}

$s_id++;
$t_labels = array_keys( $p_metrics );
$t_js_labels = graph_strings_array( $t_labels );

$t_values = array_values( $p_metrics );
$t_js_values = graph_numeric_array( $t_values );

$t_width = 500 * $p_wfactor;
$t_height = 400;

?>
<canvas id="barchart<?php echo $s_id ?>" width="500" height="400"
<canvas id="barchart<?php echo $s_id ?>" width="<?php echo $t_width ?>" height="<?php echo $t_height ?>"
data-labels="[<?php echo htmlspecialchars( $t_js_labels, ENT_QUOTES ) ?>]"
data-values="[<?php echo $t_js_values ?>]" />
<?php
Expand Down Expand Up @@ -181,11 +193,17 @@ function graph_pie( array $p_metrics, $p_title = '' ) {
* Cumulative line graph
*
* @param array $p_metrics Graph Data.
* @param integer $p_wfactor Width factor for graph chart. Eg: 2 to make it double wide
* @return void
*/
function graph_cumulative_bydate( array $p_metrics ) {
function graph_cumulative_bydate( array $p_metrics, $p_wfactor = null ) {
static $s_id = 0;

# set defaults
if( !$p_wfactor ) {
$p_wfactor = 1;
}

$s_id++;

$t_labels = array_keys( $p_metrics[0] );
Expand All @@ -209,8 +227,10 @@ function graph_cumulative_bydate( array $p_metrics ) {
$t_legend_resolved = plugin_lang_get( 'legend_resolved' );
$t_legend_still_open = plugin_lang_get( 'legend_still_open' );

$t_width = 500 * $p_wfactor;
$t_height = 400;
?>
<canvas id="linebydate<?php echo $s_id ?>" width="500" height="400"
<canvas id="linebydate<?php echo $s_id ?>" width="<?php echo $t_width ?>" height="<?php echo $t_height ?>"
data-labels="[<?php echo htmlspecialchars( $t_js_labels, ENT_QUOTES ) ?>]"
data-opened-label="<?php echo $t_legend_opened ?>"
data-opened-values="[<?php echo $t_opened_values ?>]"
Expand Down
2 changes: 1 addition & 1 deletion plugins/MantisGraph/pages/issues_trend_graph.php
Expand Up @@ -47,7 +47,7 @@
<?php
$t_metrics = create_cumulative_bydate( $t_filter );
if ( $t_metrics != null ) {
graph_cumulative_bydate( $t_metrics );
graph_cumulative_bydate( $t_metrics, 2 /*wfactor*/ );
}
?>
</div>
Expand Down
2 changes: 1 addition & 1 deletion plugins/MantisGraph/pages/reporter_graph.php
Expand Up @@ -55,7 +55,7 @@
</div>
<?php
$t_metrics = create_reporter_summary( $t_filter );
graph_bar( $t_metrics, lang_get( 'by_reporter' ), $t_series_name );
graph_bar( $t_metrics, lang_get( 'by_reporter' ), $t_series_name, null, 2 /*wfactor*/ );
?>
</div>
</div>
Expand Down

0 comments on commit fad38bb

Please sign in to comment.