Commit awal: prototipe UI SIAKAD Untan
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
{{--
|
||||
Grafik Chart.js dengan data nyata. type: bar | line | doughnut. datasets: [['label' => ..., 'data' => [...]]].
|
||||
Tabel tersembunyi menyediakan data yang sama bagi pembaca layar.
|
||||
--}}
|
||||
@props(['title', 'type' => 'bar', 'labels' => [], 'datasets' => [], 'description' => null, 'height' => '16rem'])
|
||||
|
||||
@php
|
||||
$type = in_array($type, ['bar', 'line', 'doughnut'], true) ? $type : 'bar';
|
||||
$id = 'chart-'.\Illuminate\Support\Str::random(6);
|
||||
@endphp
|
||||
|
||||
<x-glass.panel as="figure" {{ $attributes->class('chart') }}>
|
||||
<figcaption class="panel-title">
|
||||
<h2>{{ $title }}</h2>
|
||||
</figcaption>
|
||||
@if ($description) <p class="stat__hint">{{ $description }}</p> @endif
|
||||
|
||||
@if (count($labels) === 0)
|
||||
<x-ui.empty icon="chart-bar" title="Belum ada data" description="Grafik tampil setelah data tersedia." />
|
||||
@else
|
||||
<div class="chart__canvas" style="height: {{ $height }}" x-data="chartCanvas(@js(['type' => $type, 'labels' => $labels, 'datasets' => $datasets]))">
|
||||
<canvas x-ref="canvas" id="{{ $id }}" role="img" aria-label="{{ $title }}"></canvas>
|
||||
</div>
|
||||
<table class="visually-hidden">
|
||||
<caption>{{ $title }}</caption>
|
||||
<thead>
|
||||
<tr><th scope="col">Kategori</th>@foreach ($datasets as $ds)<th scope="col">{{ $ds['label'] ?? 'Nilai' }}</th>@endforeach</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($labels as $i => $label)
|
||||
<tr><th scope="row">{{ $label }}</th>@foreach ($datasets as $ds)<td>{{ $ds['data'][$i] ?? 0 }}</td>@endforeach</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
@endif
|
||||
</x-glass.panel>
|
||||
Reference in New Issue
Block a user