From beb358f8ee16f75d821d3397de10dd2f393515b0 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 22 Apr 2017 07:05:44 +0200 Subject: [PATCH] Small code optimisation. --- app/Generator/Chart/Basic/ChartJsGenerator.php | 4 ++++ app/Http/Controllers/Chart/AccountController.php | 10 ++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/Generator/Chart/Basic/ChartJsGenerator.php b/app/Generator/Chart/Basic/ChartJsGenerator.php index 642c554337..b63f9e9c01 100644 --- a/app/Generator/Chart/Basic/ChartJsGenerator.php +++ b/app/Generator/Chart/Basic/ChartJsGenerator.php @@ -108,6 +108,10 @@ class ChartJsGenerator implements GeneratorInterface ], 'labels' => [], ]; + + // sort by value, keep keys. + asort($data); + $index = 0; foreach ($data as $key => $value) { diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index ac8b516685..38bd1f3345 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -336,19 +336,13 @@ class AccountController extends Controller /** * @param Account $account - * @param string $date + * @param Carbon $start * * @return \Illuminate\Http\JsonResponse * @throws FireflyException */ - public function period(Account $account, string $date) + public function period(Account $account, Carbon $start) { - try { - $start = new Carbon($date); - } catch (Exception $e) { - Log::error($e->getMessage()); - throw new FireflyException('"' . e($date) . '" does not seem to be a valid date. Should be in the format YYYY-MM-DD'); - } $range = Preferences::get('viewRange', '1M')->data; $end = Navigation::endOfPeriod($start, $range); $cache = new CacheProperties();