<commit_before><?php

/*
 * This file is part of the LegGCharts package.
 *
 * (c) <NAME> <http://titouangalopin.com/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Leg\GCharts;

use Leg\GCharts\DataSet\DataSet;
use Leg\GCharts\DataSet\DataSetCollection;

class BaseChart implements ChartInterface
{
	/**
	 * @var string
	 */
	const BASE_URL = 'http://chart.googleapis.com/chart';

	/**
	 * @var string
	 */
	protected $type;

	/**
	 * @var integer
	 */
	protected $width;

	/**
	 * @var integer
	 */
	protected $height;

	/**
	 * @var DataSetCollection
	 */
	protected $datas;

	/**
	 * @var DataSet
	 */
	protected $labels;

	/**
	 * @var DataSet
	 */
	protected $labels_options;

	/**
	 * @var DataSet
	 */
	protected $colors;

	/**
	 * @var string
	 */
	protected $title;

	/**
	 * @var DataSet
	 */
	protected $title_options;

	/**
	 * @var boolean
	 */
	protected $transparency;

	/**
	 * @var DataSet
	 */
	protected $margins;

	/**
	 * Constructor
	 */
	public function __construct()
	{
		$this->datas = new DataSetCollection();
		$this->labels = new DataSet();
		$this->labels_options = new DataSet();
		$this->colors = new DataSet();
		$this->title_options = new DataSet();

		$this->margins = new DataSet(array(
			'top' => null,
			'bottom' => null,
			'left' => null,
			'right' => null,
			'legend-width' => null,
			'legend-height' => null
		));

		$this->setOptions($this->getDefaultOptions());
	}

	/**
	 * Set options
	 *
	 * @param array $options
	 * @throws \InvalidArgumentException
	 */
	public function setOptions(array $options)
	{
		foreach ($options as $option => $value) {
			$funcName = array_map('ucfirst', explode('_', $option));
			$funcName = 'set'.implode('', $funcName);

			if (method_exists($this, $funcName)) {
				$this->$funcName($value);
			} else {
				throw new \InvalidArgumentException(sprintf(
					'Unknown chart option "%s" or chart method "%s()"',
					$option, $funcName
				), 500);
			}
		}
	}

	/**
	 * @return array
	 */
	public function getDefaultOptions()
	{
		return array();
	}

	/**
	 * Build and return URI
	 *
	 * @return string
	 * @throws \InvalidArgumentException
	 */
	public function build()
	{
		if (empty($this->type)) {
			throw new \InvalidArgumentException('A chart must have a type.', 500);
		}

		if ($this->datas->isEmpty()) {
			throw new \InvalidArgumentException('A chart must have datas.', 500);
		}

		if (empty($this->width)) {
			throw new \InvalidArgumentException('A chart must have a width.', 500);
		}

		if (empty($this->height)) {
			throw new \InvalidArgumentException('A chart must have a height.', 500);
		}

		$url = self::BASE_URL.'?cht='.$this->type;
		$url .= '&chs='.$this->width.'x'.$this->height;

		$dataSets = array();

		foreach ($this->datas->toArray() as $dataSet) {
			$dataSets[] = implode(',', $dataSet->toArray());
		}

		$url .= '&chd=t:'.implode('|', $dataSets);

		if (! $this->colors->isEmpty()) {
			$url .= '&chco='.implode(',', $this->colors->toArray());
		}

		if ($this->isTransparent()) {
			$url .= '&chf=bg,s,65432100';
		}

		if (! $this->labels->isEmpty()) {
			$url .= '&chl='.implode('|', $this->labels->toArray());

			if ($this->labels_options->get('position')) {
				$url .= '&chdlp='.$this->labels_options->get('position');
			}

			if ($this->labels_options->get('color')) {
				$url .= '&chdls='.$this->labels_options->get('color');
			}

			if ($this->labels_options->get('font-size')) {
				if ($this->labels_options->get('color')) {
					$url .= ','.$this->labels_options->get('font-size');<commit_msg>Colours are separated by commas for line charts only<commit_after><?php

/*
 * This file is part of the LegGCharts package.
 *
 * (c) <NAME> <http://titouangalopin.com/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Leg\GCharts;

use Leg\GCharts\DataSet\DataSet;
use Leg\GCharts\DataSet\DataSetCollection;

class BaseChart implements ChartInterface
{
	/**
	 * @var string
	 */
	const BASE_URL = 'http://chart.googleapis.com/chart';

	/**
	 * @var string
	 */
	protected $type;

	/**
	 * @var integer
	 */
	protected $width;

	/**
	 * @var integer
	 */
	protected $height;

	/**
	 * @var DataSetCollection
	 */
	protected $datas;

	/**
	 * @var DataSet
	 */
	protected $labels;

	/**
	 * @var DataSet
	 */
	protected $labels_options;

	/**
	 * @var DataSet
	 */
	protected $colors;

	/**
	 * @var string
	 */
	protected $title;

	/**
	 * @var DataSet
	 */
	protected $title_options;

	/**
	 * @var boolean
	 */
	protected $transparency;

	/**
	 * @var DataSet
	 */
	protected $margins;

	/**
	 * Constructor
	 */
	public function __construct()
	{
		$this->datas = new DataSetCollection();
		$this->labels = new DataSet();
		$this->labels_options = new DataSet();
		$this->colors = new DataSet();
		$this->title_options = new DataSet();

		$this->margins = new DataSet(array(
			'top' => null,
			'bottom' => null,
			'left' => null,
			'right' => null,
			'legend-width' => null,
			'legend-height' => null
		));

		$this->setOptions($this->getDefaultOptions());
	}

	/**
	 * Set options
	 *
	 * @param array $options
	 * @throws \InvalidArgumentException
	 */
	public function setOptions(array $options)
	{
		foreach ($options as $option => $value) {
			$funcName = array_map('ucfirst', explode('_', $option));
			$funcName = 'set'.implode('', $funcName);

			if (method_exists($this, $funcName)) {
				$this->$funcName($value);
			} else {
				throw new \InvalidArgumentException(sprintf(
					'Unknown chart option "%s" or chart method "%s()"',
					$option, $funcName
				), 500);
			}
		}
	}

	/**
	 * @return array
	 */
	public function getDefaultOptions()
	{
		return array();
	}

	/**
	 * Build and return URI
	 *
	 * @return string
	 * @throws \InvalidArgumentException
	 */
	public function build()
	{
		if (empty($this->type)) {
			throw new \InvalidArgumentException('A chart must have a type.', 500);
		}

		if ($this->datas->isEmpty()) {
			throw new \InvalidArgumentException('A chart must have datas.', 500);
		}

		if (empty($this->width)) {
			throw new \InvalidArgumentException('A chart must have a width.', 500);
		}

		if (empty($this->height)) {
			throw new \InvalidArgumentException('A chart must have a height.', 500);
		}

		$url = self::BASE_URL.'?cht='.$this->type;
		$url .= '&chs='.$this->width.'x'.$this->height;

		$dataSets = array();

		foreach ($this->datas->toArray() as $dataSet) {
			$dataSets[] = implode(',', $dataSet->toArray());
		}

		$url .= '&chd=t:'.implode('|', $dataSets);

		if (! $this->colors->isEmpty()) {
		    $colorsSeparator = ($this->type == 'lc') ? ',' : '|'; 
			$url .= '&chco='.implode($colorsSeparator, $this->colors->toArray());
		}

		if ($this->isTransparent()) {
			$url .= '&chf=bg,s,65432100';
		}

		if (! $this->labels->isEmpty()) {
			$url .= '&chl='.implode('|', $this->labels->toArray());

			if ($this->labels_options->get('position')) {
				$url .= '&chdlp='.$this->labels_options->get('position');
			}

			if ($this->labels_options->get('color')) {
				$url .= '&chdls='.$this->labels_options->get('color');
			}

			if ($this->labels_options->get('font-size')) {
				if ($this->labels_options->get('color')) {
					$url .= ','.$this->labels_options->get('font-size');
{'fraction_non_alphanumeric': 0.19715254237288135, 'fraction_numerical': 0.00623728813559322, 'mean_word_length': 3.239080459770115, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 108, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '335950', 'n_tokens_mistral': 2874, 'n_tokens_neox': 2459, 'n_words': 554}