From 0b15ea0957246c406216b095c8e2527f08f35afb Mon Sep 17 00:00:00 2001 From: Jakob Warkotsch Date: Mon, 15 Feb 2016 14:19:17 +0100 Subject: [PATCH] Fix color order in pie chart. --- app/Phragile/PieChart.php | 2 +- tests/unit/PieChartTest.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Phragile/PieChart.php b/app/Phragile/PieChart.php index dd6a02b..4d36ab6 100644 --- a/app/Phragile/PieChart.php +++ b/app/Phragile/PieChart.php @@ -36,7 +36,7 @@ private function sortByCssClass(array $data) { uasort($data, function($a, $b) { - return $a < $b ? 1 : -1; + return $a['cssClass'] > $b['cssClass'] ? 1 : -1; }); return $data; diff --git a/tests/unit/PieChartTest.php b/tests/unit/PieChartTest.php index 68da06b..2f6a15c 100644 --- a/tests/unit/PieChartTest.php +++ b/tests/unit/PieChartTest.php @@ -72,4 +72,23 @@ public function testHasCssClassAsKeys() $this->assertArrayHasKey('closed deployed', $colorMap); $this->assertArrayHasKey('closed wontfix', $colorMap); } + + public function testOrdersByCssClass() + { + $chart = new PieChart( + [ + 'Done' => ['points' => 10], + 'Doing' => ['points' => 11], + 'Blocked By Others' => ['points' => 12], + 'Deployed' => ['points' => 13] + ], + new StatusCssClassService(true, ['Done', 'Deployed']) + ); + + $colorMap = array_values($chart->getData()); + $this->assertSame($colorMap[0]['cssClass'], 'closed deployed'); + $this->assertSame($colorMap[1]['cssClass'], 'closed done'); + $this->assertSame($colorMap[2]['cssClass'], 'open blocked-by-others'); + $this->assertSame($colorMap[3]['cssClass'], 'open doing'); + } }