Added cumulative graph

This commit is contained in:
Josef Citrine 2016-05-03 20:30:57 +01:00
parent 97b4bb1b8b
commit 7a73e20929
4 changed files with 31 additions and 6 deletions

View file

@ -61,7 +61,7 @@ class StatsController extends ApiControllerBase
array_push($output, $set);
}
return Response::json(['playStats' => $output], 200);
return Response::json(['playStats' => $output, 'type' => 'Hourly'], 200);
}
public function getTrackStatsDaily($id)
@ -96,7 +96,7 @@ class StatsController extends ApiControllerBase
array_push($output, $set);
}
return Response::json(['playStats' => $output], 200);
return Response::json(['playStats' => $output, 'type' => 'Daily'], 200);
}
public function getTrackStats($id) {

View file

@ -5,4 +5,5 @@
<canvas id="line" class="chart chart-line" chart-data="playsData"
chart-labels="playsLabels" chart-legend="true" chart-series="series">
</canvas>
<button class="btn btn-primary" ng-class="{ selected: totalSelected }" ng-click="totalClick()">Cumulative</button> <button class="btn btn-primary" ng-class="{ selected: !totalSelected }" ng-click="dailyClick()">{{ dailyText }}</button>
</div>

View file

@ -15,24 +15,44 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
module.exports = angular.module('ponyfm').controller "track-stats", [
module.exports = angular.module('ponyfm').controller 'track-stats', [
'$scope', '$state', 'track-stats'
($scope, $state, statsService) ->
$scope.trackId = parseInt($state.params.id)
labelArray = []
dataArray = []
cumArray = []
statsLoaded = (stats) ->
console.log(stats)
labelArray = []
dataArray = []
for key, value of stats.playStats
labelArray.push value.hour || value.days
dataArray.push value.plays
i = 0
while i < dataArray.length
if i == 0
cumArray[i] = dataArray[0]
else
cumArray[i] = cumArray[i - 1] + dataArray[i]
i++
$scope.playsLabels = labelArray
$scope.playsData = dataArray
$scope.series = ['Plays']
$scope.totalSelected = false
$scope.dailyText = stats.type
$scope.totalClick = () ->
$scope.playsData = cumArray
$scope.totalSelected = true
$scope.dailyClick = () ->
$scope.playsData = dataArray
$scope.totalSelected = false
statsService.loadStats($scope.trackId).done statsLoaded
]

View file

@ -212,6 +212,10 @@ html body {
color: #eee;
}
.btn.selected {
background: #7A4F7D;
}
.ui-datepicker {
.border-radius(0px);