xref: /webtrees/app/Statistics/Google/ChartFamilyWithSources.php (revision b50dba3a86d260384d07c30bedf82d8e78ab49f7)
18add1155SRico Sonntag<?php
23976b470SGreg Roach
38add1155SRico Sonntag/**
48add1155SRico Sonntag * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
68add1155SRico Sonntag * This program is free software: you can redistribute it and/or modify
78add1155SRico Sonntag * it under the terms of the GNU General Public License as published by
88add1155SRico Sonntag * the Free Software Foundation, either version 3 of the License, or
98add1155SRico Sonntag * (at your option) any later version.
108add1155SRico Sonntag * This program is distributed in the hope that it will be useful,
118add1155SRico Sonntag * but WITHOUT ANY WARRANTY; without even the implied warranty of
128add1155SRico Sonntag * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
138add1155SRico Sonntag * GNU General Public License for more details.
148add1155SRico Sonntag * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
168add1155SRico Sonntag */
17fcfa147eSGreg Roach
188add1155SRico Sonntagdeclare(strict_types=1);
198add1155SRico Sonntag
208add1155SRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Google;
218add1155SRico Sonntag
228add1155SRico Sonntaguse Fisharebest\Webtrees\I18N;
2393ccd686SRico Sonntaguse Fisharebest\Webtrees\Statistics\Service\ColorService;
248add1155SRico Sonntag
2571378461SGreg Roachuse function count;
2634b20f29SGreg Roachuse function view;
2771378461SGreg Roach
288add1155SRico Sonntag/**
2993ccd686SRico Sonntag * A chart showing families with sources.
308add1155SRico Sonntag */
3193ccd686SRico Sonntagclass ChartFamilyWithSources
328add1155SRico Sonntag{
3334b20f29SGreg Roach    private ColorService $color_service;
3493ccd686SRico Sonntag
3593ccd686SRico Sonntag    /**
36f78da678SGreg Roach     * @param ColorService $color_service
3793ccd686SRico Sonntag     */
38f78da678SGreg Roach    public function __construct(ColorService $color_service)
3993ccd686SRico Sonntag    {
40f78da678SGreg Roach        $this->color_service = $color_service;
4193ccd686SRico Sonntag    }
4293ccd686SRico Sonntag
4393ccd686SRico Sonntag    /**
448add1155SRico Sonntag     * Create a chart of individuals with/without sources.
458add1155SRico Sonntag     *
468add1155SRico Sonntag     * @param int         $tot_fam        The total number of families
478add1155SRico Sonntag     * @param int         $tot_fam_source The total number of families with sources
488add1155SRico Sonntag     * @param string|null $color_from
498add1155SRico Sonntag     * @param string|null $color_to
508add1155SRico Sonntag     *
518add1155SRico Sonntag     * @return string
528add1155SRico Sonntag     */
538add1155SRico Sonntag    public function chartFamsWithSources(
548add1155SRico Sonntag        int $tot_fam,
558add1155SRico Sonntag        int $tot_fam_source,
562c6f1bd5SGreg Roach        string|null $color_from = null,
57*b50dba3aSGreg Roach        string|null $color_to = null
588add1155SRico Sonntag    ): string {
593529c469SGreg Roach        $color_from ??= 'ffffff';
603529c469SGreg Roach        $color_to ??= '84beff';
618add1155SRico Sonntag
6288de55fdSRico Sonntag        $data = [
6388de55fdSRico Sonntag            [
6488de55fdSRico Sonntag                I18N::translate('Type'),
6588de55fdSRico Sonntag                I18N::translate('Total')
6688de55fdSRico Sonntag            ],
67dd7dd2a1SRico Sonntag        ];
68dd7dd2a1SRico Sonntag
69ef475b14SGreg Roach        if ($tot_fam > 0 || $tot_fam_source > 0) {
70dd7dd2a1SRico Sonntag            $data[] = [
7188de55fdSRico Sonntag                I18N::translate('Without sources'),
7288de55fdSRico Sonntag                $tot_fam - $tot_fam_source
73dd7dd2a1SRico Sonntag            ];
74dd7dd2a1SRico Sonntag
75dd7dd2a1SRico Sonntag            $data[] = [
7688de55fdSRico Sonntag                I18N::translate('With sources'),
7788de55fdSRico Sonntag                $tot_fam_source
7888de55fdSRico Sonntag            ];
79dd7dd2a1SRico Sonntag        }
808add1155SRico Sonntag
816ccdf4f0SGreg Roach        $colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1);
828add1155SRico Sonntag
8390a2f718SGreg Roach        return view('statistics/other/charts/pie', [
8488de55fdSRico Sonntag            'title'            => I18N::translate('Families with sources'),
8588de55fdSRico Sonntag            'data'             => $data,
8688de55fdSRico Sonntag            'colors'           => $colors,
8788de55fdSRico Sonntag            'labeledValueText' => 'percentage',
8865cf5706SGreg Roach            'language'         => I18N::languageTag(),
8990a2f718SGreg Roach        ]);
908add1155SRico Sonntag    }
918add1155SRico Sonntag}
92