forked from eatvio/eatvio-infra
56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Livewire\Profile;
|
|
|
|
use Livewire\Component;
|
|
use App\Models\User;
|
|
use Asantibanez\LivewireCharts\Models\LineChartModel;
|
|
|
|
class CircumferenceChart extends Component
|
|
{
|
|
public User $user;
|
|
|
|
protected $listeners = ['circumference-chart-updated' => '$refresh'];
|
|
|
|
public function render()
|
|
{
|
|
|
|
$lastOneMisure = $this
|
|
->user
|
|
->circumference_measures()
|
|
->get()
|
|
->last();
|
|
|
|
$lastFourMisures = $this
|
|
->user
|
|
->circumference_measures()
|
|
->orderBy('created_at', 'desc')
|
|
->limit(4)
|
|
->get()
|
|
->sortBy('id');
|
|
|
|
$lineChartModel =
|
|
(new LineChartModel())
|
|
->setSmoothCurve()
|
|
->multiLine()
|
|
->setColors(['#b2df8a', '#1f78b4', '#e3a6a6']);
|
|
|
|
$lastFourMisures->each(
|
|
function ($item, $key) use ($lineChartModel) {
|
|
$createdAt = \Carbon\Carbon::parse($item['created_at'])->format('d.m.y');
|
|
$lineChartModel->addSeriesPoint(__('chest'), $createdAt, $item['chest_circumference']);
|
|
$lineChartModel->addSeriesPoint(__('waist'), $createdAt, $item['waist_circumference']);
|
|
$lineChartModel->addSeriesPoint(__('hip'), $createdAt, $item['hip_circumference']);
|
|
});
|
|
|
|
return view(
|
|
'livewire.profile.circumference-chart',
|
|
[
|
|
'user' => $this->user,
|
|
'lineChartModel' => $lineChartModel,
|
|
'lastOneMisure' => $lastOneMisure,
|
|
]
|
|
);
|
|
}
|
|
}
|