diff --git a/CHANGELOG.md b/CHANGELOG.md index 664cc082a..261573304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 14.14.0 - 2023-09-22 + +### Changed +- Revert `percent` value from `Charts` + ## 14.13.0 - 2023-09-21 ### Changed diff --git a/src/Metrics/Chartable.php b/src/Metrics/Chartable.php index a2c25f003..99e9103fd 100644 --- a/src/Metrics/Chartable.php +++ b/src/Metrics/Chartable.php @@ -53,9 +53,7 @@ private function groupByDays(Builder $builder, string $value, $startDate = null, $days = $startDate->diffInDays($stopDate) + 1; - $sumValues = $query->sum('value'); - - return TimeCollection::times($days, function () use ($startDate, $query, $sumValues) { + return TimeCollection::times($days, function () use ($startDate, $query) { $found = $query->firstWhere( 'label', $startDate->startOfDay()->toDateString() @@ -64,7 +62,6 @@ private function groupByDays(Builder $builder, string $value, $startDate = null, $result = [ 'value' => ($found ? $found->value : 0), 'label' => $startDate->toDateString(), - 'percent' => ($found ? round($found->value / $sumValues * 100, 2) : 0), ]; $startDate->addDay(); diff --git a/src/Metrics/TimeCollection.php b/src/Metrics/TimeCollection.php index 328ee2025..86fbb3886 100644 --- a/src/Metrics/TimeCollection.php +++ b/src/Metrics/TimeCollection.php @@ -40,7 +40,6 @@ public function toChart(string $name, \Closure $closure = null): array 'name' => $name, 'labels' => $this->pluck('label')->map($closure)->toArray(), 'values' => $this->pluck('value')->toArray(), - 'percent' => $this->pluck('percent')->toArray(), ]; } diff --git a/src/Platform/Dashboard.php b/src/Platform/Dashboard.php index 3a571d94b..716cd33c2 100644 --- a/src/Platform/Dashboard.php +++ b/src/Platform/Dashboard.php @@ -21,7 +21,7 @@ class Dashboard /** * ORCHID Version. */ - public const VERSION = '14.13.0'; + public const VERSION = '14.14.0'; /** * @deprecated diff --git a/tests/Unit/MetricsTest.php b/tests/Unit/MetricsTest.php index e56e6e17e..d3aab35b6 100644 --- a/tests/Unit/MetricsTest.php +++ b/tests/Unit/MetricsTest.php @@ -78,7 +78,6 @@ public function testPeriod(): void 'name' => 'Users', 'labels' => $period->pluck('label')->toArray(), 'values' => $period->pluck('value')->toArray(), - 'percent' => $period->pluck('percent')->toArray(), ], $period->toChart('Users')); } @@ -109,7 +108,6 @@ public function testMaxValuesPeriod(): void 'name' => 'Users', 'labels' => $period->pluck('label')->toArray(), 'values' => $period->pluck('value')->toArray(), - 'percent' => $period->pluck('percent')->toArray(), ], $period->toChart('Users')); } @@ -140,7 +138,6 @@ public function testMinValuesPeriod(): void 'name' => 'Users', 'labels' => $period->pluck('label')->toArray(), 'values' => $period->pluck('value')->toArray(), - 'percent' => $period->pluck('percent')->toArray(), ], $period->toChart('Users')); } @@ -170,7 +167,6 @@ public function testSumPeriod(): void 'name' => 'Users', 'labels' => $period->pluck('label')->toArray(), 'values' => $period->pluck('value')->toArray(), - 'percent' => $period->pluck('percent')->toArray(), ], $period->toChart('Users')); } @@ -200,7 +196,6 @@ public function testAvgPeriod(): void 'name' => 'Users', 'labels' => $period->pluck('label')->toArray(), 'values' => $period->pluck('value')->toArray(), - 'percent' => $period->pluck('percent')->toArray(), ], $period->toChart('Users')); } @@ -265,50 +260,6 @@ public function testPeriodWithoutZero(): void 'name' => 'Users', 'labels' => $period->pluck('label')->toArray(), 'values' => $period->pluck('value')->toArray(), - 'percent' => $period->pluck('percent')->toArray(), ], $period->toChart('Users')); } - - public function testPercentValues(): void - { - $current = Carbon::now(); - $start = (clone $current)->subDays(2); - $end = (clone $current)->subDay(); - - User::factory()->count(1)->create([ - 'created_at' => $start, - ]); - - User::factory()->count(2)->create([ - 'created_at' => $end, - ]); - - $period = User::countByDays($start); - - $expected = [ - [ - 'value' => 1, - 'label' => $start->toDateString(), - 'percent' => 33.33, - ], - [ - 'value' => 2, - 'label' => $end->toDateString(), - 'percent' => 66.67, - ], - [ - 'value' => 0, - 'label' => $end->copy()->addDay()->toDateString(), - 'percent' => 0, - ], - ]; - - $actual = $period->all(); - - $this->assertEquals($expected, $actual); - - $user = $period->toChart('Users'); - - $this->assertSame([33.33, 66.67, 0], $user['percent']); - } }