Remove old tag cloud code.

This commit is contained in:
James Cole 2020-07-19 18:02:48 +02:00
parent bd779c8156
commit 3619427f60
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D

View File

@ -74,25 +74,6 @@ class TagController extends Controller
); );
} }
/**
* @param DateRequest $request
*
* @return JsonResponse
*/
public function cloud(DateRequest $request): JsonResponse
{
// parameters for boxes:
$dates = $request->getAll();
$start = $dates['start'];
$end = $dates['end'];
// get all tags:
$tags = $this->repository->get();
$cloud = $this->getTagCloud($tags, $start, $end);
return response()->json($cloud);
}
/** /**
* Delete the resource. * Delete the resource.
* *
@ -284,56 +265,4 @@ class TagController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
} }
/**
* @param array $cloud
* @param float $min
* @param float $max
*
* @return array
*/
private function analyseTagCloud(array $cloud, float $min, float $max): array
{
foreach (array_keys($cloud['tags']) as $index) {
$cloud['tags'][$index]['relative'] = round($cloud['tags'][$index]['size'] / $max, 4);
}
$cloud['min'] = $min;
$cloud['max'] = $max;
return $cloud;
}
/**
* @param Collection $tags
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function getTagCloud(Collection $tags, Carbon $start, Carbon $end): array
{
$min = null;
$max = 0;
$cloud = [
'tags' => [],
];
/** @var Tag $tag */
foreach ($tags as $tag) {
$earned = (float) $this->repository->earnedInPeriod($tag, $start, $end);
$spent = (float) $this->repository->spentInPeriod($tag, $start, $end);
$size = ($spent * -1) + $earned;
$min = $min ?? $size;
if ($size > 0) {
$max = $size > $max ? $size : $max;
$cloud['tags'][] = [
'tag' => $tag->tag,
'id' => $tag->id,
'size' => $size,
];
}
}
$cloud = $this->analyseTagCloud($cloud, $min, $max);
return $cloud;
}
} }