|
| 1 | +(function () { |
| 2 | + angular |
| 3 | + .module('app') |
| 4 | + .controller('PerformanceController', [ |
| 5 | + 'performanceService', '$q', |
| 6 | + PerformanceController |
| 7 | + ]); |
| 8 | + |
| 9 | + function PerformanceController(performanceService, $q) { |
| 10 | + var vm = this; |
| 11 | + |
| 12 | + |
| 13 | + vm.performanceChartData = performanceFunction; |
| 14 | + |
| 15 | + function performanceFunction() { |
| 16 | + var sin = []; |
| 17 | + for (var i = 0; i < 100; i++) { |
| 18 | + sin.push({x: i, y: Math.abs(Math.cos(i/10) *0.25*i + 0.9 - 0.4*i)}); |
| 19 | + } |
| 20 | + return [ { values: sin, color: 'rgb(0, 150, 136)', area: true } ]; |
| 21 | + } |
| 22 | + |
| 23 | + vm.chartOptions = { |
| 24 | + chart: { |
| 25 | + type: 'stackedAreaChart', |
| 26 | + height: 350, |
| 27 | + margin: { left: -15, right: -15 }, |
| 28 | + x: function (d) { return d[0] }, |
| 29 | + y: function (d) { return d[1] }, |
| 30 | + showLabels: false, |
| 31 | + showLegend: false, |
| 32 | + title: 'Over 9K', |
| 33 | + showYAxis: false, |
| 34 | + showXAxis: false, |
| 35 | + tooltip: { contentGenerator: function (d) { return '<div class="custom-tooltip">' + d.point.y + '%</div>' + '<div class="custom-tooltip">' + d.series[0].key + '</div>' } }, |
| 36 | + showControls: false |
| 37 | + } |
| 38 | + }; |
| 39 | + |
| 40 | + vm.performanceData = {}; |
| 41 | + vm.performanceChartData = [ |
| 42 | + |
| 43 | + |
| 44 | + // TODO: move data to service, implement period switching |
| 45 | + { |
| 46 | + "key" : 'Middleware' , |
| 47 | + "values" : [ [1,13], [2,14], [3,24], [4,18], [5,16], [6,14], [7,11], [8, 13], [9,15], [10,11], [11,18], [12,16], [13,28], [14,11], [15,12], [16,13], [17,12], [18,20], [19, 22], [20, 18], [21,11], [22,10], [23,18], [24, 20], [25,9], [26,14], [27,10], [28,11], [29,17] ] |
| 48 | + }, |
| 49 | + |
| 50 | + { |
| 51 | + "key" : 'Ruby' , |
| 52 | + "values" : [ [1,29], [2,36], [3,42], [4,25], [5,22], [6,34], [7,41], [8, 19], [9,45], [10,31], [11,28], [12,36], [13,54], [14,41], [15,36], [16,39], [17,21], [18,20], [19, 22], [20, 44], [21,32], [22,20], [23,28], [24, 24], [25,29], [26,19], [27,20], [28,31], [29,49] ] |
| 53 | + }, |
| 54 | + |
| 55 | + { |
| 56 | + "key" : 'Web External' , |
| 57 | + "values" : [ [1,54], [2,74], [3,64], [4,68], [5,56], [6,44], [7,61], [8, 63], [9,45], [10,51], [11,68], [12,46], [13,64], [14,51], [15,42], [16,63], [17,72], [18,60], [19, 52], [20, 58], [21,41], [22,40], [23,58], [24, 30], [25,49], [26,54], [27,60], [28,41], [29,66] ] |
| 58 | + } , |
| 59 | + { |
| 60 | + "key" : 'Database' , |
| 61 | + "values" : [ [1,64], [2,84], [3,64], [4,68], [5,86], [6,74], [7,81], [8, 83], [9,65], [10,61], [11,88], [12,76], [13,84], [14,71], [15,82], [16,73], [17,92], [18,80], [19, 62], [20, 68], [21,71], [22,50], [23,78], [24, 60], [25,59], [26,74], [27,80], [28,51], [29,97] ] |
| 62 | + } |
| 63 | + |
| 64 | + |
| 65 | + ]; |
| 66 | + vm.performancePeriod = 'week'; |
| 67 | + vm.changePeriod = changePeriod; |
| 68 | + |
| 69 | + activate(); |
| 70 | + |
| 71 | + function activate() { |
| 72 | + var queries = [loadData()]; |
| 73 | + $q.all(queries); |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | + function loadData() { |
| 78 | + vm.performanceData = performanceService.getPerformanceData(vm.performancePeriod); |
| 79 | + } |
| 80 | + |
| 81 | + function changePeriod() { |
| 82 | + loadData(); |
| 83 | + } |
| 84 | + } |
| 85 | +})(); |
0 commit comments