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 function count; 22 23use Fisharebest\Webtrees\GedcomTag; 24use Fisharebest\Webtrees\I18N; 25use Fisharebest\Webtrees\Module\ModuleThemeInterface; 26use Fisharebest\Webtrees\Statistics\Service\ColorService; 27 28/** 29 * A chart showing the top used media types. 30 */ 31class ChartMedia 32{ 33 /** 34 * @var ModuleThemeInterface 35 */ 36 private $theme; 37 38 /** 39 * @var ColorService 40 */ 41 private $color_service; 42 43 /** 44 * Constructor. 45 */ 46 public function __construct() 47 { 48 $this->theme = app(ModuleThemeInterface::class); 49 $this->color_service = new ColorService(); 50 } 51 52 /** 53 * Create a chart of media types. 54 * 55 * @param array $media The list of media types to display 56 * @param string|null $color_from 57 * @param string|null $color_to 58 * 59 * @return string 60 */ 61 public function chartMedia( 62 array $media, 63 string $color_from = null, 64 string $color_to = null 65 ): string { 66 $chart_color1 = (string) $this->theme->parameter('distribution-chart-no-values'); 67 $chart_color2 = (string) $this->theme->parameter('distribution-chart-high-values'); 68 $color_from = $color_from ?? $chart_color1; 69 $color_to = $color_to ?? $chart_color2; 70 71 $data = [ 72 [ 73 I18N::translate('Type'), 74 I18N::translate('Total') 75 ], 76 ]; 77 78 foreach ($media as $type => $count) { 79 $data[] = [ 80 GedcomTag::getFileFormTypeValue($type), 81 $count 82 ]; 83 } 84 85 $colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1); 86 87 return view( 88 'statistics/other/charts/pie', 89 [ 90 'title' => null, 91 'data' => $data, 92 'colors' => $colors, 93 ] 94 ); 95 } 96} 97