18add1155SRico Sonntag<?php 23976b470SGreg Roach 38add1155SRico Sonntag/** 48add1155SRico Sonntag * webtrees: online genealogy 5242a7862SGreg Roach * Copyright (C) 2019 webtrees development team 68add1155SRico Sonntag * This program is free software: you can redistribute it and/or modify 78add1155SRico Sonntag * it under the terms of the GNU General Public License as published by 88add1155SRico Sonntag * the Free Software Foundation, either version 3 of the License, or 98add1155SRico Sonntag * (at your option) any later version. 108add1155SRico Sonntag * This program is distributed in the hope that it will be useful, 118add1155SRico Sonntag * but WITHOUT ANY WARRANTY; without even the implied warranty of 128add1155SRico Sonntag * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 138add1155SRico Sonntag * GNU General Public License for more details. 148add1155SRico Sonntag * You should have received a copy of the GNU General Public License 158add1155SRico Sonntag * along with this program. If not, see <http://www.gnu.org/licenses/>. 168add1155SRico Sonntag */ 17fcfa147eSGreg Roach 188add1155SRico Sonntagdeclare(strict_types=1); 198add1155SRico Sonntag 208add1155SRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Google; 218add1155SRico Sonntag 22*90a2f718SGreg Roachuse Fisharebest\Localization\Locale\LocaleInterface; 238add1155SRico Sonntaguse Fisharebest\Webtrees\I18N; 2493ccd686SRico Sonntaguse Fisharebest\Webtrees\Module\ModuleThemeInterface; 2593ccd686SRico Sonntaguse Fisharebest\Webtrees\Statistics\Service\ColorService; 26*90a2f718SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 278add1155SRico Sonntag 28*90a2f718SGreg Roachuse function app; 29*90a2f718SGreg Roachuse function assert; 3071378461SGreg Roachuse function count; 3171378461SGreg Roach 328add1155SRico Sonntag/** 3393ccd686SRico Sonntag * A chart showing families with sources. 348add1155SRico Sonntag */ 3593ccd686SRico Sonntagclass ChartFamilyWithSources 368add1155SRico Sonntag{ 378add1155SRico Sonntag /** 3893ccd686SRico Sonntag * @var ModuleThemeInterface 3993ccd686SRico Sonntag */ 4093ccd686SRico Sonntag private $theme; 4193ccd686SRico Sonntag 4293ccd686SRico Sonntag /** 4393ccd686SRico Sonntag * @var ColorService 4493ccd686SRico Sonntag */ 4593ccd686SRico Sonntag private $color_service; 4693ccd686SRico Sonntag 4793ccd686SRico Sonntag /** 4893ccd686SRico Sonntag * Constructor. 4993ccd686SRico Sonntag */ 5093ccd686SRico Sonntag public function __construct() 5193ccd686SRico Sonntag { 52cab242e7SGreg Roach $this->theme = app(ModuleThemeInterface::class); 5393ccd686SRico Sonntag $this->color_service = new ColorService(); 5493ccd686SRico Sonntag } 5593ccd686SRico Sonntag 5693ccd686SRico Sonntag /** 578add1155SRico Sonntag * Create a chart of individuals with/without sources. 588add1155SRico Sonntag * 598add1155SRico Sonntag * @param int $tot_fam The total number of families 608add1155SRico Sonntag * @param int $tot_fam_source The total number of families with sources 618add1155SRico Sonntag * @param string|null $color_from 628add1155SRico Sonntag * @param string|null $color_to 638add1155SRico Sonntag * 648add1155SRico Sonntag * @return string 658add1155SRico Sonntag */ 668add1155SRico Sonntag public function chartFamsWithSources( 678add1155SRico Sonntag int $tot_fam, 688add1155SRico Sonntag int $tot_fam_source, 698add1155SRico Sonntag string $color_from = null, 708add1155SRico Sonntag string $color_to = null 718add1155SRico Sonntag ): string { 7288de55fdSRico Sonntag $chart_color1 = (string) $this->theme->parameter('distribution-chart-no-values'); 7388de55fdSRico Sonntag $chart_color2 = (string) $this->theme->parameter('distribution-chart-high-values'); 748add1155SRico Sonntag $color_from = $color_from ?? $chart_color1; 758add1155SRico Sonntag $color_to = $color_to ?? $chart_color2; 768add1155SRico Sonntag 7788de55fdSRico Sonntag $data = [ 7888de55fdSRico Sonntag [ 7988de55fdSRico Sonntag I18N::translate('Type'), 8088de55fdSRico Sonntag I18N::translate('Total') 8188de55fdSRico Sonntag ], 82dd7dd2a1SRico Sonntag ]; 83dd7dd2a1SRico Sonntag 84dd7dd2a1SRico Sonntag if ($tot_fam || $tot_fam_source) { 85dd7dd2a1SRico Sonntag $data[] = [ 8688de55fdSRico Sonntag I18N::translate('Without sources'), 8788de55fdSRico Sonntag $tot_fam - $tot_fam_source 88dd7dd2a1SRico Sonntag ]; 89dd7dd2a1SRico Sonntag 90dd7dd2a1SRico Sonntag $data[] = [ 9188de55fdSRico Sonntag I18N::translate('With sources'), 9288de55fdSRico Sonntag $tot_fam_source 9388de55fdSRico Sonntag ]; 94dd7dd2a1SRico Sonntag } 958add1155SRico Sonntag 966ccdf4f0SGreg Roach $colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1); 978add1155SRico Sonntag 98*90a2f718SGreg Roach $locale = app(ServerRequestInterface::class)->getAttribute('locale'); 99*90a2f718SGreg Roach assert($locale instanceof LocaleInterface); 100*90a2f718SGreg Roach 101*90a2f718SGreg Roach return view('statistics/other/charts/pie', [ 10288de55fdSRico Sonntag 'title' => I18N::translate('Families with sources'), 10388de55fdSRico Sonntag 'data' => $data, 10488de55fdSRico Sonntag 'colors' => $colors, 10588de55fdSRico Sonntag 'labeledValueText' => 'percentage', 106*90a2f718SGreg Roach 'language' => $locale->languageTag(), 107*90a2f718SGreg Roach ]); 1088add1155SRico Sonntag } 1098add1155SRico Sonntag} 110