xref: /webtrees/resources/views/statistics/other/charts/pie.phtml (revision f49178372ce2fce90124921dd80544f39495cda8)
1<?php
2declare(strict_types=1);
3
4use Fisharebest\Webtrees\I18N;
5
6$id   = 'google-chart-' . bin2hex(random_bytes(8));
7$name = 'callback_' . bin2hex(random_bytes(12));
8?>
9
10<?php if (count($data) === 1): ?>
11    <?= I18N::translate('This information is not available.') ?>
12<?php else: ?>
13    <div id="<?= $id ?>"></div>
14    <script>
15
16    let <?= $name ?> = function () {
17        statistics.drawPieChart(
18            <?= json_encode($id) ?>,
19            <?= json_encode($data) ?>,
20            {
21                title: <?= json_encode($title) ?>,
22
23                // Note: "legend" needs to be defined completely as Object.assign does only a shallow merge
24                legend: {
25                    alignment: 'center',
26                    labeledValueText: <?= json_encode($labeledValueText ?? 'value') ?>,
27                    position: 'labeled'
28                },
29                colors: <?= json_encode($colors) ?>
30            }
31        );
32    };
33
34    if (document.readyState === "complete"
35        || (document.readyState !== "loading" && !document.documentElement.doScroll)
36    ) {
37        statistics.init(<?= json_encode($language) ?>);
38        statistics.addCallback(<?= $name ?>);
39    } else {
40        document.addEventListener("DOMContentLoaded", function () {
41            statistics.init(<?= json_encode($language) ?>);
42            statistics.addCallback(<?= $name ?>);
43        });
44    }
45
46    </script>
47<?php endif; ?>
48