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