xref: /webtrees/resources/views/statistics/other/charts/combo.phtml (revision 728c8c2714cc197d45bad7363eb52e0bff3297bb)
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 array<array> $data
10dc270d8cSGreg Roach * @var string       $language
11dc270d8cSGreg Roach */
12dc270d8cSGreg Roach
1388de55fdSRico Sonntag$id   = 'google-chart-' . bin2hex(random_bytes(8));
1466ce3d23SRico Sonntag$name = 'callback_' . bin2hex(random_bytes(12));
1588de55fdSRico Sonntag?>
1688de55fdSRico Sonntag
17dd7dd2a1SRico Sonntag<?php if (count($data) === 1) : ?>
1839c990acSGreg Roach    <?= I18N::translate('This information is not available.') ?>
19dd7dd2a1SRico Sonntag<?php else : ?>
201b860509SRico Sonntag    <div id="<?= $id ?>" title="<?= $chart_title ?? '' ?>"></div>
2188de55fdSRico Sonntag    <script>
2288de55fdSRico Sonntag
2366ce3d23SRico Sonntag    let <?= $name ?> = function () {
2466ce3d23SRico Sonntag        statistics.drawComboChart(
25*728c8c27SGreg Roach            <?= json_encode($id, JSON_THROW_ON_ERROR) ?>,
26*728c8c27SGreg Roach            <?= json_encode($data, JSON_THROW_ON_ERROR) ?>,
27*728c8c27SGreg Roach            <?= json_encode($chart_options, JSON_THROW_ON_ERROR) ?>
2888de55fdSRico Sonntag        );
2988de55fdSRico Sonntag    };
3088de55fdSRico Sonntag
3166ce3d23SRico Sonntag    if (document.readyState === "complete"
3266ce3d23SRico Sonntag        || (document.readyState !== "loading" && !document.documentElement.doScroll)
3388de55fdSRico Sonntag    ) {
34*728c8c27SGreg Roach        statistics.init(<?= json_encode($language, JSON_THROW_ON_ERROR) ?>);
3566ce3d23SRico Sonntag        statistics.addCallback(<?= $name ?>);
3688de55fdSRico Sonntag    } else {
3766ce3d23SRico Sonntag        document.addEventListener("DOMContentLoaded", function () {
38*728c8c27SGreg Roach            statistics.init(<?= json_encode($language, JSON_THROW_ON_ERROR) ?>);
3966ce3d23SRico Sonntag            statistics.addCallback(<?= $name ?>);
4066ce3d23SRico Sonntag        });
4188de55fdSRico Sonntag    }
4288de55fdSRico Sonntag
4388de55fdSRico Sonntag    </script>
44dd7dd2a1SRico Sonntag<?php endif; ?>
45