18add1155SRico Sonntag<?php 23976b470SGreg Roach 38add1155SRico Sonntag/** 48add1155SRico Sonntag * webtrees: online genealogy 5*89f7189bSGreg Roach * Copyright (C) 2021 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 15*89f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 168add1155SRico Sonntag */ 17fcfa147eSGreg Roach 188add1155SRico Sonntagdeclare(strict_types=1); 198add1155SRico Sonntag 208add1155SRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Google; 218add1155SRico Sonntag 228add1155SRico Sonntaguse Fisharebest\Webtrees\I18N; 2393ccd686SRico Sonntaguse Fisharebest\Webtrees\Module\ModuleThemeInterface; 2493ccd686SRico Sonntaguse Fisharebest\Webtrees\Statistics\Service\ColorService; 258add1155SRico Sonntag 2690a2f718SGreg Roachuse function app; 2771378461SGreg Roachuse function count; 2871378461SGreg Roach 298add1155SRico Sonntag/** 3093ccd686SRico Sonntag * A chart showing families with sources. 318add1155SRico Sonntag */ 3293ccd686SRico Sonntagclass ChartFamilyWithSources 338add1155SRico Sonntag{ 348add1155SRico Sonntag /** 3593ccd686SRico Sonntag * @var ModuleThemeInterface 3693ccd686SRico Sonntag */ 3793ccd686SRico Sonntag private $theme; 3893ccd686SRico Sonntag 3993ccd686SRico Sonntag /** 4093ccd686SRico Sonntag * @var ColorService 4193ccd686SRico Sonntag */ 4293ccd686SRico Sonntag private $color_service; 4393ccd686SRico Sonntag 4493ccd686SRico Sonntag /** 4593ccd686SRico Sonntag * Constructor. 4693ccd686SRico Sonntag */ 4793ccd686SRico Sonntag public function __construct() 4893ccd686SRico Sonntag { 49cab242e7SGreg Roach $this->theme = app(ModuleThemeInterface::class); 5093ccd686SRico Sonntag $this->color_service = new ColorService(); 5193ccd686SRico Sonntag } 5293ccd686SRico Sonntag 5393ccd686SRico Sonntag /** 548add1155SRico Sonntag * Create a chart of individuals with/without sources. 558add1155SRico Sonntag * 568add1155SRico Sonntag * @param int $tot_fam The total number of families 578add1155SRico Sonntag * @param int $tot_fam_source The total number of families with sources 588add1155SRico Sonntag * @param string|null $color_from 598add1155SRico Sonntag * @param string|null $color_to 608add1155SRico Sonntag * 618add1155SRico Sonntag * @return string 628add1155SRico Sonntag */ 638add1155SRico Sonntag public function chartFamsWithSources( 648add1155SRico Sonntag int $tot_fam, 658add1155SRico Sonntag int $tot_fam_source, 668add1155SRico Sonntag string $color_from = null, 678add1155SRico Sonntag string $color_to = null 688add1155SRico Sonntag ): string { 6988de55fdSRico Sonntag $chart_color1 = (string) $this->theme->parameter('distribution-chart-no-values'); 7088de55fdSRico Sonntag $chart_color2 = (string) $this->theme->parameter('distribution-chart-high-values'); 718add1155SRico Sonntag $color_from = $color_from ?? $chart_color1; 728add1155SRico Sonntag $color_to = $color_to ?? $chart_color2; 738add1155SRico Sonntag 7488de55fdSRico Sonntag $data = [ 7588de55fdSRico Sonntag [ 7688de55fdSRico Sonntag I18N::translate('Type'), 7788de55fdSRico Sonntag I18N::translate('Total') 7888de55fdSRico Sonntag ], 79dd7dd2a1SRico Sonntag ]; 80dd7dd2a1SRico Sonntag 81dd7dd2a1SRico Sonntag if ($tot_fam || $tot_fam_source) { 82dd7dd2a1SRico Sonntag $data[] = [ 8388de55fdSRico Sonntag I18N::translate('Without sources'), 8488de55fdSRico Sonntag $tot_fam - $tot_fam_source 85dd7dd2a1SRico Sonntag ]; 86dd7dd2a1SRico Sonntag 87dd7dd2a1SRico Sonntag $data[] = [ 8888de55fdSRico Sonntag I18N::translate('With sources'), 8988de55fdSRico Sonntag $tot_fam_source 9088de55fdSRico Sonntag ]; 91dd7dd2a1SRico Sonntag } 928add1155SRico Sonntag 936ccdf4f0SGreg Roach $colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1); 948add1155SRico Sonntag 9590a2f718SGreg Roach return view('statistics/other/charts/pie', [ 9688de55fdSRico Sonntag 'title' => I18N::translate('Families with sources'), 9788de55fdSRico Sonntag 'data' => $data, 9888de55fdSRico Sonntag 'colors' => $colors, 9988de55fdSRico Sonntag 'labeledValueText' => 'percentage', 10065cf5706SGreg Roach 'language' => I18N::languageTag(), 10190a2f718SGreg Roach ]); 1028add1155SRico Sonntag } 1038add1155SRico Sonntag} 104