xref: /webtrees/app/Statistics/Google/ChartFamilyWithSources.php (revision 242a78626998a767db1568b24919e94ae4b38ac3)
18add1155SRico Sonntag<?php
28add1155SRico Sonntag/**
38add1155SRico Sonntag * webtrees: online genealogy
4*242a7862SGreg Roach * Copyright (C) 2019 webtrees development team
58add1155SRico Sonntag * This program is free software: you can redistribute it and/or modify
68add1155SRico Sonntag * it under the terms of the GNU General Public License as published by
78add1155SRico Sonntag * the Free Software Foundation, either version 3 of the License, or
88add1155SRico Sonntag * (at your option) any later version.
98add1155SRico Sonntag * This program is distributed in the hope that it will be useful,
108add1155SRico Sonntag * but WITHOUT ANY WARRANTY; without even the implied warranty of
118add1155SRico Sonntag * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
128add1155SRico Sonntag * GNU General Public License for more details.
138add1155SRico Sonntag * You should have received a copy of the GNU General Public License
148add1155SRico Sonntag * along with this program. If not, see <http://www.gnu.org/licenses/>.
158add1155SRico Sonntag */
168add1155SRico Sonntagdeclare(strict_types=1);
178add1155SRico Sonntag
188add1155SRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Google;
198add1155SRico Sonntag
208add1155SRico Sonntaguse Fisharebest\Webtrees\I18N;
218add1155SRico Sonntaguse Fisharebest\Webtrees\Statistics\AbstractGoogle;
228add1155SRico Sonntag
238add1155SRico Sonntag/**
248add1155SRico Sonntag *
258add1155SRico Sonntag */
268add1155SRico Sonntagclass ChartFamilyWithSources extends AbstractGoogle
278add1155SRico Sonntag{
288add1155SRico Sonntag    /**
298add1155SRico Sonntag     * Create a chart of individuals with/without sources.
308add1155SRico Sonntag     *
318add1155SRico Sonntag     * @param int         $tot_fam        The total number of families
328add1155SRico Sonntag     * @param int         $tot_fam_source The total number of families with sources
338add1155SRico Sonntag     * @param string|null $color_from
348add1155SRico Sonntag     * @param string|null $color_to
358add1155SRico Sonntag     *
368add1155SRico Sonntag     * @return string
378add1155SRico Sonntag     */
388add1155SRico Sonntag    public function chartFamsWithSources(
398add1155SRico Sonntag        int $tot_fam,
408add1155SRico Sonntag        int $tot_fam_source,
418add1155SRico Sonntag        string $color_from = null,
428add1155SRico Sonntag        string $color_to   = null
438add1155SRico Sonntag    ): string {
4488de55fdSRico Sonntag        $chart_color1 = (string) $this->theme->parameter('distribution-chart-no-values');
4588de55fdSRico Sonntag        $chart_color2 = (string) $this->theme->parameter('distribution-chart-high-values');
468add1155SRico Sonntag        $color_from   = $color_from ?? $chart_color1;
478add1155SRico Sonntag        $color_to     = $color_to   ?? $chart_color2;
488add1155SRico Sonntag
4988de55fdSRico Sonntag        $data = [
5088de55fdSRico Sonntag            [
5188de55fdSRico Sonntag                I18N::translate('Type'),
5288de55fdSRico Sonntag                I18N::translate('Total')
5388de55fdSRico Sonntag            ],
54dd7dd2a1SRico Sonntag        ];
55dd7dd2a1SRico Sonntag
56dd7dd2a1SRico Sonntag        if ($tot_fam || $tot_fam_source) {
57dd7dd2a1SRico Sonntag            $data[] = [
5888de55fdSRico Sonntag                I18N::translate('Without sources'),
5988de55fdSRico Sonntag                $tot_fam - $tot_fam_source
60dd7dd2a1SRico Sonntag            ];
61dd7dd2a1SRico Sonntag
62dd7dd2a1SRico Sonntag            $data[] = [
6388de55fdSRico Sonntag                I18N::translate('With sources'),
6488de55fdSRico Sonntag                $tot_fam_source
6588de55fdSRico Sonntag            ];
66dd7dd2a1SRico Sonntag        }
678add1155SRico Sonntag
6888de55fdSRico Sonntag        $colors = $this->interpolateRgb($color_from, $color_to, \count($data) - 1);
698add1155SRico Sonntag
708add1155SRico Sonntag        return view(
7188de55fdSRico Sonntag            'statistics/other/charts/pie',
728add1155SRico Sonntag            [
7388de55fdSRico Sonntag                'title'            => I18N::translate('Families with sources'),
7488de55fdSRico Sonntag                'data'             => $data,
7588de55fdSRico Sonntag                'colors'           => $colors,
7688de55fdSRico Sonntag                'labeledValueText' => 'percentage',
778add1155SRico Sonntag            ]
788add1155SRico Sonntag        );
798add1155SRico Sonntag    }
808add1155SRico Sonntag}
81