Various code cleanup and fixed alignments.

This commit is contained in:
James Cole
2024-01-01 14:43:56 +01:00
parent 1368aafe5f
commit f963ac63f1
443 changed files with 3668 additions and 3672 deletions

View File

@@ -44,16 +44,16 @@ class ChartJsGenerator implements GeneratorInterface
'labels' => [],
];
$amounts = array_column($data, 'amount');
$next = next($amounts);
$sortFlag = SORT_ASC;
$amounts = array_column($data, 'amount');
$next = next($amounts);
$sortFlag = SORT_ASC;
if (!is_bool($next) && 1 === bccomp((string)$next, '0')) {
$sortFlag = SORT_DESC;
}
array_multisort($amounts, $sortFlag, $data);
unset($next, $sortFlag, $amounts);
$index = 0;
$index = 0;
foreach ($data as $key => $valueArray) {
// make larger than 0
$chartData['datasets'][0]['data'][] = app('steam')->positive((string)$valueArray['amount']);
@@ -99,11 +99,11 @@ class ChartJsGenerator implements GeneratorInterface
public function multiSet(array $data): array
{
reset($data);
$first = current($data);
$first = current($data);
if (!is_array($first)) {
return [];
}
$labels = is_array($first['entries']) ? array_keys($first['entries']) : [];
$labels = is_array($first['entries']) ? array_keys($first['entries']) : [];
$chartData = [
'count' => count($data),
@@ -113,7 +113,7 @@ class ChartJsGenerator implements GeneratorInterface
unset($first, $labels);
foreach ($data as $set) {
$currentSet = [
$currentSet = [
'label' => $set['label'] ?? '(no label)',
'type' => $set['type'] ?? 'line',
'data' => array_values($set['entries']),
@@ -153,20 +153,20 @@ class ChartJsGenerator implements GeneratorInterface
// sort by value, keep keys.
// different sort when values are positive and when they're negative.
asort($data);
$next = next($data);
$next = next($data);
if (!is_bool($next) && 1 === bccomp((string)$next, '0')) {
// next is positive, sort other way around.
arsort($data);
}
unset($next);
$index = 0;
$index = 0;
foreach ($data as $key => $value) {
// make larger than 0
$chartData['datasets'][0]['data'][] = app('steam')->positive((string)$value);
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
$chartData['labels'][] = $key;
$chartData['labels'][] = $key;
++$index;
}