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