xref: /webtrees/resources/views/statistics/other/charts/geo.phtml (revision 6b1381a306f9b3ddbe167a71b6a607d5ab7a609d)
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 class="mb-3">
16        <div class="card-deck">
17            <div class="col-12 mb-3">
18                <div class="card m-0">
19                    <div class="card-header">
20                        <?= $chart_title ?>
21                    </div>
22                    <div class="card-body">
23                        <div id="<?= $id ?>" title="<?= $chart_title ?>"></div>
24                    </div>
25                </div>
26            </div>
27        </div>
28    </div>
29
30    <script>
31
32    var callbackGeoChart = function () {
33        var options = {
34            title: '<?= $chart_title ?>',
35            region: '<?= $region ?>',
36            colorAxis: {
37                colors: [
38                    '#<?= $chart_color3 ?>',
39                    '#<?= $chart_color2 ?>'
40                ]
41            }
42        };
43
44        google.charts.setOnLoadCallback(function () {
45            drawGeoChart(
46                '<?= $id ?>',
47                <?= json_encode($data) ?>,
48                options
49            );
50        });
51
52        $(window).resize(function () {
53            drawGeoChart(
54                '<?= $id ?>',
55                <?= json_encode($data) ?>,
56                options
57            );
58        });
59    };
60
61    if (
62        document.readyState === "complete" ||
63        (document.readyState !== "loading" && !document.documentElement.doScroll)
64    ) {
65        callbackGeoChart();
66    } else {
67        document.addEventListener("DOMContentLoaded", callbackGeoChart);
68    }
69
70    </script>
71<?php endif; ?>
72