From 18d33de0c54e64693274bc17afb1a08b9fec5ad8 Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Sat, 15 Sep 2018 14:00:20 -0400 Subject: [PATCH] Fix date and label calculation --- app/public/panel/controllers/DashCtrl.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/public/panel/controllers/DashCtrl.js b/app/public/panel/controllers/DashCtrl.js index 5ebd96f..2f18ca3 100644 --- a/app/public/panel/controllers/DashCtrl.js +++ b/app/public/panel/controllers/DashCtrl.js @@ -3,14 +3,14 @@ var angular = require('angular'); angular.module('DashCtrl', ['chart.js']).controller('DashController', ['$scope', $scope => { const colorScheme = ['#2a9fd6']; - let weekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; - for(let i = 0; i < 6 - (new Date()).getDay(); i++) { - const back = weekDays.pop(); - weekDays.unshift(back); - } + // Calculate and format descending dates back one week + const currentDate = new Date(); + const oneDay = 1000 * 60 * 60 * 24; + let dates = Array.from({length: 7}, (date, i) => new Date(currentDate - oneDay * (6 - i))); + let labels = dates.map(date => date.toISOString().substr(5, 5)); $scope.uploadColors = colorScheme; - $scope.uploadLabels = weekDays; + $scope.uploadLabels = labels; $scope.uploadSeries = ['Uploads']; $scope.uploadData = [[10, 20, 30, 20, 15, 20, 45]]; $scope.uploadOptions = { @@ -21,7 +21,7 @@ angular.module('DashCtrl', ['chart.js']).controller('DashController', ['$scope', }; $scope.viewColors = colorScheme; - $scope.viewLabels = weekDays; + $scope.viewLabels = labels; $scope.viewSeries = ['Views']; $scope.viewData = [[5, 11, 4, 3, 7, 9, 21]]; $scope.viewOptions = {