xref: /webtrees/resources/views/statistics/other/charts/column.phtml (revision 3c0669a92fe4ada310a6a4b43746fd7241d29577)
188de55fdSRico Sonntag<?php
2d70512abSGreg Roach
388de55fdSRico Sonntagdeclare(strict_types=1);
488de55fdSRico Sonntag
5dd7dd2a1SRico Sonntaguse Fisharebest\Webtrees\I18N;
6dd7dd2a1SRico Sonntag
7dc270d8cSGreg Roach/**
8dc270d8cSGreg Roach * @var array<mixed> $chart_options
9dc270d8cSGreg Roach * @var string       $chart_title
10dc270d8cSGreg Roach * @var array<array> $data
11dc270d8cSGreg Roach * @var string       $language
12dc270d8cSGreg Roach */
13dc270d8cSGreg Roach
1488de55fdSRico Sonntag$id   = 'google-chart-' . bin2hex(random_bytes(8));
1566ce3d23SRico Sonntag$name = 'callback_' . bin2hex(random_bytes(12));
1688de55fdSRico Sonntag?>
1788de55fdSRico Sonntag
18dd7dd2a1SRico Sonntag<?php if (count($data) === 1) : ?>
1939c990acSGreg Roach    <?= I18N::translate('This information is not available.') ?>
20dd7dd2a1SRico Sonntag<?php else : ?>
21dc270d8cSGreg Roach    <div id="<?= $id ?>" title="<?= $chart_title ?>"></div>
2288de55fdSRico Sonntag    <script>
2388de55fdSRico Sonntag
2466ce3d23SRico Sonntag    let <?= $name ?> = function () {
2566ce3d23SRico Sonntag        statistics.drawColumnChart(
26*3c0669a9SGreg Roach            <?= json_encode($id, JSON_THROW_ON_ERROR) ?>,
27*3c0669a9SGreg Roach            <?= json_encode($data, JSON_THROW_ON_ERROR) ?>,
28*3c0669a9SGreg Roach            <?= json_encode($chart_options, JSON_THROW_ON_ERROR) ?>
2988de55fdSRico Sonntag        );
301b860509SRico Sonntag    };
3188de55fdSRico Sonntag
3266ce3d23SRico Sonntag    if (document.readyState === "complete"
3366ce3d23SRico Sonntag        || (document.readyState !== "loading" && !document.documentElement.doScroll)
3488de55fdSRico Sonntag    ) {
35*3c0669a9SGreg Roach        statistics.init(<?= json_encode($language, JSON_THROW_ON_ERROR) ?>);
3666ce3d23SRico Sonntag        statistics.addCallback(<?= $name ?>);
3788de55fdSRico Sonntag    } else {
3866ce3d23SRico Sonntag        document.addEventListener("DOMContentLoaded", function () {
39*3c0669a9SGreg Roach            statistics.init(<?= json_encode($language, JSON_THROW_ON_ERROR) ?>);
4066ce3d23SRico Sonntag            statistics.addCallback(<?= $name ?>);
4166ce3d23SRico Sonntag        });
4288de55fdSRico Sonntag    }
4388de55fdSRico Sonntag
4488de55fdSRico Sonntag    </script>
45dd7dd2a1SRico Sonntag<?php endif; ?>
46