Adrielpin / gchartphp

Automatically exported from code.google.com/p/gchartphp
0 stars 0 forks source link

Simple Encoder Written in PHP #6

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Here's a simple encoder that I ported to PHP from the JavaScript example 
included in the Chart documentation.  Thought it would be a nice feature 
to add to your tool.

     --eric(dot]martin{at}3jane[dot)com--

/**
 * Encodes a dataset for use in Google Charts
 */
private static function __simpleEncode( $valueArray, $maxValue )
{
    $enc  = split
(',','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');
    $data = array('s:');
    foreach( $valueArray as $curr )
    {
        if ( isset($curr) && $curr >= 0)
        {
            $index  = round( (count($enc)-1) * $curr / 
$maxValue);
            $data[] = $enc[$index];
        }
        else
        {
            $data[] = '_';
        }
    }
    return implode('',$data);
}

Original issue reported on code.google.com by elmartin...@gmail.com on 30 Jan 2008 at 7:58

GoogleCodeExporter commented 8 years ago
PS: I would have sent this directly to the developers if I could have.  It 
didn't 
seem like something that should go in the WIKI... so I opened an issue thinking 
this 
was basically the best place to put the code.

Original comment by elmartin...@gmail.com on 30 Jan 2008 at 11:30

GoogleCodeExporter commented 8 years ago
     --eric(dot]martin{at}3jane[dot)com--
     --ibrahim[dot]yilmaz{at}karmabilisim[dot]com-- //Added Turkish characters
/**
 * Encodes a dataset for use in Google Charts
 */
private static function __simpleEncode( $valueArray, $maxValue )
{
    $enc  = split
(',','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');
    $data = array('s:');
    foreach( $valueArray as $curr )
    {
        if ( isset($curr) && $curr >= 0)
        {
            $index  = round( (count($enc)-1) * $curr / 
$maxValue);
            $data[] = $enc[$index];
        }
        else
        {
            $data[] = '_';
        }
    }
    return implode('',$data);
}

Original comment by prehisto...@gmail.com on 12 Sep 2008 at 8:26

GoogleCodeExporter commented 8 years ago
     --eric(dot]martin{at}3jane[dot)com--
     --ibrahim[dot]yilmaz{at}karmabilisim[dot]net-- //Added Turkish characters
//Sorry for first submit this change for only contact information.
/**
 * Encodes a dataset for use in Google Charts
 */
private static function __simpleEncode( $valueArray, $maxValue )
{
    $enc  = split
(',','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');
    $data = array('s:');
    foreach( $valueArray as $curr )
    {
        if ( isset($curr) && $curr >= 0)
        {
            $index  = round( (count($enc)-1) * $curr / 
$maxValue);
            $data[] = $enc[$index];
        }
        else
        {
            $data[] = '_';
        }
    }
    return implode('',$data);
}

Original comment by prehisto...@gmail.com on 12 Sep 2008 at 8:27

GoogleCodeExporter commented 8 years ago
Fixed with the changes in rev. 14

Original comment by bardellie on 12 May 2010 at 11:49