18add1155SRico Sonntag<?php 23976b470SGreg Roach 38add1155SRico Sonntag/** 48add1155SRico Sonntag * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 68add1155SRico Sonntag * This program is free software: you can redistribute it and/or modify 78add1155SRico Sonntag * it under the terms of the GNU General Public License as published by 88add1155SRico Sonntag * the Free Software Foundation, either version 3 of the License, or 98add1155SRico Sonntag * (at your option) any later version. 108add1155SRico Sonntag * This program is distributed in the hope that it will be useful, 118add1155SRico Sonntag * but WITHOUT ANY WARRANTY; without even the implied warranty of 128add1155SRico Sonntag * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 138add1155SRico Sonntag * GNU General Public License for more details. 148add1155SRico Sonntag * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 168add1155SRico Sonntag */ 17fcfa147eSGreg Roach 188add1155SRico Sonntagdeclare(strict_types=1); 198add1155SRico Sonntag 208add1155SRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Google; 218add1155SRico Sonntag 228add1155SRico Sonntaguse Fisharebest\Webtrees\I18N; 2393ccd686SRico Sonntaguse Fisharebest\Webtrees\Statistics\Service\ColorService; 248add1155SRico Sonntag 2571378461SGreg Roachuse function count; 2634b20f29SGreg Roachuse function view; 2771378461SGreg Roach 288add1155SRico Sonntag/** 2993ccd686SRico Sonntag * A chart showing the mortality. 308add1155SRico Sonntag */ 3193ccd686SRico Sonntagclass ChartMortality 328add1155SRico Sonntag{ 3334b20f29SGreg Roach private ColorService $color_service; 3493ccd686SRico Sonntag 3593ccd686SRico Sonntag /** 36f78da678SGreg Roach * @param ColorService $color_service 3793ccd686SRico Sonntag */ 38f78da678SGreg Roach public function __construct(ColorService $color_service) 3993ccd686SRico Sonntag { 40f78da678SGreg Roach $this->color_service = $color_service; 4193ccd686SRico Sonntag } 4293ccd686SRico Sonntag 4393ccd686SRico Sonntag /** 448add1155SRico Sonntag * Create a chart showing mortality. 458add1155SRico Sonntag * 468add1155SRico Sonntag * @param int $tot_l 478add1155SRico Sonntag * @param int $tot_d 488add1155SRico Sonntag * @param string|null $color_living 498add1155SRico Sonntag * @param string|null $color_dead 508add1155SRico Sonntag * 518add1155SRico Sonntag * @return string 528add1155SRico Sonntag */ 538add1155SRico Sonntag public function chartMortality( 548add1155SRico Sonntag int $tot_l, 558add1155SRico Sonntag int $tot_d, 568add1155SRico Sonntag string $color_living = null, 578add1155SRico Sonntag string $color_dead = null 588add1155SRico Sonntag ): string { 593529c469SGreg Roach $color_living ??= '#ffffff'; 603529c469SGreg Roach $color_dead ??= '#cccccc'; 618add1155SRico Sonntag 6288de55fdSRico Sonntag $data = [ 6388de55fdSRico Sonntag [ 6488de55fdSRico Sonntag I18N::translate('Century'), 6588de55fdSRico Sonntag I18N::translate('Total') 66dd7dd2a1SRico Sonntag ] 67dd7dd2a1SRico Sonntag ]; 68dd7dd2a1SRico Sonntag 69ef475b14SGreg Roach if ($tot_l > 0 || $tot_d > 0) { 70dd7dd2a1SRico Sonntag $data[] = [ 7188de55fdSRico Sonntag I18N::translate('Living'), 7288de55fdSRico Sonntag $tot_l 73dd7dd2a1SRico Sonntag ]; 74dd7dd2a1SRico Sonntag 75dd7dd2a1SRico Sonntag $data[] = [ 7688de55fdSRico Sonntag I18N::translate('Dead'), 7788de55fdSRico Sonntag $tot_d 7888de55fdSRico Sonntag ]; 79dd7dd2a1SRico Sonntag } 808add1155SRico Sonntag 816ccdf4f0SGreg Roach $colors = $this->color_service->interpolateRgb($color_living, $color_dead, count($data) - 1); 828add1155SRico Sonntag 8390a2f718SGreg Roach return view('statistics/other/charts/pie', [ 8488de55fdSRico Sonntag 'title' => null, 8588de55fdSRico Sonntag 'data' => $data, 8688de55fdSRico Sonntag 'colors' => $colors, 8788de55fdSRico Sonntag 'labeledValueText' => 'percentage', 8865cf5706SGreg Roach 'language' => I18N::languageTag(), 8990a2f718SGreg Roach ]); 908add1155SRico Sonntag } 918add1155SRico Sonntag} 92