Colorize the ratios.

@param  \Illuminate\Database\Eloquent\Collection  $ratios

@return \Illuminate\Database\Eloquent\Collection
512298
private function colorizeRatios(Collection $ratios)
    {
        $colors = ['#F56954', '#00A65A', '#F39C12', '#00C0EF', '#3C8DBC'];

        return $ratios->values()->transform(function (array $values, $key) use ($colors) {
            return $values + ['color' => $colors[$key]];
        });
    }
666069
public static function setColors(array $colors = array())
    {
        if (!empty($colors)) {
            static::$colors = $colors;
            return;
        }
        static::$colors = array(
            \Monolog\Logger::DEBUG     => 'purple',
            \Monolog\Logger::INFO      => 'cyan',
            \Monolog\Logger::NOTICE    => 'green',
            \Monolog\Logger::WARNING   => 'yellow',
            \Monolog\Logger::ERROR     => 'red',
            \Monolog\Logger::CRITICAL  => 'red',
            \Monolog\Logger::ALERT     => 'red',
            \Monolog\Logger::EMERGENCY => 'red',
        );
    }
437838
public function convert(Currency $currency, $ratio, $roundingMode = self::ROUND_HALF_UP)
    {
        $this->currency = $currency;

        $this->assertOperand($ratio);
        $this->assertRoundingMode($roundingMode);

        if ($ratio < 1) {
            return $this->divide($ratio, $roundingMode);
        }

        return $this->multiply($ratio, $roundingMode);
    }
309939
public function totals()
    {
        $totals = Collection::make();

        foreach (Arr::except($this->footer(), 'all') as $level => $count) {
            $totals->put($level, [
                'label'     => $this->translate("levels.$level"),
                'value'     => $count,
                'color'     => $this->color($level),
                'highlight' => $this->color($level),
            ]);
        }

        return $totals;
    }
1290096
public function loadCount($relations)
    {
        $relations = is_string($relations) ? func_get_args() : $relations;

        $this->newCollection([$this])->loadCount($relations);

        return $this;
    }
691130
public function load($relations)
    {
        if ($this->isNotEmpty()) {
            if (is_string($relations)) {
                $relations = func_get_args();
            }

            $query = $this->first()->newQueryWithoutRelationships()->with($relations);

            $this->items = $query->eagerLoadRelations($this->items);
        }

        return $this;
    }
692472
public function setColor($red = null, $green = null, $blue = null)
    {
        $deferred = new Deferred();

        if (is_null($red)) {
            $this->setAttribute('color', 0);

            $deferred->resolve();

            return $deferred->promise();
        }

        $this->setAttribute('color', $red * 16 ** 4 + $green * 16 ** 2 + $blue);

        $deferred->resolve();

        return $deferred->promise();
    }
841032
public function renumberCollection(Collection $collection)
    {
        $i = 0;

        foreach ( $collection as $item ) {
            if ( $item instanceof NumericallySortableContract ) {
                $item->updateSortingOrder(++$i);
            }
        }

        return $this;
    }
314398
public function flatten($depth = INF): CollectionInterface
    {
        return $this->wrap(function (Iterator $data) use ($depth) {
            $lowerDepth = $depth === INF ? INF : $depth - 1;
            foreach ($data as $key => $datum) {
                if ($lowerDepth >= 0 && is_iterable($datum)) {
                    $collection = $this::make($datum);

                    foreach ($collection->flatten($lowerDepth)->getIterator() as $item) {
                        yield $item;
                    }
                } else {
                    yield $datum;
                }
            }
        });
    }
755987
protected function renderBar( $ratio, $length = 100 )
	{
		$css			= array();
//		$width			= floor( $ratio * $length );
		$width			= max( 0, min( 100, $ratio * 100 ) );
		$css['width']	= $width.'%';
		if( $this->getOption( 'useColor' ) )
		{
			$color	= $this->getColorFromRatio( $ratio );
			$css['background-color']	= "rgb(".$color[0].",".$color[1].",".$color[2].")";
		}

		$attributes	= array(
			'class'	=> $this->getOption( 'classInner' ),
			'style'	=> $css,
		);
		$bar		= UI_HTML_Tag::create( 'div', "", $attributes );

		$attributes	= array( 'class' => $this->getOption( 'classOuter' ) );
		$css		= array();
		if( $length !== 100 )
			$css['width']	= preg_match( "/%$/", $length ) ? $length : $length.'px';
		if( $this->getOption( 'useColor' ) && $this->getOption( 'useColorAtBorder' ) )
			$css['border-color']	= "rgb(".$color[0].",".$color[1].",".$color[2].")";
		$attributes['style']	= $css;
		return UI_HTML_Tag::create( "span", $bar, $attributes );
	}
739314
public function getColorFromRatio( $ratio ){
		if( $this->getOption( 'invertColor' ) )
			$ratio	= 1 - $ratio;
		$colorR	= ( 1 - $ratio ) > 0.5 ? 255 : round( ( 1 - $ratio ) * 2 * 255 );
		$colorG	= $ratio > 0.5 ? 255 : round( $ratio * 2 * 255 );
		$colorB	= "0";
		return array( $colorR, $colorG, $colorB );
	}
479021
public function orRelations(array $relations)
    {
        foreach ($relations as $column1 => $column2) {
            $this->orRelation($column1, $column2);
        }

        return $this;
    }
1341659
public function split(float $ratio = 0.5) : array
    {
        if ($ratio <= 0. or $ratio >= 1.) {
            throw new InvalidArgumentException('Split ratio must be strictly'
                . " between 0 and 1, $ratio given.");
        }

        $p = (int) ($ratio * $this->numRows());

        $left = self::quick(array_slice($this->samples, 0, $p));
        $right = self::quick(array_slice($this->samples, $p));

        return [$left, $right];
    }
562561
public function colorize($red, $green, $blue, $alpha = 127) {
		$normalizer = function ($value) { return max(-255, min(255, $value)); };
		$red = $normalizer($red);
		$green = $normalizer($green);
		$blue = $normalizer($blue);
		$alpha = min(127, max(0, $alpha));
		imagefilter($this->resource, IMG_FILTER_COLORIZE, $red, $green, $blue, $alpha);
		return $this;
	}
56619
public function addAlternative($ratio, Medium $alternative)
    {
        if (!is_numeric($ratio) || $ratio === 0) {
            return;
        }

        $alternative->set('ratio', $ratio);
        $width = $alternative->get('width');

        $this->alternatives[$width] = $alternative;
    }
486310
protected function createImageMatrix($size = 0, &$ratio) {
		// create two-color image
		$this->toBinary(false);

		// rescale if necessary (for performance reasons)
		if($size > 0 && ($this->width > $size || $this->height > $size)) {
			if($this->width > $this->height) {
				$ratio = $size / $this->width;
			} else {
				$ratio = $size / $this->height;
			}
			$width = (int)($ratio * $this->width);
			$height = (int)($ratio * $this->height);
			$image = imagecreate($width, $height);
			imagecopyresized($image, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
		} else {
			$ratio = 1;
			$image = imagecreate($this->width, $this->height);
			imagecopy($image, $this->image, 0, 0, 0, 0, $this->width, $this->height);
			list($width, $height) = $this->getSize();
		}

		$this->image = $image;

		// find the background color (fast approximation)
		$bin = $this->getBinaryBuffer();
        $colors = count_chars($bin);

		arsort($colors, SORT_NUMERIC);
		reset($colors); // HipHop for PHP compatibility.
		$backgroundColor = key($colors);

		// make colors negation if necessary, 0's should be used for background.
		if($backgroundColor === 255) {
			imagefilter($this->image, IMG_FILTER_NEGATE);
		}

		$image = imagecreatetruecolor($size, $size);
		imagefill($image, 0, 0, 0);
		imagecopy($image, $this->image, ($size - $width) / 2, ($size - $height) / 2, 0, 0, $width, $height);
		$this->image = $image;

		$bin = $this->getBinaryBuffer();

		$this->getSize();
		return $bin;
	}
720768
public function prepareCollection(ProductCollection $collection)
    {
        $collection->addAttributeToSelect($this->attributes);
        $collection->addPriceData();

        return $collection;
    }