xref: /webtrees/resources/views/statistics/other/charts/geo.phtml (revision 12a0693f1b6760e019806135ae71270602315868)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\I18N;
6
7$id   = 'google-chart-' . bin2hex(random_bytes(8));
8$name = 'callback_' . bin2hex(random_bytes(12));
9?>
10
11<?php if (count($data) === 1) : ?>
12    <?= I18N::translate('This information is not available.') ?>
13<?php else : ?>
14    <div class="mb-3">
15        <div class="card-deck">
16            <div class="col-12 mb-3">
17                <div class="card m-0">
18                    <div class="card-header">
19                        <?= $chart_title ?>
20                    </div>
21                    <div class="card-body">
22                        <div id="<?= $id ?>" title="<?= $chart_title ?>"></div>
23                    </div>
24                </div>
25            </div>
26        </div>
27    </div>
28    <script>
29
30    let <?= $name ?> = function () {
31        statistics.drawGeoChart(
32            <?= json_encode($id) ?>,
33            <?= json_encode($data) ?>,
34            {
35                title: <?= json_encode($chart_title) ?>,
36                region: <?= json_encode($region) ?>,
37                colorAxis: {
38                    colors: [
39                        <?= json_encode('#' . $chart_color3) ?>,
40                        <?= json_encode('#' . $chart_color2) ?>
41                    ]
42                }
43            }
44        );
45    };
46
47    if (document.readyState === "complete"
48        || (document.readyState !== "loading" && !document.documentElement.doScroll)
49    ) {
50        statistics.init(<?= json_encode($language) ?>);
51        statistics.addCallback(<?= $name ?>);
52    } else {
53        document.addEventListener("DOMContentLoaded", function () {
54            statistics.init(<?= json_encode($language) ?>);
55            statistics.addCallback(<?= $name ?>);
56        });
57    }
58
59    </script>
60<?php endif; ?>
61