Passed
Push — 2.1 ( bd72ee...1f10eb )
by Greg
05:58
created

ChartSex::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2023 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
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\Statistics\Google;
21
22
use Fisharebest\Webtrees\I18N;
23
24
/**
25
 * A chart showing the distribution of males and females.
26
 */
27
class ChartSex
28
{
29
    public function __construct()
30
    {
31
        // Empty constructor to prevent the "deprecated constructor" warning in PHP 7.4
32
    }
33
34
    /**
35
     * Generate a chart showing sex distribution.
36
     *
37
     * @param int         $tot_m         The total number of male individuals
38
     * @param int         $tot_f         The total number of female individuals
39
     * @param int         $tot_u         The total number of unknown individuals
40
     * @param string|null $color_female
41
     * @param string|null $color_male
42
     * @param string|null $color_unknown
43
     *
44
     * @return string
45
     */
46
    public function chartSex(
47
        int $tot_m,
48
        int $tot_f,
49
        int $tot_u,
50
        string $color_female = null,
51
        string $color_male = null,
52
        string $color_unknown = null
53
    ): string {
54
        $color_female ??= '#ffd1dc';
55
        $color_male ??= '#84beff';
56
        $color_unknown ??= '#777777';
57
58
        $data = [
59
            [
60
                I18N::translate('Type'),
61
                I18N::translate('Total')
62
            ],
63
        ];
64
65
        if ($tot_m > 0 || $tot_f > 0 || $tot_u > 0) {
66
            $data[] = [
67
                I18N::translate('Males'),
68
                $tot_m
69
            ];
70
71
            $data[] = [
72
                I18N::translate('Females'),
73
                $tot_f
74
            ];
75
76
            $data[] = [
77
                I18N::translate('Unknown'),
78
                $tot_u
79
            ];
80
        }
81
82
        return view('statistics/other/charts/pie', [
83
            'title'            => null,
84
            'data'             => $data,
85
            'colors'           => [$color_male, $color_female, $color_unknown],
86
            'labeledValueText' => 'percentage',
87
            'language'         => I18N::languageTag(),
88
        ]);
89
    }
90
}
91