Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Use CSS variables in Statistics charts for colour customisation #4103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Module/StatisticsChartModule.php
Expand Up @@ -1020,13 +1020,13 @@ private function myPlot(
],
'hAxis' => [
'title' => $x_axis_title ?? '',
],
'colors' => $colors,
]
];

return view('statistics/other/charts/custom', [
'data' => $data,
'chart_options' => $chart_options,
'chart_colors' => $colors,
'chart_title' => $chart_title,
'language' => I18N::languageTag(),
]);
Expand Down
9 changes: 3 additions & 6 deletions app/Statistics.php
Expand Up @@ -55,7 +55,6 @@
use Fisharebest\Webtrees\Statistics\Repository\ServerRepository;
use Fisharebest\Webtrees\Statistics\Repository\UserRepository;
use Fisharebest\Webtrees\Statistics\Service\CenturyService;
use Fisharebest\Webtrees\Statistics\Service\ColorService;
use Fisharebest\Webtrees\Statistics\Service\CountryService;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -131,26 +130,24 @@ class Statistics implements
* Create the statistics for a tree.
*
* @param CenturyService $century_service
* @param ColorService $color_service
* @param CountryService $country_service
* @param ModuleService $module_service
* @param Tree $tree Generate statistics for this tree
* @param UserService $user_service
*/
public function __construct(
CenturyService $century_service,
ColorService $color_service,
CountryService $country_service,
ModuleService $module_service,
Tree $tree,
UserService $user_service
) {
$this->tree = $tree;
$this->gedcom_repository = new GedcomRepository($tree);
$this->individual_repository = new IndividualRepository($century_service, $color_service, $tree);
$this->family_repository = new FamilyRepository($century_service, $color_service, $tree);
$this->individual_repository = new IndividualRepository($century_service, $tree);
$this->family_repository = new FamilyRepository($century_service, $tree);
$this->family_dates_repository = new FamilyDatesRepository($tree);
$this->media_repository = new MediaRepository($color_service, $tree);
$this->media_repository = new MediaRepository($tree);
$this->event_repository = new EventRepository($tree);
$this->user_repository = new UserRepository($tree, $user_service);
$this->server_repository = new ServerRepository();
Expand Down
13 changes: 7 additions & 6 deletions app/Statistics/Google/ChartAge.php
Expand Up @@ -137,18 +137,19 @@ public function chartAge(): string
],
'hAxis' => [
'title' => I18N::translate('Century'),
],
'colors' => [
'#84beff',
'#ffd1dc',
'#ff0000',
],
]
];
$chart_colors = [
['--sex-m-chart', '#84beff'],
['--sex-f-chart', '#ffd1dc'],
['--chart-values-avg', '#ff0000']
];

return view('statistics/other/charts/combo', [
'data' => $data,
'chart_options' => $chart_options,
'chart_title' => $chart_title,
'chart_colors' => $chart_colors,
'language' => I18N::languageTag(),
]);
}
Expand Down
16 changes: 5 additions & 11 deletions app/Statistics/Google/ChartBirth.php
Expand Up @@ -21,7 +21,6 @@

use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Statistics\Service\CenturyService;
use Fisharebest\Webtrees\Statistics\Service\ColorService;
use Fisharebest\Webtrees\Tree;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Support\Collection;
Expand All @@ -38,17 +37,13 @@ class ChartBirth

private CenturyService $century_service;

private ColorService $color_service;

/**
* @param CenturyService $century_service
* @param ColorService $color_service
* @param Tree $tree
*/
public function __construct(CenturyService $century_service, ColorService $color_service, Tree $tree)
public function __construct(CenturyService $century_service, Tree $tree)
{
$this->century_service = $century_service;
$this->color_service = $color_service;
$this->tree = $tree;
}

Expand Down Expand Up @@ -87,8 +82,8 @@ private function queryRecords(): Collection
*/
public function chartBirth(string $color_from = null, string $color_to = null): string
{
$color_from = $color_from ?? 'ffffff';
$color_to = $color_to ?? '84beff';
$color_from = $color_from ?? ['--chart-values-low', '#ffffff'];
$color_to = $color_to ?? ['--chart-values-high', '#84beff'];

$data = [
[
Expand All @@ -104,12 +99,11 @@ public function chartBirth(string $color_from = null, string $color_to = null):
];
}

$colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1);

return view('statistics/other/charts/pie', [
'title' => I18N::translate('Births by century'),
'data' => $data,
'colors' => $colors,
'colors' => [$color_from, $color_to],
'steps' => count($data) - 1,
'language' => I18N::languageTag(),
]);
}
Expand Down
4 changes: 1 addition & 3 deletions app/Statistics/Google/ChartChildren.php
Expand Up @@ -108,14 +108,12 @@ public function chartChildren(): string
'hAxis' => [
'title' => I18N::translate('Century'),
],
'colors' => [
'#84beff'
],
];

return view('statistics/other/charts/column', [
'data' => $data,
'chart_options' => $chart_options,
'chart_colors' => [ ['--chart-values-default', '#84beff'] ],
'chart_title' => $chart_title,
'language' => I18N::languageTag(),
]);
Expand Down
20 changes: 4 additions & 16 deletions app/Statistics/Google/ChartCommonGiven.php
Expand Up @@ -20,7 +20,6 @@
namespace Fisharebest\Webtrees\Statistics\Google;

use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Statistics\Service\ColorService;

use function count;
use function view;
Expand All @@ -30,16 +29,6 @@
*/
class ChartCommonGiven
{
private ColorService $color_service;

/**
* @param ColorService $color_service
*/
public function __construct(ColorService $color_service)
{
$this->color_service = $color_service;
}

/**
* Create a chart of common given names.
*
Expand All @@ -56,8 +45,8 @@ public function chartCommonGiven(
string $color_from = null,
string $color_to = null
): string {
$color_from = $color_from ?? 'ffffff';
$color_to = $color_to ?? '84beff';
$color_from = $color_from ?? ['--chart-values-low', '#ffffff'];
$color_to = $color_to ?? ['--chart-values-high', '#84beff'];

$tot = 0;
foreach ($given as $count) {
Expand All @@ -80,12 +69,11 @@ public function chartCommonGiven(
$tot_indi - $tot
];

$colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1);

return view('statistics/other/charts/pie', [
'title' => null,
'data' => $data,
'colors' => $colors,
'colors' => [$color_from, $color_to],
'steps' => count($data) - 1,
'language' => I18N::languageTag(),
]);
}
Expand Down
16 changes: 5 additions & 11 deletions app/Statistics/Google/ChartCommonSurname.php
Expand Up @@ -20,7 +20,6 @@
namespace Fisharebest\Webtrees\Statistics\Google;

use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Statistics\Service\ColorService;
use Fisharebest\Webtrees\SurnameTradition\PolishSurnameTradition;
use Fisharebest\Webtrees\SurnameTradition\SurnameTraditionInterface;

Expand All @@ -34,18 +33,14 @@
*/
class ChartCommonSurname
{
private ColorService $color_service;

private SurnameTraditionInterface $surname_tradition;

/**
* @param ColorService $color_service
* @param SurnameTraditionInterface $surname_tradition
*/
public function __construct(ColorService $color_service, SurnameTraditionInterface $surname_tradition)
public function __construct(SurnameTraditionInterface $surname_tradition)
{
$this->surname_tradition = $surname_tradition;
$this->color_service = $color_service;
}

/**
Expand Down Expand Up @@ -114,8 +109,8 @@ public function chartCommonSurnames(
string $color_from = null,
string $color_to = null
): string {
$color_from = $color_from ?? 'ffffff';
$color_to = $color_to ?? '84beff';
$color_from = $color_from ?? ['--chart-values-low', '#ffffff'];
$color_to = $color_to ?? ['--chart-values-high', '#84beff'];

$tot = 0;
foreach ($all_surnames as $surnames) {
Expand All @@ -138,12 +133,11 @@ public function chartCommonSurnames(
$tot_indi - $tot
];

$colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1);

return view('statistics/other/charts/pie', [
'title' => null,
'data' => $data,
'colors' => $colors,
'colors' => [$color_from, $color_to],
'steps' => count($data) - 1,
'language' => I18N::languageTag(),
]);
}
Expand Down
16 changes: 5 additions & 11 deletions app/Statistics/Google/ChartDeath.php
Expand Up @@ -21,7 +21,6 @@

use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Statistics\Service\CenturyService;
use Fisharebest\Webtrees\Statistics\Service\ColorService;
use Fisharebest\Webtrees\Tree;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Support\Collection;
Expand All @@ -38,17 +37,13 @@ class ChartDeath

private CenturyService $century_service;

private ColorService $color_service;

/**
* @param CenturyService $century_service
* @param ColorService $color_service
* @param Tree $tree
*/
public function __construct(CenturyService $century_service, ColorService $color_service, Tree $tree)
public function __construct(CenturyService $century_service, Tree $tree)
{
$this->century_service = $century_service;
$this->color_service = $color_service;
$this->tree = $tree;
}

Expand Down Expand Up @@ -87,8 +82,8 @@ private function queryRecords(): Collection
*/
public function chartDeath(string $color_from = null, string $color_to = null): string
{
$color_from = $color_from ?? 'ffffff';
$color_to = $color_to ?? '84beff';
$color_from = $color_from ?? ['--chart-values-low', '#ffffff'];
$color_to = $color_to ?? ['--chart-values-high', '#84beff'];

$data = [
[
Expand All @@ -104,12 +99,11 @@ public function chartDeath(string $color_from = null, string $color_to = null):
];
}

$colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1);

return view('statistics/other/charts/pie', [
'title' => I18N::translate('Deaths by century'),
'data' => $data,
'colors' => $colors,
'colors' => [$color_from, $color_to],
'steps' => count($data) - 1,
'language' => I18N::languageTag(),
]);
}
Expand Down
3 changes: 1 addition & 2 deletions app/Statistics/Google/ChartDistribution.php
Expand Up @@ -343,8 +343,7 @@ public function chartDistribution(

return view('statistics/other/charts/geo', [
'chart_title' => $chart_title,
'chart_color2' => '84beff',
'chart_color3' => 'c3dfff',
'chart_colors' => [['--chart-values-high', '84beff'], ['--chart-values-default', 'c3dfff']],
'region' => $chart_shows,
'data' => $data,
'language' => I18N::languageTag(),
Expand Down
16 changes: 5 additions & 11 deletions app/Statistics/Google/ChartDivorce.php
Expand Up @@ -21,7 +21,6 @@

use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Statistics\Service\CenturyService;
use Fisharebest\Webtrees\Statistics\Service\ColorService;
use Fisharebest\Webtrees\Tree;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Support\Collection;
Expand All @@ -38,17 +37,13 @@ class ChartDivorce

private CenturyService $century_service;

private ColorService $color_service;

/**
* @param CenturyService $century_service
* @param ColorService $color_service
* @param Tree $tree
*/
public function __construct(CenturyService $century_service, ColorService $color_service, Tree $tree)
public function __construct(CenturyService $century_service, Tree $tree)
{
$this->century_service = $century_service;
$this->color_service = $color_service;
$this->tree = $tree;
}

Expand Down Expand Up @@ -87,8 +82,8 @@ private function queryRecords(): Collection
*/
public function chartDivorce(string $color_from = null, string $color_to = null): string
{
$color_from = $color_from ?? 'ffffff';
$color_to = $color_to ?? '84beff';
$color_from = $color_from ?? ['--chart-values-low', '#ffffff'];
$color_to = $color_to ?? ['--chart-values-high', '#84beff'];

$data = [
[
Expand All @@ -104,12 +99,11 @@ public function chartDivorce(string $color_from = null, string $color_to = null)
];
}

$colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1);

return view('statistics/other/charts/pie', [
'title' => I18N::translate('Divorces by century'),
'data' => $data,
'colors' => $colors,
'colors' => [$color_from, $color_to],
'steps' => count($data) - 1,
'language' => I18N::languageTag(),
]);
}
Expand Down