xref: /webtrees/app/Statistics/Google/ChartIndividualWithSources.php (revision dd7dd2a11a7399e56fa4d21fb56b0ecdff69c7d0)
188de55fdSRico Sonntag<?php
288de55fdSRico Sonntag/**
388de55fdSRico Sonntag * webtrees: online genealogy
488de55fdSRico Sonntag * Copyright (C) 2018 webtrees development team
588de55fdSRico Sonntag * This program is free software: you can redistribute it and/or modify
688de55fdSRico Sonntag * it under the terms of the GNU General Public License as published by
788de55fdSRico Sonntag * the Free Software Foundation, either version 3 of the License, or
888de55fdSRico Sonntag * (at your option) any later version.
988de55fdSRico Sonntag * This program is distributed in the hope that it will be useful,
1088de55fdSRico Sonntag * but WITHOUT ANY WARRANTY; without even the implied warranty of
1188de55fdSRico Sonntag * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1288de55fdSRico Sonntag * GNU General Public License for more details.
1388de55fdSRico Sonntag * You should have received a copy of the GNU General Public License
1488de55fdSRico Sonntag * along with this program. If not, see <http://www.gnu.org/licenses/>.
1588de55fdSRico Sonntag */
1688de55fdSRico Sonntagdeclare(strict_types=1);
1788de55fdSRico Sonntag
1888de55fdSRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Google;
1988de55fdSRico Sonntag
2088de55fdSRico Sonntaguse Fisharebest\Webtrees\I18N;
2188de55fdSRico Sonntaguse Fisharebest\Webtrees\Statistics\AbstractGoogle;
2288de55fdSRico Sonntag
2388de55fdSRico Sonntag/**
2488de55fdSRico Sonntag *
2588de55fdSRico Sonntag */
2688de55fdSRico Sonntagclass ChartIndividualWithSources extends AbstractGoogle
2788de55fdSRico Sonntag{
2888de55fdSRico Sonntag    /**
2988de55fdSRico Sonntag     * Create a chart showing individuals with/without sources.
3088de55fdSRico Sonntag     *
3188de55fdSRico Sonntag     * @param int         $tot_indi        The total number of individuals
3288de55fdSRico Sonntag     * @param int         $tot_indi_source The total number of individuals with sources
3388de55fdSRico Sonntag     * @param string|null $color_from
3488de55fdSRico Sonntag     * @param string|null $color_to
3588de55fdSRico Sonntag     *
3688de55fdSRico Sonntag     * @return string
3788de55fdSRico Sonntag     */
3888de55fdSRico Sonntag    public function chartIndisWithSources(
3988de55fdSRico Sonntag        int $tot_indi,
4088de55fdSRico Sonntag        int $tot_indi_source,
4188de55fdSRico Sonntag        string $color_from = null,
4288de55fdSRico Sonntag        string $color_to   = null
4388de55fdSRico 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');
4688de55fdSRico Sonntag        $color_from   = $color_from ?? $chart_color1;
4788de55fdSRico Sonntag        $color_to     = $color_to   ?? $chart_color2;
4888de55fdSRico Sonntag
4988de55fdSRico Sonntag        $data = [
5088de55fdSRico Sonntag            [
5188de55fdSRico Sonntag                I18N::translate('Type'),
5288de55fdSRico Sonntag                I18N::translate('Total')
5388de55fdSRico Sonntag            ],
54*dd7dd2a1SRico Sonntag        ];
55*dd7dd2a1SRico Sonntag
56*dd7dd2a1SRico Sonntag        if ($tot_indi || $tot_indi_source) {
57*dd7dd2a1SRico Sonntag            $data[] = [
5888de55fdSRico Sonntag                I18N::translate('Without sources'),
5988de55fdSRico Sonntag                $tot_indi - $tot_indi_source
60*dd7dd2a1SRico Sonntag            ];
61*dd7dd2a1SRico Sonntag
62*dd7dd2a1SRico Sonntag            $data[] = [
6388de55fdSRico Sonntag                I18N::translate('With sources'),
6488de55fdSRico Sonntag                $tot_indi_source
6588de55fdSRico Sonntag            ];
66*dd7dd2a1SRico Sonntag        }
6788de55fdSRico Sonntag
6888de55fdSRico Sonntag        $colors = $this->interpolateRgb($color_from, $color_to, \count($data) - 1);
6988de55fdSRico Sonntag
7088de55fdSRico Sonntag        return view(
7188de55fdSRico Sonntag            'statistics/other/charts/pie',
7288de55fdSRico Sonntag            [
7388de55fdSRico Sonntag                'title'            => I18N::translate('Individuals with sources'),
7488de55fdSRico Sonntag                'data'             => $data,
7588de55fdSRico Sonntag                'colors'           => $colors,
7688de55fdSRico Sonntag                'labeledValueText' => 'percentage',
7788de55fdSRico Sonntag            ]
7888de55fdSRico Sonntag        );
7988de55fdSRico Sonntag    }
8088de55fdSRico Sonntag}
81