xref: /webtrees/resources/views/statistics/other/charts/pie.phtml (revision 0c0910bf0f275a14f35d2ccdf698f91f79e269d4)
1<?php
2declare(strict_types=1);
3
4use Fisharebest\Webtrees\I18N;
5
6$id = 'google-chart-' . bin2hex(random_bytes(8));
7?>
8
9<?php if (count($data) === 1): ?>
10    <?= I18N::translate('This information is not available.') ?>
11<?php else: ?>
12
13    <?= view('statistics/other/chart-setup') ?>
14
15    <div id="<?= $id ?>"></div>
16
17    <script>
18
19    var callbackPieChart = function () {
20        google.charts.setOnLoadCallback(function () {
21            drawPieChart(
22                '<?= $id ?>',
23                <?= json_encode($data) ?>,
24                <?= json_encode($colors) ?>,
25                '<?= $title ?>',
26                '<?= $labeledValueText ?? 'value' ?>'
27            );
28        });
29
30        $(window).resize(function () {
31            drawPieChart(
32                '<?= $id ?>',
33                <?= json_encode($data) ?>,
34                <?= json_encode($colors) ?>,
35                '<?= $title ?>',
36                '<?= $labeledValueText ?? 'value' ?>'
37            );
38        });
39    };
40
41    if (
42        document.readyState === "complete" ||
43        (document.readyState !== "loading" && !document.documentElement.doScroll)
44    ) {
45        callbackPieChart();
46    } else {
47        document.addEventListener("DOMContentLoaded", callbackPieChart);
48    }
49
50    </script>
51<?php endif; ?>
52