xref: /webtrees/app/Statistics/Google/ChartSex.php (revision d812eb6b3dd6c33a96d07cd964cb4c3b88cec447)
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 Fisharebest\Webtrees\I18N;
22
23/**
24 * A chart showing the distribution of males and females.
25 */
26class ChartSex
27{
28    /**
29     * Generate a chart showing sex distribution.
30     *
31     * @param int         $tot_m         The total number of male individuals
32     * @param int         $tot_f         The total number of female individuals
33     * @param int         $tot_u         The total number of unknown individuals
34     * @param string|null $color_female
35     * @param string|null $color_male
36     * @param string|null $color_unknown
37     *
38     * @return string
39     */
40    public function chartSex(
41        int $tot_m,
42        int $tot_f,
43        int $tot_u,
44        string $color_female = null,
45        string $color_male = null,
46        string $color_unknown = null
47    ): string {
48        $color_female  = $color_female  ?? '#ffd1dc';
49        $color_male    = $color_male    ?? '#84beff';
50        $color_unknown = $color_unknown ?? '#777777';
51
52        $data = [
53            [
54                I18N::translate('Type'),
55                I18N::translate('Total')
56            ],
57        ];
58
59        if ($tot_m || $tot_f || $tot_u) {
60            $data[] = [
61                I18N::translate('Males'),
62                $tot_m
63            ];
64
65            $data[] = [
66                I18N::translate('Females'),
67                $tot_f
68            ];
69
70            $data[] = [
71                I18N::translate('Unknown'),
72                $tot_u
73            ];
74        }
75
76        return view(
77            'statistics/other/charts/pie',
78            [
79                'title'            => null,
80                'data'             => $data,
81                'colors'           => [$color_male, $color_female, $color_unknown],
82                'labeledValueText' => 'percentage',
83            ]
84        );
85    }
86}
87