src/Widgets/Reports/BaseReportGraphs.php
public function getChartColors(int $count, string $myString, bool $shade = true) : array
    {
        $grad = [];

        // Generate first color
        if ($shade && $count > 0) {
            $color = substr(dechex(crc32($myString)), 0, 6);
            list($r, $g, $b) = array_map(function ($n) {
                return hexdec($n);
            }, str_split($color, 2));

            // Generate second color
            $color2 = substr(dechex(crc32($myString . ' ')), 0, 6);
            list($r2, $g2, $b2) = array_map(function ($n) {
                return hexdec($n);
            }, str_split($color2, 2));

            $rl = ( $r2 - $r) / $count - 1;
            $gl = ( $g2 - $g) / $count - 1;
            $bl = ( $b2 - $b) / $count - 1;

            // Create a shade from the first color to the second
            for ($i = 0; $i < $count; $i++) {
                $grad[] = '#' . str_pad(dechex($r + $rl * $i), 2, "0", 0) . str_pad(dechex($g + $gl * $i), 2, "0", 0) . str_pad(dechex($b + $bl * $i), 2, "0", 0);
            }

            return $grad;
        }

        $my_palette = Configure::read("Widget.colors");

        for ($i = 0; $i < $count; $i++) {
            $grad[] = $my_palette[(crc32($myString) + $i) % count($my_palette)];
        }

        return $grad;
    }
public function getChartColors(int $count, string $myString, bool $shade = true) : array
    {
        $grad = [];

        // Generate first color
        if ($shade && $count > 0) {
            $color = substr(dechex(crc32($myString)), 0, 6);
            list($r, $g, $b) = array_map(function ($n) {
                return hexdec($n);
            }, str_split($color, 2));

            // Generate second color
            $color2 = substr(dechex(crc32($myString . ' ')), 0, 6);
            list($r2, $g2, $b2) = array_map(function ($n) {
                return hexdec($n);
            }, str_split($color2, 2));

            $rl = ( $r2 - $r) / $count - 1;
            $gl = ( $g2 - $g) / $count - 1;
            $bl = ( $b2 - $b) / $count - 1;

            // Create a shade from the first color to the second
            for ($i = 0; $i < $count; $i++) {
                $grad[] = '#' . str_pad(dechex($r + $rl * $i), 2, "0", 0) . str_pad(dechex($g + $gl * $i), 2, "0", 0) . str_pad(dechex($b + $bl * $i), 2, "0", 0);
            }

            return $grad;
        }

        $my_palette = Configure::read("Widget.colors");

        for ($i = 0; $i < $count; $i++) {
            $grad[] = $my_palette[(crc32($myString) + $i) % count($my_palette)];
        }

        return $grad;
    }
public function getChartColors ( int $ count , string $ myString , bool $ shade = true ) : array { $ grad = [ ] ; // Generate first color if ( $ shade && $ count > 0 ) { $ color = substr ( dechex ( crc32 ( $ myString ) ) , 0 , 6 ) ; list ( $ r , $ g , $ b ) = array_map ( function ( $ n ) { return hexdec ( $ n ) ; } , str_split ( $ color , 2 ) ) ; // Generate second color $ color2 = substr ( dechex ( crc32 ( $ myString . ' ' ) ) , 0 , 6 ) ; list ( $ r2 , $ g2 , $ b2 ) = array_map ( function ( $ n ) { return hexdec ( $ n ) ; } , str_split ( $ color2 , 2 ) ) ; $ rl = ( $ r2 - $ r ) / $ count - 1 ; $ gl = ( $ g2 - $ g ) / $ count - 1 ; $ bl = ( $ b2 - $ b ) / $ count - 1 ; // Create a shade from the first color to the second for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ grad [ ] = '#' . str_pad ( dechex ( $ r + $ rl * $ i ) , 2 , "0" , 0 ) . str_pad ( dechex ( $ g + $ gl * $ i ) , 2 , "0" , 0 ) . str_pad ( dechex ( $ b + $ bl * $ i ) , 2 , "0" , 0 ) ; } return $ grad ; } $ my_palette = Configure :: read ( "Widget.colors" ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ grad [ ] = $ my_palette [ ( crc32 ( $ myString ) + $ i ) % count ( $ my_palette ) ] ; } return $ grad ; }
Generate an array whit the colors for the chars.

@param  int     $count    How many element in the array.
@param  string  $myString The color have to be calculated on a
fix string to be constant in every refresh.
@param  bool    $shade    Shade the default color with another
generated one. If false, the colors will be from a pre-set palette.
@return string[]
Generate an array whit the colors for the chars .