xref: /webtrees/app/Statistics/Google/ChartSex.php (revision dd7dd2a11a7399e56fa4d21fb56b0ecdff69c7d0)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2018 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;
21use Fisharebest\Webtrees\Statistics\AbstractGoogle;
22
23/**
24 *
25 */
26class ChartSex extends AbstractGoogle
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