xref: /webtrees/resources/views/statistics/other/charts/geo.phtml (revision 6353b9318c10a598e6d1937cf87856662d3d7f54)
1<?php
2declare(strict_types=1);
3
4use Fisharebest\Localization\Locale\LocaleInterface;
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(app(LocaleInterface::class)->code()) ?>);
51        statistics.addCallback(<?= $name ?>);
52    } else {
53        document.addEventListener("DOMContentLoaded", function () {
54            statistics.init(<?= json_encode(app(LocaleInterface::class)->code()) ?>);
55            statistics.addCallback(<?= $name ?>);
56        });
57    }
58
59    </script>
60<?php endif; ?>
61