Skip to content

Commit d6a73a3

Browse files
committed
add performance chart
1 parent b769a6a commit d6a73a3

File tree

6 files changed

+97
-52
lines changed

6 files changed

+97
-52
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
})();

src/app/controllers/ProgressController.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/app/controllers/WarningsController.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
var vm = this;
1010

1111
// TODO: move data to the service
12-
vm.warningsChartData = warningFunction; //[ {x: 10, y: 5264}, { x: 20, y: 3872} ];
12+
vm.warningsChartData = warningFunction;
1313

1414
function warningFunction() {
1515
var sin = [];
@@ -23,7 +23,6 @@
2323
chart: {
2424
type: 'lineChart',
2525
height: 210,
26-
donut: true,
2726
margin: { left: -20, right: -20 },
2827
x: function (d) { return d.x },
2928
y: function (d) { return d.y },

src/app/stylesheets/_custom.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ body {
102102

103103
.custom-tooltip {
104104
font-size: 24px;
105+
color: $text-color;
106+
text-align: center;
105107
}
106108

107109

@@ -146,7 +148,6 @@ md-radio-button.md-accent.md-checked .md-label span {
146148

147149
.nvtooltip {
148150
background-color: transparent;
149-
color: $text-color;
150151
border: none;
151152
font-weight: $font-weight-bold;
152153
}
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
<div ng-controller="ProgressController as vm">
1+
<div ng-controller="PerformanceController as vm">
22
<md-content ng-show="$showOptions" class="options">
3-
<md-radio-group ng-model="vm.progressPeriod" ng-change="vm.changePeriod()">
3+
<md-radio-group ng-model="vm.performancePeriod" ng-change="vm.changePeriod()">
44
<md-radio-button value="week">Last week</md-radio-button>
55
<md-radio-button value="month">Last month</md-radio-button>
66
</md-radio-group>
77
</md-content>
88

99
<md-content class="md-padding">
10-
<div layout-margin ng-repeat="data in vm.progressData">
11-
<div layout="row">
12-
<span>{{data.title}}</span>
13-
<span flex></span>
14-
<span>{{data.value}}%</span>
15-
</div>
16-
<md-progress-linear md-theme={{data.theme}} md-mode="determinate" value={{data.value}}></md-progress-linear>
17-
</div>
10+
<nvd3 options="vm.chartOptions" data="vm.performanceChartData"></nvd3>
1811
</md-content>
1912
</div>

src/components/data/ProgressService.js renamed to src/components/data/PerformanceService.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
'use strict';
33

44
angular.module('app')
5-
.service('progressService', [
6-
progressService
5+
.service('performanceService', [
6+
performanceService
77
]);
88

9-
function progressService(){
9+
function performanceService(){
1010

1111
var service = {
12-
getProgressData: getProgressData
12+
getPerformanceData: getPerformanceData
1313
};
1414

1515
return service;
1616

17-
function getProgressData(progressPeriod) {
18-
if (progressPeriod === 'week') {
17+
function getPerformanceData(performancePeriod) {
18+
if (performancePeriod === 'week') {
1919
return [
2020
{
2121
title: 'Database',

0 commit comments

Comments
 (0)