xref: /webtrees/resources/views/statistics/other/charts/geo.phtml (revision a020b8bd22327c55a48db9cc18431b6152b701c4)
188de55fdSRico Sonntag<?php
2d70512abSGreg Roach
388de55fdSRico Sonntagdeclare(strict_types=1);
488de55fdSRico Sonntag
5a81e5019SRico Sonntaguse Fisharebest\Webtrees\I18N;
6a81e5019SRico Sonntag
7dc270d8cSGreg Roach/**
8dc270d8cSGreg Roach * @var string                                            $chart_color2
9dc270d8cSGreg Roach * @var string                                            $chart_color3
10dc270d8cSGreg Roach * @var string                                            $chart_title
11*a020b8bdSGreg Roach * @var array<int,array<int|string|array<string,string>>> $data
12dc270d8cSGreg Roach * @var string                                            $language
13dc270d8cSGreg Roach * @var string                                            $region
14dc270d8cSGreg Roach */
15dc270d8cSGreg Roach
1688de55fdSRico Sonntag$id   = 'google-chart-' . bin2hex(random_bytes(8));
1766ce3d23SRico Sonntag$name = 'callback_' . bin2hex(random_bytes(12));
1888de55fdSRico Sonntag?>
1988de55fdSRico Sonntag
20a81e5019SRico Sonntag<?php if (count($data) === 1) : ?>
2139c990acSGreg Roach    <?= I18N::translate('This information is not available.') ?>
22a81e5019SRico Sonntag<?php else : ?>
2361275c55SJonathan Jaubart    <div class="d-grid mb-3">
2461275c55SJonathan Jaubart        <div class="card">
25a81e5019SRico Sonntag            <div class="card-header">
26a81e5019SRico Sonntag                <?= $chart_title ?>
2788de55fdSRico Sonntag            </div>
28a81e5019SRico Sonntag            <div class="card-body">
29a81e5019SRico Sonntag                <div id="<?= $id ?>" title="<?= $chart_title ?>"></div>
3088de55fdSRico Sonntag            </div>
3188de55fdSRico Sonntag        </div>
3288de55fdSRico Sonntag    </div>
3388de55fdSRico Sonntag    <script>
3488de55fdSRico Sonntag
3566ce3d23SRico Sonntag    let <?= $name ?> = function () {
3666ce3d23SRico Sonntag        statistics.drawGeoChart(
373c0669a9SGreg Roach            <?= json_encode($id, JSON_THROW_ON_ERROR) ?>,
383c0669a9SGreg Roach            <?= json_encode($data, JSON_THROW_ON_ERROR) ?>,
3966ce3d23SRico Sonntag            {
403c0669a9SGreg Roach                title: <?= json_encode($chart_title, JSON_THROW_ON_ERROR) ?>,
413c0669a9SGreg Roach                region: <?= json_encode($region, JSON_THROW_ON_ERROR) ?>,
4288de55fdSRico Sonntag                colorAxis: {
4388de55fdSRico Sonntag                    colors: [
443c0669a9SGreg Roach                        <?= json_encode('#' . $chart_color3, JSON_THROW_ON_ERROR) ?>,
453c0669a9SGreg Roach                        <?= json_encode('#' . $chart_color2, JSON_THROW_ON_ERROR) ?>
4688de55fdSRico Sonntag                    ]
4788de55fdSRico Sonntag                }
4866ce3d23SRico Sonntag            }
4966ce3d23SRico Sonntag        );
5088de55fdSRico Sonntag    };
5188de55fdSRico Sonntag
5266ce3d23SRico Sonntag    if (document.readyState === "complete"
5366ce3d23SRico Sonntag        || (document.readyState !== "loading" && !document.documentElement.doScroll)
5488de55fdSRico Sonntag    ) {
553c0669a9SGreg Roach        statistics.init(<?= json_encode($language, JSON_THROW_ON_ERROR) ?>);
5666ce3d23SRico Sonntag        statistics.addCallback(<?= $name ?>);
5788de55fdSRico Sonntag    } else {
5866ce3d23SRico Sonntag        document.addEventListener("DOMContentLoaded", function () {
593c0669a9SGreg Roach            statistics.init(<?= json_encode($language, JSON_THROW_ON_ERROR) ?>);
6066ce3d23SRico Sonntag            statistics.addCallback(<?= $name ?>);
6166ce3d23SRico Sonntag        });
6288de55fdSRico Sonntag    }
6388de55fdSRico Sonntag
6488de55fdSRico Sonntag    </script>
65a81e5019SRico Sonntag<?php endif; ?>
66