mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 18:02:34 +00:00
Fix tag cloud
This commit is contained in:
@@ -43,9 +43,6 @@ use View;
|
|||||||
class TagController extends Controller
|
class TagController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
public $tagOptions = [];
|
|
||||||
|
|
||||||
/** @var TagRepositoryInterface */
|
/** @var TagRepositoryInterface */
|
||||||
protected $repository;
|
protected $repository;
|
||||||
|
|
||||||
@@ -60,17 +57,8 @@ class TagController extends Controller
|
|||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
$this->repository = app(TagRepositoryInterface::class);
|
$this->repository = app(TagRepositoryInterface::class);
|
||||||
$this->tagOptions = [
|
|
||||||
'nothing' => trans('firefly.regular_tag'),
|
|
||||||
'balancingAct' => trans('firefly.balancing_act'),
|
|
||||||
'advancePayment' => trans('firefly.advance_payment'),
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
View::share('title', strval(trans('firefly.tags')));
|
View::share('title', strval(trans('firefly.tags')));
|
||||||
View::share('mainTitleIcon', 'fa-tags');
|
View::share('mainTitleIcon', 'fa-tags');
|
||||||
View::share('tagOptions', $this->tagOptions);
|
|
||||||
|
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -275,17 +275,23 @@ class TagRepository implements TagRepositoryInterface
|
|||||||
$max = 0;
|
$max = 0;
|
||||||
$query = $this->user->tags();
|
$query = $this->user->tags();
|
||||||
$return = [];
|
$return = [];
|
||||||
|
Log::debug('Going to build tag-cloud');
|
||||||
if (!is_null($year)) {
|
if (!is_null($year)) {
|
||||||
|
Log::debug(sprintf('Year is not null: %d', $year));
|
||||||
$start = $year . '-01-01';
|
$start = $year . '-01-01';
|
||||||
$end = $year . '-12-31';
|
$end = $year . '-12-31';
|
||||||
$query->where('date', '>=', $start)->where('date', '<=', $end);
|
$query->where('date', '>=', $start)->where('date', '<=', $end);
|
||||||
}
|
}
|
||||||
if (is_null($year)) {
|
if (is_null($year)) {
|
||||||
$query->whereNull('date');
|
$query->whereNull('date');
|
||||||
|
Log::debug('Year is NULL');
|
||||||
}
|
}
|
||||||
$tags = $query->orderBy('id', 'desc')->get();
|
$tags = $query->orderBy('id', 'desc')->get();
|
||||||
$temporary = [];
|
$temporary = [];
|
||||||
|
Log::debug(sprintf('Found %d tags', $tags->count()));
|
||||||
|
/** @var Tag $tag */
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
|
|
||||||
$amount = floatval($this->sumOfTag($tag, null, null));
|
$amount = floatval($this->sumOfTag($tag, null, null));
|
||||||
$min = $amount < $min || is_null($min) ? $amount : $min;
|
$min = $amount < $min || is_null($min) ? $amount : $min;
|
||||||
$max = $amount > $max ? $amount : $max;
|
$max = $amount > $max ? $amount : $max;
|
||||||
@@ -293,6 +299,8 @@ class TagRepository implements TagRepositoryInterface
|
|||||||
'amount' => $amount,
|
'amount' => $amount,
|
||||||
'tag' => $tag,
|
'tag' => $tag,
|
||||||
];
|
];
|
||||||
|
Log::debug(sprintf('Now working on tag %s with total amount %s', $tag->tag, $amount));
|
||||||
|
Log::debug(sprintf('Minimum is now %f, maximum is %f', $min, $max));
|
||||||
}
|
}
|
||||||
/** @var array $entry */
|
/** @var array $entry */
|
||||||
foreach ($temporary as $entry) {
|
foreach ($temporary as $entry) {
|
||||||
@@ -304,6 +312,8 @@ class TagRepository implements TagRepositoryInterface
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::debug('DONE with tagcloud');
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,7 +347,16 @@ class TagRepository implements TagRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
private function cloudScale(array $range, float $amount, float $min, float $max): int
|
private function cloudScale(array $range, float $amount, float $min, float $max): int
|
||||||
{
|
{
|
||||||
|
Log::debug(sprintf('Now in cloudScale with %s as amount and %f min, %f max', $amount, $min, $max));
|
||||||
$amountDiff = $max - $min;
|
$amountDiff = $max - $min;
|
||||||
|
Log::debug(sprintf('AmountDiff is %f', $amountDiff));
|
||||||
|
|
||||||
|
// no difference? Every tag same range:
|
||||||
|
if($amountDiff === 0.0) {
|
||||||
|
Log::debug(sprintf('AmountDiff is zero, return %d', $range[0]));
|
||||||
|
return $range[0];
|
||||||
|
}
|
||||||
|
|
||||||
$diff = $range[1] - $range[0];
|
$diff = $range[1] - $range[0];
|
||||||
$step = 1;
|
$step = 1;
|
||||||
if ($diff != 0) {
|
if ($diff != 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user