Skip to content

Commit

Permalink
Added customize method from 2.5
Browse files Browse the repository at this point in the history
Will be incorporating the functionality into the constructor in future
versions.
  • Loading branch information
kevinkhill committed Jan 22, 2016
1 parent cbb3464 commit 8ed32d7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src/Charts/Chart.php
Expand Up @@ -197,6 +197,29 @@ public function datatable(DataTable $datatable)
return $this;
}

/**
* Sets any configuration option, with no checks for type / validity
*
*
* This is method was added in 2.5 as a bandaid to remove the handcuffs from
* users who want to add options that Google has added, that I have not.
* I didn't intend to restrict the user to only select options, as the
* goal was to type check and validate. This method can be used to set
* any option, just pass in arrays with key value pairs for any setting.
*
* If the setting is an object, per the google docs, then use multi-dimensional
* arrays and they will be converted upon rendering.
*
* @access public
* @since 3.0.0
* @param array $optionArray Array of customization options for the chart
* @return \Khill\Lavacharts\Charts\Chart
*/
public function customize($optionArray)
{
return $this->options->setOptions($optionArray, false);
}

/**
* Returns the DataTable
*
Expand Down
17 changes: 13 additions & 4 deletions src/Options.php
Expand Up @@ -147,15 +147,20 @@ public function get($option)
}

/**
* Batch set options from an array
* Batch set options from an array.
*
*
* The check flag can be used to bypass valid option checking
* (added for the customize chart method ported from the 2.5 branch)
*
* @access public
* @param array $options
* @param array $options Options to set
* @param bool $check Flag to check options against list of set options
* @return \Khill\Lavacharts\Options
* @throws \Khill\Lavacharts\Exceptions\InvalidConfigValue
* @throws \Khill\Lavacharts\Exceptions\InvalidOption
*/
public function setOptions($options)
public function setOptions($options, $check = true)
{
if (is_array($options) === false) {
throw new InvalidConfigValue(
Expand All @@ -165,7 +170,11 @@ public function setOptions($options)
}

foreach ($options as $option => $value) {
$this->set($option, $value);
if ($check === true) {
$this->set($option, $value);
} else {
$this->values[$option] = $value;
}
}

return $this;
Expand Down

0 comments on commit 8ed32d7

Please sign in to comment.