1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2018 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 Fisharebest\Webtrees\I18N; 21use Fisharebest\Webtrees\Module\ModuleThemeInterface; 22use Fisharebest\Webtrees\Statistics\AbstractGoogle; 23use Fisharebest\Webtrees\Theme; 24 25/** 26 * 27 */ 28class ChartFamilyWithSources extends AbstractGoogle 29{ 30 /** 31 * Create a chart of individuals with/without sources. 32 * 33 * @param int $tot_fam The total number of families 34 * @param int $tot_fam_source The total number of families with sources 35 * @param string|null $size 36 * @param string|null $color_from 37 * @param string|null $color_to 38 * 39 * @return string 40 */ 41 public function chartFamsWithSources( 42 int $tot_fam, 43 int $tot_fam_source, 44 string $size = null, 45 string $color_from = null, 46 string $color_to = null 47 ): string { 48 $chart_color1 = (string) app()->make(ModuleThemeInterface::class)->parameter('distribution-chart-no-values'); 49 $chart_color2 = (string) app()->make(ModuleThemeInterface::class)->parameter('distribution-chart-high-values'); 50 $chart_x = app()->make(ModuleThemeInterface::class)->parameter('stats-small-chart-x'); 51 $chart_y = app()->make(ModuleThemeInterface::class)->parameter('stats-small-chart-y'); 52 53 $size = $size ?? ($chart_x . 'x' . $chart_y); 54 $color_from = $color_from ?? $chart_color1; 55 $color_to = $color_to ?? $chart_color2; 56 57 $sizes = explode('x', $size); 58 59 if ($tot_fam === 0) { 60 return ''; 61 } 62 63 $tot_sfam_per = $tot_fam_source / $tot_fam; 64 $with = (int) (100 * $tot_sfam_per); 65 $chd = $this->arrayToExtendedEncoding([100 - $with, $with]); 66 $chl = I18N::translate('Without sources') . ' - ' . I18N::percentage(1 - $tot_sfam_per, 1) . '|' . I18N::translate('With sources') . ' - ' . I18N::percentage($tot_sfam_per, 1); 67 $colors = [$color_from, $color_to]; 68 69 return view( 70 'statistics/other/chart-google', 71 [ 72 'chart_title' => I18N::translate('Families with sources'), 73 'chart_url' => $this->getPieChartUrl($chd, $size, $colors, $chl), 74 'sizes' => $sizes, 75 ] 76 ); 77 } 78} 79