xref: /webtrees/resources/views/statistics/other/charts/geo.phtml (revision 5fb051e95bc3d8a26af94d588bd85bf2d37f583c)
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 class="mb-3">
14        <div class="card-deck">
15            <div class="col-12 mb-3">
16                <div class="card m-0">
17                    <div class="card-header">
18                        <?= $chart_title ?>
19                    </div>
20                    <div class="card-body">
21                        <div id="<?= $id ?>" title="<?= $chart_title ?>"></div>
22                    </div>
23                </div>
24            </div>
25        </div>
26    </div>
27    <script>
28
29    let <?= $name ?> = function () {
30        statistics.drawGeoChart(
31            <?= json_encode($id) ?>,
32            <?= json_encode($data) ?>,
33            {
34                title: <?= json_encode($chart_title) ?>,
35                region: <?= json_encode($region) ?>,
36                colorAxis: {
37                    colors: [
38                        <?= json_encode('#' . $chart_color3) ?>,
39                        <?= json_encode('#' . $chart_color2) ?>
40                    ]
41                }
42            }
43        );
44    };
45
46    if (document.readyState === "complete"
47        || (document.readyState !== "loading" && !document.documentElement.doScroll)
48    ) {
49        statistics.init(<?= json_encode($language) ?>);
50        statistics.addCallback(<?= $name ?>);
51    } else {
52        document.addEventListener("DOMContentLoaded", function () {
53            statistics.init(<?= json_encode($language) ?>);
54            statistics.addCallback(<?= $name ?>);
55        });
56    }
57
58    </script>
59<?php endif; ?>
60