1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>. 16 */ 17declare(strict_types=1); 18 19namespace Fisharebest\Webtrees\Statistics\Google; 20 21use Fisharebest\Webtrees\I18N; 22use Fisharebest\Webtrees\Module\ModuleThemeInterface; 23use Fisharebest\Webtrees\Statistics\Service\ColorService; 24 25use function count; 26 27/** 28 * A chart showing families with sources. 29 */ 30class ChartFamilyWithSources 31{ 32 /** 33 * @var ModuleThemeInterface 34 */ 35 private $theme; 36 37 /** 38 * @var ColorService 39 */ 40 private $color_service; 41 42 /** 43 * Constructor. 44 */ 45 public function __construct() 46 { 47 $this->theme = app(ModuleThemeInterface::class); 48 $this->color_service = new ColorService(); 49 } 50 51 /** 52 * Create a chart of individuals with/without sources. 53 * 54 * @param int $tot_fam The total number of families 55 * @param int $tot_fam_source The total number of families with sources 56 * @param string|null $color_from 57 * @param string|null $color_to 58 * 59 * @return string 60 */ 61 public function chartFamsWithSources( 62 int $tot_fam, 63 int $tot_fam_source, 64 string $color_from = null, 65 string $color_to = null 66 ): string { 67 $chart_color1 = (string) $this->theme->parameter('distribution-chart-no-values'); 68 $chart_color2 = (string) $this->theme->parameter('distribution-chart-high-values'); 69 $color_from = $color_from ?? $chart_color1; 70 $color_to = $color_to ?? $chart_color2; 71 72 $data = [ 73 [ 74 I18N::translate('Type'), 75 I18N::translate('Total') 76 ], 77 ]; 78 79 if ($tot_fam || $tot_fam_source) { 80 $data[] = [ 81 I18N::translate('Without sources'), 82 $tot_fam - $tot_fam_source 83 ]; 84 85 $data[] = [ 86 I18N::translate('With sources'), 87 $tot_fam_source 88 ]; 89 } 90 91 $colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1); 92 93 return view( 94 'statistics/other/charts/pie', 95 [ 96 'title' => I18N::translate('Families with sources'), 97 'data' => $data, 98 'colors' => $colors, 99 'labeledValueText' => 'percentage', 100 ] 101 ); 102 } 103} 104