Files
livewire-charts/src/Models/ColumnChartModel.php
Andrés Santibáñez 9df03c36a8 Added HasLegend trait
- Refactored component to use BaseChartModel and traits
2020-10-25 00:40:06 -05:00

103 lines
2.0 KiB
PHP

<?php
namespace Asantibanez\LivewireCharts\Models;
/**
* Class ColumnChartModel
* @package Asantibanez\LivewireCharts\Models
*/
class ColumnChartModel extends BaseChartModel
{
public $title;
public $animated;
public $opacity;
public $onColumnClickEventName;
public $data;
public function __construct()
{
parent::__construct();
$this->title = '';
$this->animated = false;
$this->onColumnClickEventName = null;
$this->opacity = 0.5;
$this->data = collect();
}
public function setTitle($title)
{
$this->title = $title;
return $this;
}
public function setAnimated($animated)
{
$this->animated = $animated;
return $this;
}
public function setOpacity($opacity)
{
$this->opacity = $opacity;
return $this;
}
public function withOnColumnClickEventName($onColumnClickEventName)
{
$this->onColumnClickEventName = $onColumnClickEventName;
return $this;
}
public function addColumn($title, $value, $color, $extras = [])
{
$this->data->push([
'title' => $title,
'value' => $value,
'color' => $color,
'extras' => $extras,
]);
return $this;
}
public function toArray()
{
return array_merge(parent::toArray(), [
'title' => $this->title,
'animated' => $this->animated,
'onColumnClickEventName' => $this->onColumnClickEventName,
'opacity' => $this->opacity,
'data' => $this->data->toArray(),
]);
}
public function fromArray($array)
{
parent::fromArray($array);
$this->title = data_get($array, 'title', '');
$this->animated = data_get($array, 'animated', false);
$this->onColumnClickEventName = data_get($array, 'onColumnClickEventName', null);
$this->opacity = data_get($array, 'opacity', 0.5);
$this->data = collect(data_get($array, 'data', []));
}
}