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