Initial commit
This commit is contained in:
99
src/Models/ColumnChartModel.php
Normal file
99
src/Models/ColumnChartModel.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Asantibanez\LivewireCharts\Models;
|
||||
|
||||
/**
|
||||
* Class ColumnChartModel
|
||||
* @package Asantibanez\LivewireCharts\Models
|
||||
*/
|
||||
class ColumnChartModel
|
||||
{
|
||||
public $title;
|
||||
|
||||
public $animated;
|
||||
|
||||
public $opacity;
|
||||
|
||||
public $onColumnClickEventName;
|
||||
|
||||
public $data;
|
||||
|
||||
public function __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 [
|
||||
'title' => $this->title,
|
||||
'animated' => $this->animated,
|
||||
'onColumnClickEventName' => $this->onColumnClickEventName,
|
||||
'opacity' => $this->opacity,
|
||||
'data' => $this->data->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
public function 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', []));
|
||||
}
|
||||
|
||||
}
|
||||
110
src/Models/LineChartModel.php
Normal file
110
src/Models/LineChartModel.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Asantibanez\LivewireCharts\Models;
|
||||
|
||||
/**
|
||||
* Class LineChartModel
|
||||
* @package Asantibanez\LivewireCharts\Models
|
||||
*/
|
||||
class LineChartModel
|
||||
{
|
||||
public $title;
|
||||
|
||||
public $animated;
|
||||
|
||||
public $data;
|
||||
|
||||
public $markers;
|
||||
|
||||
public $onPointClickEventName;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->title = '';
|
||||
|
||||
$this->animated = false;
|
||||
|
||||
$this->onPointClickEventName = null;
|
||||
|
||||
$this->data = collect();
|
||||
|
||||
$this->markers = collect();
|
||||
}
|
||||
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAnimated($animated)
|
||||
{
|
||||
$this->animated = $animated;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addPoint($title, $value, $extras = [])
|
||||
{
|
||||
$this->data->push([
|
||||
'title' => $title,
|
||||
'value' => $value,
|
||||
'extras' => $extras,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addMarker($title,
|
||||
$value,
|
||||
$strokeColor = 'green',
|
||||
$text = '',
|
||||
$textColor = '#ffffff',
|
||||
$textBackgroundColor = '#cccccc')
|
||||
{
|
||||
$this->markers->push([
|
||||
'title' => $title,
|
||||
'value' => $value,
|
||||
'strokeColor' => $strokeColor,
|
||||
'text' => $text,
|
||||
'textColor' => $textColor,
|
||||
'textBackgroundColor' => $textBackgroundColor,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withOnPointClickEvent($onPointClickEventName)
|
||||
{
|
||||
$this->onPointClickEventName = $onPointClickEventName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'title' => $this->title,
|
||||
'animated' => $this->animated,
|
||||
'onPointClickEventName' => $this->onPointClickEventName,
|
||||
'data' => $this->data->toArray(),
|
||||
'markers' => $this->markers->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
public function fromArray($array)
|
||||
{
|
||||
$this->title = data_get($array, 'title', '');
|
||||
|
||||
$this->animated = data_get($array, 'animated', false);
|
||||
|
||||
$this->onPointClickEventName = data_get($array, 'onPointClickEventName', null);
|
||||
|
||||
$this->data = collect(data_get($array, 'data', []));
|
||||
|
||||
$this->markers = collect(data_get($array, 'markers', []));
|
||||
}
|
||||
|
||||
}
|
||||
99
src/Models/PieChartModel.php
Normal file
99
src/Models/PieChartModel.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Asantibanez\LivewireCharts\Models;
|
||||
|
||||
/**
|
||||
* Class PieChartModel
|
||||
* @package Asantibanez\LivewireCharts\Models
|
||||
*/
|
||||
class PieChartModel
|
||||
{
|
||||
public $title;
|
||||
|
||||
public $animated;
|
||||
|
||||
public $onSliceClickEventName;
|
||||
|
||||
public $opacity;
|
||||
|
||||
public $data;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->title = '';
|
||||
|
||||
$this->animated = false;
|
||||
|
||||
$this->onSliceClickEventName = null;
|
||||
|
||||
$this->opacity = 0.75;
|
||||
|
||||
$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 withOnSliceClickEvent($onSliceClickEventName)
|
||||
{
|
||||
$this->onSliceClickEventName = $onSliceClickEventName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addSlice($title, $value, $color, $extras = [])
|
||||
{
|
||||
$this->data->push([
|
||||
'title' => $title,
|
||||
'value' => $value,
|
||||
'color' => $color,
|
||||
'extras' => $extras,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'title' => $this->title,
|
||||
'animated' => $this->animated,
|
||||
'onSliceClickEventName' => $this->onSliceClickEventName,
|
||||
'opacity' => $this->opacity,
|
||||
'data' => $this->data->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
public function fromArray($array)
|
||||
{
|
||||
$this->title = data_get($array, 'title', '');
|
||||
|
||||
$this->animated = data_get($array, 'animated', false);
|
||||
|
||||
$this->onSliceClickEventName = data_get($array, 'onSliceClickEventName', null);
|
||||
|
||||
$this->opacity = data_get($array, 'opacity', 0.75);
|
||||
|
||||
$this->data = collect(data_get($array, 'data', []));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user