Yourls: Negative values in statistics graph

Created on 21 Feb 2017  路  6Comments  路  Source: YOURLS/YOURLS

More just funny than a bug to really go after:
image

Most helpful comment

Just as additional info.

It's call Spline Interpolation.
In the graph, is used when curveType is declared as function.

As a workaround, a simple plugin can be created to override yourls_stats_line function (_pre_stats_line action_)
and set one of the following:

  1. Render lines instead of curves... _(line need just two points, so no negative value is render)_

    • "curveType" => "none" L184
  2. Add viewWindow: {min:0} in vAxis. This will _crop_ the graph at the bottom, so you don't _see_ the negative curve (even if exist, but be aware that also will hide legend at the bottom)

    • "vAxis" => "{viewWindow: {min:0}, minValue: -0.5, format: '#'}" L188

All 6 comments

It's just the way the Google API draw things.

Just as additional info.

It's call Spline Interpolation.
In the graph, is used when curveType is declared as function.

As a workaround, a simple plugin can be created to override yourls_stats_line function (_pre_stats_line action_)
and set one of the following:

  1. Render lines instead of curves... _(line need just two points, so no negative value is render)_

    • "curveType" => "none" L184
  2. Add viewWindow: {min:0} in vAxis. This will _crop_ the graph at the bottom, so you don't _see_ the negative curve (even if exist, but be aware that also will hide legend at the bottom)

    • "vAxis" => "{viewWindow: {min:0}, minValue: -0.5, format: '#'}" L188

Wow, thanks @gmolop, very clear and interesting additional info! 馃 馃憤

Will implement that, thanks

I played with the different options but alas I think the tradeoff of not having "negative" values isn't worth it: labels are printed over the chart instead of below the axis, which is IMO less readable.

For the record, I'll wrap @gmolop's solution as a plugin :

<?php
/*
Plugin Name: No Negs In Graphs
Description: No negative values in graphs
Version: 0.1
Author: Ozh
*/

// No direct call
if( !defined( 'YOURLS_ABSPATH' ) ) die();

yourls_add_filter( 'stats_line_options', 'gmolop_no_negative_values_on_charts' );
function gmolop_no_negative_values_on_charts( $in ) {
    $in['curveType'] = 'none';
    $in['vAxis']     = "{viewWindow: {min:0}, minValue: -0.5, format: '#'}";
    return($in);
}

Thanks @ozh,
Actually there's no need to set both, just choose one of:

curvType to none will render straight lines. (Clean and without negative values)

Or...

vAxis options will crop the visible graph area to hide the existent negative value, that's why the graph get messy with the legend. (don't like it either)

I think/recommend if the negative curve really bother, go with the first option and left the second only if you want to play with the chart legend and redesign the positions.

Was this page helpful?
0 / 5 - 0 ratings