Beispiel #1
1
 /**
  * Overriding getOption function to pull config options from calendar array.
  * (Thanks google)
  *
  * @param  string             $o Which option to fetch
  * @throws InvalidConfigValue
  * @return mixed
  */
 public function getOption($o)
 {
     if (is_string($o) && array_key_exists($o, $this->options['calendar'])) {
         return $this->options['calendar'][$o];
     } else {
         if (is_string($o) && array_key_exists($o, $this->options)) {
             return $this->options[$o];
         } else {
             $calendarOptions = $this->options['calendar'];
             $nonCalendarOptions = array_diff($this->options, $calendarOptions);
             $options = array_merge($calendarOptions, $nonCalendarOptions);
             throw $this->invalidConfigValue(__FUNCTION__, 'string', 'must be one of ' . Utils::arrayToPipedString(array_keys($options)));
         }
     }
 }
Beispiel #2
0
 /**
  * Sets the opacity of the stroke.
  *
  * @param  float $strokeOpacity
  * @return \Khill\Lavacharts\Configs\Stroke
  * @throws \Khill\Lavacharts\Exceptions\InvalidConfigValue
  */
 public function strokeOpacity($strokeOpacity)
 {
     if (Utils::between(0.0, $strokeOpacity, 1.0, true) === false) {
         throw new InvalidConfigValue(__FUNCTION__, 'float', 'between 0.0 and 1.0');
     }
     return $this->setOption(__FUNCTION__, $strokeOpacity);
 }
Beispiel #3
0
 /**
  * How far to separate the slice from the rest of the pie.
  * from 0.0 (not at all) to 1.0 (the pie's radius).
  *
  * @param  float $offset
  * @return \Khill\Lavacharts\Configs\Slice
  * @throws \Khill\Lavacharts\Exceptions\InvalidConfigValue
  */
 public function offset($offset)
 {
     if (Utils::between(0.0, $offset, 1.0) === false) {
         throw new InvalidConfigValue(__FUNCTION__, 'float', 'where 0.0 < $offset < 1.0');
     }
     return $this->setOption(__FUNCTION__, $offset);
 }
Beispiel #4
0
 /**
  * Sets the transparency of assigned object points
  *
  * 1.0 being completely opaque and 0.0 fully transparent.
  *
  * @param  float $opacity
  * @throws \Khill\Lavacharts\Exceptions\InvalidConfigValue
  * @return \Khill\Lavacharts\Charts\Chart
  */
 public function opacity($opacity)
 {
     if (Utils::between(0.0, $opacity, 1.0) === false) {
         throw new InvalidConfigValue(static::TYPE . '->' . __FUNCTION__, 'float', 'between 0.0 - 1.0');
     }
     return $this->setOption(__FUNCTION__, $opacity);
 }
 /**
  * The width of a group of bars, specified in either of these formats:
  * - Pixels (e.g. 50).
  * - Percentage of the available width for each group (e.g. '20%'),
  *   where '100%' means that groups have no space between them.
  *
  * @param  int|string $barGroupWidth
  * @return \Khill\Lavacharts\Charts\Chart
  * @throws \Khill\Lavacharts\Exceptions\InvalidConfigValue
  */
 public function barGroupWidth($barGroupWidth)
 {
     if (Utils::isIntOrPercent($barGroupWidth) === false) {
         throw new InvalidConfigValue(static::TYPE . '->' . __FUNCTION__, 'int|string', 'String only if representing a percent. "50%"');
     }
     return $this->setOption(__FUNCTION__, ['groupWidth' => $barGroupWidth]);
 }
Beispiel #6
0
 /**
  * If between 0 and 1, displays a donut chart.
  *
  * The hole with have a radius equal to $pieHole times the radius of the chart.
  *
  *
  * @param  integer|float $pieHole Size of the pie hole.
  * @return \Khill\Lavacharts\Charts\DonutChart
  * @throws \Khill\Lavacharts\Exceptions\InvalidConfigValue
  */
 public function pieHole($pieHole)
 {
     if (Utils::between(0.0, $pieHole, 1.0) === false) {
         throw new InvalidConfigValue(static::TYPE . '->' . __FUNCTION__, 'float', 'while, 0 < pieHole < 1 ');
     }
     return $this->setOption(__FUNCTION__, $pieHole);
 }
Beispiel #7
0
 /**
  * Sets the callback for an event.
  *
  * @access public
  * @param  string $event
  * @param  string $callback
  * @throws \Khill\Lavacharts\Exceptions\InvalidEvent
  * @throws \Khill\Lavacharts\Exceptions\InvalidEventCallback
  */
 public function set($event, $callback)
 {
     $this->validEvent($event);
     if (Utils::nonEmptyString($callback) === false) {
         throw new InvalidEventCallback($callback);
     }
     $this->events[$event] = $callback;
 }
Beispiel #8
0
 /**
  * Builds the Event object.
  *
  * @param  string             $c Name of Javascript callback function.
  * @throws InvalidConfigValue
  * @return Event
  */
 public function __construct($c)
 {
     if (Utils::nonEmptyString($c)) {
         $this->callback = $c;
     } else {
         throw new InvalidConfigValue('an Event', 'string');
     }
 }
Beispiel #9
0
 /**
  * How far to separate the slice from the rest of the pie.
  * from 0.0 (not at all) to 1.0 (the pie's radius).
  *
  * @param  float              $offset
  * @throws InvalidConfigValue
  * @return Slice
  */
 public function offset($offset)
 {
     if (Utils::between(0.0, $offset, 1.0)) {
         $this->offset = $offset;
     } else {
         throw new InvalidConfigValue(__FUNCTION__, 'float', 'where 0.0 < $offset < 0.1');
     }
     return $this;
 }
 /**
  * The width of a group of bars, specified in either of these formats:
  * - Pixels (e.g. 50).
  * - Percentage of the available width for each group (e.g. '20%'),
  *   where '100%' means that groups have no space between them.
  *
  * @param  mixed       $barGroupWidth
  * @return ColumnChart
  */
 public function barGroupWidth($barGroupWidth)
 {
     if (Utils::isIntOrPercent($barGroupWidth)) {
         $this->addOption(array('bar' => array('groupWidth' => $barGroupWidth)));
     } else {
         throw $this->invalidConfigValue(__FUNCTION__, 'string | int', 'must be a valid int or percent [ 50 | 65% ]');
     }
     return $this;
 }
Beispiel #11
0
 /**
  * Sets the opacity of the stroke.
  *
  * @param  float             $strokeOpacity
  * @throws InvalidConfigValue
  * @return Stroke
  */
 public function strokeOpacity($so)
 {
     if (Utils::between(0.0, $so, 1.0, true)) {
         $this->strokeOpacity = (double) $so;
     } else {
         throw new InvalidConfigValue(__FUNCTION__, 'float');
     }
     return $this;
 }
Beispiel #12
0
 /**
  * If between 0 and 1, displays a donut chart. The hole with have a radius
  * equal to $pieHole times the radius of the chart.
  *
  * @param int|float $pieHole
  *
  * @return DonutChart
  */
 public function pieHole($pieHole)
 {
     if (Utils::between(0.0, $pieHole, 1.0)) {
         $this->addOption(array('pieHole' => $pieHole));
     } else {
         throw $this->invalidConfigValue(__FUNCTION__, 'float', 'while, 0 < pieHole < 1 ');
     }
     return $this;
 }
 /**
  * The method of filtering the string:
  *
  * exact - The pattern matches the string exactly.
  * prefix - The pattern is found at the beginning of the string.
  * any - The pattern is found anywhere in the string.
  *
  * @param  string             $position
  * @throws InvalidConfigValue
  * @return StringFilter
  */
 public function matchType($type)
 {
     $values = array('exact', 'prefix', 'any');
     if (is_string($type) && in_array($type, $values)) {
         $this->addOption(array(__FUNCTION__ => $type));
     } else {
         throw $this->invalidConfigValue(__FUNCTION__, 'string', 'with a value of ' . Utils::arrayToPipedString($values));
     }
     return $this;
 }
 /**
  * Controls the curve of the lines when the line width is not zero.
  *
  * Can be one of the following:
  * 'none' - Straight lines without curve.
  * 'function' - The angles of the line will be smoothed.
  *
  * @param  string             $curveType
  * @throws InvalidConfigValue
  * @return LineChart
  */
 public function curveType($curveType)
 {
     $values = array('none', 'function');
     if (is_string($curveType) && in_array($curveType, $values)) {
         $this->addOption(array('curveType' => $curveType));
     } else {
         throw $this->invalidConfigValue(__FUNCTION__, 'string', 'with a value of ' . Utils::arrayToPipedString($values));
     }
     return $this;
 }
 /**
  * Where to place the axis titles, compared to the chart area. Supported values:
  *
  * in - Draw the axis titles inside the the chart area.
  * out - Draw the axis titles outside the chart area.
  * none - Omit the axis titles.
  *
  * @param  string             $position
  * @throws InvalidConfigValue
  * @return AreaChart
  */
 public function axisTitlesPosition($position)
 {
     $values = array('in', 'out', 'none');
     if (is_string($position) && in_array($position, $values)) {
         $this->addOption(array('axisTitlesPosition' => $position));
     } else {
         throw $this->invalidConfigValue(__FUNCTION__, 'string', 'with a value of ' . Utils::arrayToPipedString($values));
     }
     return $this;
 }
Beispiel #16
0
 /**
  * Animation Easing
  *
  * The easing function applied to the animation. The following options are available:
  * 'linear' - Constant speed.
  * 'in' - Ease in - Start slow and speed up.
  * 'out' - Ease out - Start fast and slow down.
  * 'inAndOut' - Ease in and out - Start slow, speed up, then slow down.
  *
  * @param string $easing
  *
  * @return Chart
  */
 public function animationEasing($easing = 'linear')
 {
     $values = array('linear', 'in', 'out', 'inAndOut');
     if (in_array($easing, $values)) {
         $this->easing = $easing;
     } else {
         $this->error('Invalid animationEasing value, must be (string) ' . Utils::arrayToPipedString($values));
     }
     return $this;
 }
 /**
  * Specifies properties for individual horizontal axes, if the chart has multiple horizontal axes.
  * Each child object is a hAxis object, and can contain all the properties supported by hAxis.
  * These property values override any global settings for the same property.
  * To specify a chart with multiple horizontal axes, first define a new axis using series.targetAxisIndex,
  * then configure the axis using hAxes.
  *
  * @param  array $hAxisConfigArray Array of HorizontalAxis configuration arrays
  * @return \Khill\Lavacharts\Charts\Chart
  * @throws \Khill\Lavacharts\Exceptions\InvalidConfigValue
  */
 public function hAxes($hAxisConfigArray)
 {
     if (Utils::arrayIsMulti($hAxisConfigArray) === false) {
         throw new InvalidConfigValue(static::TYPE . '->' . __FUNCTION__, 'array', 'With arrays of HorizontalAxis options.');
     }
     $hAxes = [];
     foreach ($hAxisConfigArray as $hAxisConfig) {
         $hAxes[] = new HorizontalAxis($hAxisConfig);
     }
     return $this->setOption(__FUNCTION__, $hAxes);
 }
Beispiel #18
0
 /**
  * An array of objects, each describing the format of the corresponding series
  * in the chart.
  * To use default values for a series, specify an null in the array.
  * If a series or a value is not specified, the global value will be used.
  *
  * @param  array $seriesConfigArray Array of Series options.
  * @return \Khill\Lavacharts\Charts\Chart
  * @throws \Khill\Lavacharts\Exceptions\InvalidConfigValue
  */
 public function series($seriesConfigArray)
 {
     if (Utils::arrayIsMulti($seriesConfigArray) === false) {
         throw new InvalidConfigValue(static::TYPE . '->' . __FUNCTION__, 'array', 'With arrays of Series options.');
     }
     $series = [];
     foreach ($seriesConfigArray as $seriesConfig) {
         $series[] = new Series($seriesConfig);
     }
     return $this->setOption(__FUNCTION__, $series);
 }
 /**
  * If set to true, stacks the elements for all series at each domain value.
  *
  * Note: In Column, Area, and SteppedArea charts, Google Charts reverses the order
  *  of legend items to better correspond with the stacking of the series elements
  *  (E.g. series 0 will be the bottom-most legend item). This does not apply to Bar Charts.
  *
  * The isStacked option also supports 100% stacking, where the stacks
  * of elements at each domain value are rescaled to add up to 100%.
  *
  * The options for isStacked are:
  *
  * false — elements will not stack. This is the default option.
  * true — stacks elements for all series at each domain value.
  *        'percent' — stacks elements for all series at each domain value
  *        and rescales them such that they add up to 100%, with each element's
  *        value calculated as a percentage of 100%.
  * 'relative' — stacks elements for all series at each domain value
  *              and rescales them such that they add up to 1, with each element's
  *              value calculated as a fraction of 1.
  * 'absolute' — functions the same as isStacked: true.
  *
  * For 100% stacking, the calculated value for each element will appear
  *  in the tooltip after its actual value.
  *
  * The target axis will default to tick values based on the relative
  * 0-1 scale as fractions of 1 for 'relative', and 0-100% for 'percent'
  * (Note: when using the 'percent' option, the axis/tick values are
  * displayed as percentages, however the actual values are the relative
  *  0-1 scale values. This is because the percentage axis ticks are the
  *  result of applying a format of "#.##%" to the relative 0-1 scale values.
  *  When using isStacked: 'percent', be sure to specify any ticks/gridlines
  * using the relative 0-1 scale values). You can customize the gridlines/tick
  * values and formatting using the appropriate hAxis/vAxis options.
  *
  * 100% stacking only supports data values of type number, and must have a baseline of zero.
  *
  * @param  bool|string $isStacked
  * @throws \Khill\Lavacharts\Exceptions\InvalidConfigValue
  * @return \Khill\Lavacharts\Charts\Chart
  */
 public function isStacked($isStacked)
 {
     $values = ['relative', 'absolute'];
     if (is_bool($isStacked) === true) {
         return $this->setBoolOption(__FUNCTION__, $isStacked);
     } elseif (is_string($isStacked) === true) {
         return $this->setStringInArrayOption(__FUNCTION__, $isStacked, $values);
     } else {
         throw new InvalidConfigValue(static::TYPE . '->' . __FUNCTION__, 'bool|string', 'Whose value is one of ' . Utils::arrayToPipedString($values));
     }
 }
 /**
  * Defines how the chart trendlines will be displayed.
  *
  * @param  array $trendlineConfigArray
  * @return \Khill\Lavacharts\Charts\Chart
  * @throws \Khill\Lavacharts\Traits\InvalidConfigValue
  */
 public function trendlines($trendlineConfigArray)
 {
     if (Utils::arrayIsMulti($trendlineConfigArray) === false) {
         throw new InvalidConfigValue(static::TYPE . '->' . __FUNCTION__, 'array', 'With arrays of Trendline options.');
     }
     $trendlines = [];
     foreach ($trendlineConfigArray as $index => $trendlineConfig) {
         $trendlines[(string) $index] = new Trendline($trendlineConfig);
     }
     return $this->setOption(__FUNCTION__, $trendlines);
 }
Beispiel #21
0
 /**
  * Builds a new Filter Object.
  *
  * Takes either a column label or a column index to filter. The options object will be
  * created internally, so no need to set defaults. The child filter objects will set them.
  *
  * @param  string|int $columnLabelOrIndex
  * @param  array      $config Array of options to set.
  * @throws \Khill\Lavacharts\Exceptions\InvalidConfigValue
  */
 public function __construct($columnLabelOrIndex, $config = [])
 {
     if (Utils::nonEmptyString($columnLabelOrIndex) === false && is_int($columnLabelOrIndex) === false) {
         throw new InvalidConfigValue(static::TYPE . '->' . __FUNCTION__, 'string|int');
     }
     if (is_string($columnLabelOrIndex) === true) {
         $config = array_merge($config, ['filterColumnLabel' => $columnLabelOrIndex]);
     }
     if (is_int($columnLabelOrIndex) === true) {
         $config = array_merge($config, ['filterColumnIndex' => $columnLabelOrIndex]);
     }
     $this->options = new Options($config);
 }
Beispiel #22
0
 /**
  * Parses a datetime string with or without a datetime format.
  *
  * Uses Carbon to create the values for the DateCell.
  *
  *
  * @param  string $dateTimeString
  * @param  string $dateTimeFormat
  * @return \Khill\Lavacharts\DataTables\Cells\Cell
  * @throws \Khill\Lavacharts\Exceptions\FailedCarbonParsing
  * @throws \Khill\Lavacharts\Exceptions\InvalidDateTimeFormat
  * @throws \Khill\Lavacharts\Exceptions\InvalidDateTimeString
  */
 public static function parseString($dateTimeString, $dateTimeFormat = '')
 {
     if (Utils::nonEmptyString($dateTimeString) === false) {
         throw new InvalidDateTimeString($dateTimeString);
     }
     if (gettype($dateTimeFormat) != 'string') {
         throw new InvalidDateTimeFormat($dateTimeFormat);
     }
     if (Utils::nonEmptyString($dateTimeFormat) === false) {
         $carbon = Carbon::parse($dateTimeString);
     } else {
         $carbon = Carbon::createFromFormat($dateTimeFormat, $dateTimeString);
     }
     return new DateCell($carbon);
 }
Beispiel #23
0
 /**
  * Create a new Binding for the dashboard.
  *
  * @param  mixed $arg1 One or array of many ControlWrappers
  * @param  mixed $arg2 One or array of many ChartWrappers
  * @throws \Khill\Lavacharts\Exceptions\InvalidBindings
  * @return \Khill\Lavacharts\Dashboards\Bindings\Binding
  */
 public static function create($arg1, $arg2)
 {
     $chartWrapperArrayCheck = Utils::arrayValuesCheck($arg2, 'class', 'ChartWrapper');
     $controlWrapperArrayCheck = Utils::arrayValuesCheck($arg1, 'class', 'ControlWrapper');
     if ($arg1 instanceof ControlWrapper && $arg2 instanceof ChartWrapper) {
         return new OneToOne($arg1, $arg2);
     } elseif ($arg1 instanceof ControlWrapper && $chartWrapperArrayCheck) {
         return new OneToMany($arg1, $arg2);
     } elseif ($controlWrapperArrayCheck && $arg2 instanceof ChartWrapper) {
         return new ManyToOne($arg1, $arg2);
     } elseif ($controlWrapperArrayCheck && $chartWrapperArrayCheck) {
         return new ManyToMany($arg1, $arg2);
     } else {
         throw new InvalidBindings();
     }
 }
Beispiel #24
0
 /**
  * Simple true/false test if a chart exists.
  *
  * @param string $type  Type of chart to store.
  * @param string $label Identifying label of a chart to check.
  *
  * @return bool
  */
 public function checkChart($type, $label)
 {
     if (Utils::nonEmptyString($type) && Utils::nonEmptyString($label)) {
         if (array_key_exists($type, $this->charts)) {
             if (array_key_exists($label, $this->charts[$type])) {
                 return true;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #25
0
 /**
  * Builds the ConfigOptions object.
  *
  * Passing an array of key value pairs will set the configuration for each
  * child object created from this parent object.
  *
  * @param  mixed                 $child  Child ConfigOption object.
  * @param  array                 $config Array of options.
  * @throws InvalidConfigValue
  * @throws InvalidConfigProperty
  * @return mixed
  */
 public function __construct($child, $config)
 {
     $class = new \ReflectionClass($child);
     $this->options = array_map(function ($prop) {
         return $prop->name;
     }, $class->getProperties(\ReflectionProperty::IS_PUBLIC));
     if (is_array($config)) {
         foreach ($config as $option => $value) {
             if (in_array($option, $this->options)) {
                 $this->{$option}($value);
             } else {
                 throw new InvalidConfigProperty($child::TYPE, __FUNCTION__, $option, $this->options);
             }
         }
     } else {
         throw new InvalidConfigValue(__FUNCTION__, 'array', 'with valid keys as ' . Utils::arrayToPipedString($this->options));
     }
 }
Beispiel #26
0
 /**
  * Creates a new column object.
  *
  * @access public
  * @since  3.0.0
  * @param  string                                      $type Type of column to create.
  * @param  string                                      $label A label for the column.
  * @param  \Khill\Lavacharts\DataTables\Formats\Format $format Column formatter for the data.
  * @param  string                                      $role A role for the column to play.
  * @return \Khill\Lavacharts\DataTables\Columns\Column
  * @throws \Khill\Lavacharts\Exceptions\InvalidColumnRole
  * @throws \Khill\Lavacharts\Exceptions\InvalidColumnType
  */
 public static function create($type, $label = '', Format $format = null, $role = '')
 {
     if (Utils::nonEmptyStringInArray($type, self::$TYPES) === false) {
         throw new InvalidColumnType($type, self::$TYPES);
     }
     $columnArgs = [$type];
     if (Utils::nonEmptyString($label) === true) {
         $columnArgs[] = $label;
     } else {
         $columnArgs[] = '';
     }
     if ($format !== null) {
         $columnArgs[] = $format;
     } else {
         $columnArgs[] = null;
     }
     if (is_string($role) === false || $role != '' && in_array($role, self::$ROLES, true) === false) {
         throw new InvalidColumnRole($role, self::$ROLES);
     }
     $columnArgs[] = $role;
     $column = new \ReflectionClass('\\Khill\\Lavacharts\\DataTables\\Columns\\Column');
     return $column->newInstanceArgs($columnArgs);
 }
Beispiel #27
0
 /**
  * Sets the height of the chart in the container.
  *
  * @param  int                $height Amount in pixels
  * @throws InvalidConfigValue
  * @return ChartArea
  */
 public function height($height)
 {
     if (Utils::isIntOrPercent($height)) {
         $this->height = $height;
     } else {
         throw new InvalidConfigValue(__FUNCTION__, 'int | string', 'representing pixels or a percent.');
     }
     return $this;
 }
 /**
  * The colors to use for the chart elements.
  *
  * An array of strings, where each element is an HTML color string
  * for example:['red','#004411']
  *
  *
  * @access public
  * @param  array $colorArray
  * @return \Khill\Lavacharts\Charts\Chart
  * @throws \Khill\Lavacharts\Exceptions\InvalidConfigValue
  */
 public function colors($colorArray)
 {
     if (Utils::arrayValuesCheck($colorArray, 'string') === false) {
         throw new InvalidConfigValue(static::TYPE . '->' . __FUNCTION__, 'array', 'with valid HTML colors');
     }
     return $this->setOption(__FUNCTION__, $colorArray);
 }
Beispiel #29
0
 /**
  * Get the value of a set option.
  *
  * @access public
  * @param  string $option Name of option.
  * @return mixed
  * @throws \Khill\Lavacharts\Exceptions\InvalidOption
  */
 public function get($option)
 {
     if (Utils::nonEmptyString($option) === false) {
         throw new InvalidOption($option, $this->options);
     }
     if (array_key_exists($option, $this->values) === false) {
         return null;
     } else {
         return $this->values[$option];
     }
 }
Beispiel #30
0
 /**
  * The type of the entity that receives focus on mouse hover.
  *
  * Also affects which entity is selected by mouse click, and which data table
  * element is associated with events. Can be one of the following:
  *  'datum'    - Focus on a single data point. Correlates to a cell in the data table.
  *  'category' - Focus on a grouping of all data points along the major axis.
  *               Correlates to a row in the data table.
  *
  * In focusTarget 'category' the tooltip displays all the category values.
  * This may be useful for comparing values of different series.
  *
  * @since  v2.4.1
  * @param  string     $ft
  * @return AreaChart
  */
 public function focusTarget($ft)
 {
     $values = array('datum', 'category');
     if (Utils::nonEmptyStringInArray($ft, $values)) {
         $this->addOption(array(__FUNCTION__ => $ft));
     } else {
         throw $this->invalidConfigValue(__FUNCTION__, 'string', 'must be one of ' . Utils::arrayToPipedString($values));
     }
     return $this;
 }