@if(isset($PocetKontrolPodlaKategorieVozidlaEChartSource) && $PocetKontrolPodlaKategorieVozidlaEChartSource->isNotEmpty())
    <div id="EChartPocetKontrolPodlaKategorieVozidla" style="height:400px"></div>

    @push('scripts')
        <script type="text/javascript">
            $(document).ready(function () {
                const EChartPocetKontrolPodlaKategorieVozidla = echarts.init(document.getElementById('EChartPocetKontrolPodlaKategorieVozidla'), 'macarons');

                window.addEventListener('resize', function () {
                    EChartPocetKontrolPodlaKategorieVozidla.resize();
                });

                EChartPocetKontrolPodlaKategorieVozidla.setOption({
                    backgroundColor: 'transparent',
                    grid: {
                        height: 200,
                        top: 'auto',
                    },
                    legend: {
                        show: true,
                        type: 'plain',
                        align: 'right',
                        right: 0,
                        top: 60,
                        orient: 'vertical',
                        zlevel: 100,
                    },
                    tooltip: {
                        trigger: 'item',
                    },
                    toolbox: {
                        show: true,
                        orient: 'horizontal',
                        top: 0,
                        right: 0,
                        zlevel: 100,
                        feature: {
                            saveAsImage: {
                                type: 'png',
                                name: 'pek-pocet-kontrol-podla-kategorie-vozidla',
                                backgroundColor: 'white',
                                show: true,
                                title: 'Uložiť ako obrázok',
                            },
                            restore: {
                                show: true,
                                title: 'Obnoviť',
                            },
                        },
                    },
                    series: [{
                        type: 'pie',
                        radius: ['30%', '70%'],
                        center: ['30%', '40%',],
                        itemStyle: {
                            borderRadius: 10,
                            borderColor: '#fff',
                            borderWidth: 2,
                        },
                        startAngle: 15,
                        encode: {
                            itemName: 'label',
                            value: 'pocet',
                        },
                        animation: true,
                        animationType: 'scale',
                        animationEasing: 'elasticOut',
                        animationDelay: function (idx) {
                            return Math.random() * 400;
                        },
                        label: {
                            show: true,
                            position: 'outside',
                            rotate: false,
                        },
                        datasetIndex: 1,
                    }],
                    dataset: [
                        {
                            dimensions: [
                                {
                                    name: 'kategoria',
                                    type: 'ordinal',
                                },
                                {
                                    name: 'label',
                                    type: 'ordinal',
                                },
                                {
                                    name: 'pocet',
                                    type: 'number',
                                }
                            ],
                            source: @json($PocetKontrolPodlaKategorieVozidlaEChartSource ?? []),
                        },
                        {
                            transform: [
                                {
                                    type: 'sort',
                                    config: {
                                        dimension: 'kategoria',
                                        order: 'asc',
                                    },
                                }
                            ],
                        }
                    ],
                });
            });
        </script>
    @endpush
@else
    <p class="h4 text-center text-muted">Nie sú k dispozícii žiadne údaje...</p>
@endif
