18add1155SRico Sonntag<?php 28add1155SRico Sonntag/** 38add1155SRico Sonntag * webtrees: online genealogy 4*242a7862SGreg Roach * Copyright (C) 2019 webtrees development team 58add1155SRico Sonntag * This program is free software: you can redistribute it and/or modify 68add1155SRico Sonntag * it under the terms of the GNU General Public License as published by 78add1155SRico Sonntag * the Free Software Foundation, either version 3 of the License, or 88add1155SRico Sonntag * (at your option) any later version. 98add1155SRico Sonntag * This program is distributed in the hope that it will be useful, 108add1155SRico Sonntag * but WITHOUT ANY WARRANTY; without even the implied warranty of 118add1155SRico Sonntag * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 128add1155SRico Sonntag * GNU General Public License for more details. 138add1155SRico Sonntag * You should have received a copy of the GNU General Public License 148add1155SRico Sonntag * along with this program. If not, see <http://www.gnu.org/licenses/>. 158add1155SRico Sonntag */ 168add1155SRico Sonntagdeclare(strict_types=1); 178add1155SRico Sonntag 188add1155SRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Google; 198add1155SRico Sonntag 208add1155SRico Sonntaguse Fisharebest\Webtrees\I18N; 218add1155SRico Sonntaguse Fisharebest\Webtrees\Statistics\AbstractGoogle; 228add1155SRico Sonntag 238add1155SRico Sonntag/** 248add1155SRico Sonntag * 258add1155SRico Sonntag */ 268add1155SRico Sonntagclass ChartCommonGiven extends AbstractGoogle 278add1155SRico Sonntag{ 288add1155SRico Sonntag /** 298add1155SRico Sonntag * Create a chart of common given names. 308add1155SRico Sonntag * 318add1155SRico Sonntag * @param int $tot_indi The total number of individuals 328add1155SRico Sonntag * @param array $given The list of common given names 338add1155SRico Sonntag * @param string|null $color_from 348add1155SRico Sonntag * @param string|null $color_to 358add1155SRico Sonntag * 368add1155SRico Sonntag * @return string 378add1155SRico Sonntag */ 388add1155SRico Sonntag public function chartCommonGiven( 398add1155SRico Sonntag int $tot_indi, 408add1155SRico Sonntag array $given, 418add1155SRico Sonntag string $color_from = null, 428add1155SRico Sonntag string $color_to = null 438add1155SRico Sonntag ) : string { 4488de55fdSRico Sonntag $chart_color1 = (string) $this->theme->parameter('distribution-chart-no-values'); 4588de55fdSRico Sonntag $chart_color2 = (string) $this->theme->parameter('distribution-chart-high-values'); 468add1155SRico Sonntag $color_from = $color_from ?? $chart_color1; 478add1155SRico Sonntag $color_to = $color_to ?? $chart_color2; 488add1155SRico Sonntag 498add1155SRico Sonntag $tot = 0; 508add1155SRico Sonntag foreach ($given as $count) { 518add1155SRico Sonntag $tot += $count; 528add1155SRico Sonntag } 538add1155SRico Sonntag 5488de55fdSRico Sonntag $data = [ 5588de55fdSRico Sonntag [ 5688de55fdSRico Sonntag I18N::translate('Name'), 5788de55fdSRico Sonntag I18N::translate('Total') 5888de55fdSRico Sonntag ], 5988de55fdSRico Sonntag ]; 608add1155SRico Sonntag 6188de55fdSRico Sonntag foreach ($given as $name => $count) { 6288de55fdSRico Sonntag $data[] = [ $name, $count ]; 638add1155SRico Sonntag } 648add1155SRico Sonntag 6588de55fdSRico Sonntag $data[] = [ 6688de55fdSRico Sonntag I18N::translate('Other'), 6788de55fdSRico Sonntag $tot_indi - $tot 6888de55fdSRico Sonntag ]; 698add1155SRico Sonntag 7088de55fdSRico Sonntag $colors = $this->interpolateRgb($color_from, $color_to, \count($data) - 1); 718add1155SRico Sonntag 728add1155SRico Sonntag return view( 7388de55fdSRico Sonntag 'statistics/other/charts/pie', 748add1155SRico Sonntag [ 7588de55fdSRico Sonntag 'title' => null, 7688de55fdSRico Sonntag 'data' => $data, 7788de55fdSRico Sonntag 'colors' => $colors, 788add1155SRico Sonntag ] 798add1155SRico Sonntag ); 808add1155SRico Sonntag } 818add1155SRico Sonntag} 82