Welcome Guest, Not a member yet? Register   Sign In
CI Google Charts API
#1

[eluser]onecurlyfry[/eluser]
Hey all -

Using the latest Google Charts API in my CI 1.7.2 framework. Pretty rad encoding utility. One small problem.

Here's the short code snippet for the chart helper:

Code:
function extendedencode($data, &$maxvalue='notspecified')
{
    $grid = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
        'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
        'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
        'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
        'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '.');

    // try to find reasonable maximum value
    if(is_numeric(&$maxvalue)){
        // assume below manipulations are better than what caller is doing
        $max = ceil(&$maxvalue);
    } else {
        $max = ceil(max($data));
    }

    $precision = strlen($max) - 1;
    $maxvalue = ceil($max/pow(10,$precision));
    $maxvalue = $maxvalue * pow(10, $precision);

    $multiplier = (float)(count($grid) * count($grid)) / $maxvalue;
    $ret = '';
    for($i=0;$i<count($data);$i++){
        if(!is_numeric($data[$i])){
            $ret .= '__';
        } else {
            $datum = $data[$i] * $multiplier;
            $x = (int)($datum / count($grid));
            $y = $datum % 64;
            $ret .= $grid[$x].$grid[$y];
        }
    }
    return $ret;
}
I'm getting intermittent offset errors where the offset is set to 64. Obviously in a 64 item, 0-based array, $i[64] doesn't exist. Any thoughts on how to fix this?

Scott




Theme © iAndrew 2016 - Forum software by © MyBB