1<?php 2 3declare(strict_types=1); 4 5use Fisharebest\Webtrees\I18N; 6 7$id = 'google-chart-' . bin2hex(random_bytes(8)); 8$name = 'callback_' . bin2hex(random_bytes(12)); 9?> 10 11<?php if (count($data) === 1) : ?> 12 <?= I18N::translate('This information is not available.') ?> 13<?php else : ?> 14 <div id="<?= $id ?>"></div> 15 <script> 16 17 let <?= $name ?> = function () { 18 statistics.drawPieChart( 19 <?= json_encode($id) ?>, 20 <?= json_encode($data) ?>, 21 { 22 title: <?= json_encode($title) ?>, 23 24 // Note: "legend" needs to be defined completely as Object.assign does only a shallow merge 25 legend: { 26 alignment: 'center', 27 labeledValueText: <?= json_encode($labeledValueText ?? 'value') ?>, 28 position: 'labeled' 29 }, 30 colors: <?= json_encode($colors) ?> 31 } 32 ); 33 }; 34 35 if (document.readyState === "complete" 36 || (document.readyState !== "loading" && !document.documentElement.doScroll) 37 ) { 38 statistics.init(<?= json_encode($language) ?>); 39 statistics.addCallback(<?= $name ?>); 40 } else { 41 document.addEventListener("DOMContentLoaded", function () { 42 statistics.init(<?= json_encode($language) ?>); 43 statistics.addCallback(<?= $name ?>); 44 }); 45 } 46 47 </script> 48<?php endif; ?> 49