1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2021 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Statistics\Google; 21 22use Fisharebest\Webtrees\I18N; 23use Fisharebest\Webtrees\Statistics\Service\ColorService; 24 25use function count; 26use function view; 27 28/** 29 * A chart showing individuals with sources. 30 */ 31class ChartIndividualWithSources 32{ 33 private ColorService $color_service; 34 35 /** 36 * Constructor. 37 */ 38 public function __construct() 39 { 40 $this->color_service = new ColorService(); 41 } 42 43 /** 44 * Create a chart showing individuals with/without sources. 45 * 46 * @param int $tot_indi The total number of individuals 47 * @param int $tot_indi_source The total number of individuals with sources 48 * @param string|null $color_from 49 * @param string|null $color_to 50 * 51 * @return string 52 */ 53 public function chartIndisWithSources( 54 int $tot_indi, 55 int $tot_indi_source, 56 string $color_from = null, 57 string $color_to = null 58 ): string { 59 $color_from = $color_from ?? 'ffffff'; 60 $color_to = $color_to ?? '84beff'; 61 62 $data = [ 63 [ 64 I18N::translate('Type'), 65 I18N::translate('Total') 66 ], 67 ]; 68 69 if ($tot_indi || $tot_indi_source) { 70 $data[] = [ 71 I18N::translate('Without sources'), 72 $tot_indi - $tot_indi_source 73 ]; 74 75 $data[] = [ 76 I18N::translate('With sources'), 77 $tot_indi_source 78 ]; 79 } 80 81 $colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1); 82 83 return view('statistics/other/charts/pie', [ 84 'title' => I18N::translate('Individuals with sources'), 85 'data' => $data, 86 'colors' => $colors, 87 'labeledValueText' => 'percentage', 88 'language' => I18N::languageTag(), 89 ]); 90 } 91} 92