188de55fdSRico Sonntag<?php 23976b470SGreg Roach 388de55fdSRico Sonntag/** 488de55fdSRico Sonntag * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 688de55fdSRico Sonntag * This program is free software: you can redistribute it and/or modify 788de55fdSRico Sonntag * it under the terms of the GNU General Public License as published by 888de55fdSRico Sonntag * the Free Software Foundation, either version 3 of the License, or 988de55fdSRico Sonntag * (at your option) any later version. 1088de55fdSRico Sonntag * This program is distributed in the hope that it will be useful, 1188de55fdSRico Sonntag * but WITHOUT ANY WARRANTY; without even the implied warranty of 1288de55fdSRico Sonntag * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1388de55fdSRico Sonntag * GNU General Public License for more details. 1488de55fdSRico 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/>. 1688de55fdSRico Sonntag */ 17fcfa147eSGreg Roach 1888de55fdSRico Sonntagdeclare(strict_types=1); 1988de55fdSRico Sonntag 2088de55fdSRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Google; 2188de55fdSRico Sonntag 2288de55fdSRico Sonntaguse Fisharebest\Webtrees\I18N; 2393ccd686SRico Sonntaguse Fisharebest\Webtrees\Statistics\Service\ColorService; 2488de55fdSRico Sonntag 2571378461SGreg Roachuse function count; 2634b20f29SGreg Roachuse function view; 2771378461SGreg Roach 2888de55fdSRico Sonntag/** 2993ccd686SRico Sonntag * A chart showing individuals with sources. 3088de55fdSRico Sonntag */ 3193ccd686SRico Sonntagclass ChartIndividualWithSources 3288de55fdSRico 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 /** 4488de55fdSRico Sonntag * Create a chart showing individuals with/without sources. 4588de55fdSRico Sonntag * 4688de55fdSRico Sonntag * @param int $tot_indi The total number of individuals 4788de55fdSRico Sonntag * @param int $tot_indi_source The total number of individuals with sources 4888de55fdSRico Sonntag * @param string|null $color_from 4988de55fdSRico Sonntag * @param string|null $color_to 5088de55fdSRico Sonntag * 5188de55fdSRico Sonntag * @return string 5288de55fdSRico Sonntag */ 5388de55fdSRico Sonntag public function chartIndisWithSources( 5488de55fdSRico Sonntag int $tot_indi, 5588de55fdSRico Sonntag int $tot_indi_source, 562c6f1bd5SGreg Roach string|null $color_from = null, 57*b50dba3aSGreg Roach string|null $color_to = null 5888de55fdSRico Sonntag ): string { 593529c469SGreg Roach $color_from ??= 'ffffff'; 603529c469SGreg Roach $color_to ??= '84beff'; 6188de55fdSRico Sonntag 6288de55fdSRico Sonntag $data = [ 6388de55fdSRico Sonntag [ 6488de55fdSRico Sonntag I18N::translate('Type'), 6588de55fdSRico Sonntag I18N::translate('Total') 6688de55fdSRico Sonntag ], 67dd7dd2a1SRico Sonntag ]; 68dd7dd2a1SRico Sonntag 69ef475b14SGreg Roach if ($tot_indi > 0 || $tot_indi_source > 0) { 70dd7dd2a1SRico Sonntag $data[] = [ 7188de55fdSRico Sonntag I18N::translate('Without sources'), 7288de55fdSRico Sonntag $tot_indi - $tot_indi_source 73dd7dd2a1SRico Sonntag ]; 74dd7dd2a1SRico Sonntag 75dd7dd2a1SRico Sonntag $data[] = [ 7688de55fdSRico Sonntag I18N::translate('With sources'), 7788de55fdSRico Sonntag $tot_indi_source 7888de55fdSRico Sonntag ]; 79dd7dd2a1SRico Sonntag } 8088de55fdSRico Sonntag 816ccdf4f0SGreg Roach $colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1); 8288de55fdSRico Sonntag 8390a2f718SGreg Roach return view('statistics/other/charts/pie', [ 8488de55fdSRico Sonntag 'title' => I18N::translate('Individuals with sources'), 8588de55fdSRico Sonntag 'data' => $data, 8688de55fdSRico Sonntag 'colors' => $colors, 8788de55fdSRico Sonntag 'labeledValueText' => 'percentage', 8865cf5706SGreg Roach 'language' => I18N::languageTag(), 8990a2f718SGreg Roach ]); 9088de55fdSRico Sonntag } 9188de55fdSRico Sonntag} 92