xref: /webtrees/app/Statistics/Google/ChartSex.php (revision 93ccd68614f026f01c7c92e49f24344e66f17edb)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Statistics\Google;
19
20use Fisharebest\Webtrees\I18N;
21
22/**
23 * A chart showing the distribution of males and females.
24 */
25class ChartSex
26{
27    /**
28     * Generate a chart showing sex distribution.
29     *
30     * @param int         $tot_m         The total number of male individuals
31     * @param int         $tot_f         The total number of female individuals
32     * @param int         $tot_u         The total number of unknown individuals
33     * @param string|null $color_female
34     * @param string|null $color_male
35     * @param string|null $color_unknown
36     *
37     * @return string
38     */
39    public function chartSex(
40        int $tot_m,
41        int $tot_f,
42        int $tot_u,
43        string $color_female  = null,
44        string $color_male    = null,
45        string $color_unknown = null
46    ): string {
47        $color_female  = $color_female  ?? '#ffd1dc';
48        $color_male    = $color_male    ?? '#84beff';
49        $color_unknown = $color_unknown ?? '#777777';
50
51        $data = [
52            [
53                I18N::translate('Type'),
54                I18N::translate('Total')
55            ],
56        ];
57
58        if ($tot_m || $tot_f || $tot_u) {
59            $data[] = [
60                I18N::translate('Males'),
61                $tot_m
62            ];
63
64            $data[] = [
65                I18N::translate('Females'),
66                $tot_f
67            ];
68
69            $data[] = [
70                I18N::translate('Unknown'),
71                $tot_u
72            ];
73        }
74
75        return view(
76            'statistics/other/charts/pie',
77            [
78                'title'            => null,
79                'data'             => $data,
80                'colors'           => [$color_male, $color_female, $color_unknown],
81                'labeledValueText' => 'percentage',
82            ]
83        );
84    }
85}
86