simple_metrics 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ (function(){
2
+
3
+ window.app = {};
4
+ app.collections = {};
5
+ app.models = {};
6
+ app.views = {};
7
+ app.mixins = {};
8
+
9
+ $(function(){
10
+ app.collections.metrics = new app.collections.Metric();
11
+ app.collections.metrics.fetch();
12
+
13
+ app.views.app = new app.views.App({ collection: app.collections.metrics });
14
+
15
+ app.router = new app.Router();
16
+
17
+ Backbone.history.start({pushState: false});
18
+ });
19
+
20
+ })();
@@ -0,0 +1,16 @@
1
+ (function (collections, model) {
2
+
3
+ collections.Graph = Backbone.Collection.extend({
4
+ model: model,
5
+
6
+ initialize: function(options) {
7
+ this.targets = options.targets;
8
+ this.time = options.time;
9
+ },
10
+
11
+ url: function() {
12
+ return "/api/graph?targets[]="+this.targets+"&time="+this.time;
13
+ }
14
+ });
15
+
16
+ })( app.collections, app.models.Graph);
@@ -0,0 +1,9 @@
1
+ (function (collections, model) {
2
+
3
+ collections.Metric = Backbone.Collection.extend({
4
+ model: model,
5
+ url: '/api/metrics'
6
+ });
7
+
8
+
9
+ })( app.collections, app.models.Metric);
@@ -0,0 +1,6 @@
1
+ (function (models) {
2
+
3
+ models.Graph = Backbone.Model.extend({
4
+ });
5
+
6
+ })( app.models );
@@ -0,0 +1,7 @@
1
+ (function ( models ) {
2
+
3
+ models.Metric = Backbone.Model.extend({
4
+ urlRoot: '/api/metrics'
5
+ });
6
+
7
+ })( app.models );
@@ -0,0 +1,42 @@
1
+ (function (app) {
2
+
3
+ app.Router = Backbone.Router.extend({
4
+ routes: {
5
+ "": "home",
6
+ "metrics": "metrics",
7
+ "metrics/:name": "metric_details",
8
+ "dashboard": "dashboard",
9
+ "about": "about"
10
+ },
11
+
12
+ home: function() {
13
+ console.log("ROUTER: home");
14
+ new app.views.App({ el: "#main", collection: app.collections.metrics }).render();
15
+ },
16
+ metrics: function() {
17
+ console.log("ROUTER: metrics");
18
+ new app.views.App({ el: "#main", collection: app.collections.metrics }).render();
19
+ },
20
+ metric_details: function(name) {
21
+ console.log("ROUTER: metric details:", name);
22
+
23
+ metric = new app.models.Metric({ name: name});
24
+ metric.fetch({
25
+ success: function(model, resp) {
26
+ new app.views.Metric({ el: "#main", model: model }).render();
27
+ },
28
+ error: function() {
29
+ alert("Document not found:"+id);
30
+ }
31
+ });
32
+ },
33
+ dashboard: function() {
34
+ console.log("ROUTER: dashboard");
35
+ new app.views.Dashboard({ el: "#main" }).render();
36
+ },
37
+ about: function() {
38
+ console.log("ROUTER: about");
39
+ }
40
+ });
41
+
42
+ })(app);
@@ -0,0 +1,18 @@
1
+ (function (views){
2
+
3
+ views.App = Backbone.View.extend({
4
+
5
+ template: Handlebars.compile($("#metric-list").html()),
6
+
7
+ initialize: function(options) {
8
+ _.bindAll(this, "render");
9
+ this.collection.bind('reset', this.render);
10
+ },
11
+
12
+ render: function() {
13
+ $(this.el).html(this.template({ metrics: this.collection.toJSON() }));
14
+ return this;
15
+ }
16
+ });
17
+
18
+ })(app.views);
@@ -0,0 +1,10 @@
1
+ ( function ( views ){
2
+
3
+ views.Dashboard = Backbone.View.extend({
4
+ render: function() {
5
+ $(this.el).html("This is a dashboard view");
6
+ return this;
7
+ }
8
+ });
9
+
10
+ })( app.views );
@@ -0,0 +1,101 @@
1
+ ( function (views){
2
+
3
+ views.Graph = Backbone.View.extend({
4
+ template: Handlebars.compile($("#graph").html()),
5
+
6
+ initialize: function(options) {
7
+ _.bindAll(this, "render");
8
+ this.time = this.options.time;
9
+ this.series = this.options.series;
10
+ },
11
+
12
+ render: function() {
13
+ $(this.el).html(this.template({ time: this.time }));
14
+
15
+ var pastel = [
16
+ '#239928',
17
+ '#6CCC70',
18
+ '#DEFFA1',
19
+ '#DEFFA1',
20
+ '#DEFFA1',
21
+ '#362F2B',
22
+ '#BFD657',
23
+ '#FF6131',
24
+ '#FFFF9D',
25
+ '#BEEB9F',
26
+ '#79BD8F',
27
+ '#00A388'
28
+ ].reverse();
29
+
30
+ var customPalette = new Rickshaw.Color.Palette( { scheme: pastel } );
31
+ var spectrum14Palette = new Rickshaw.Color.Palette( { scheme: "spectrum14" } );
32
+
33
+ function addColorToSeries(data, palette) {
34
+ var result = [];
35
+ $.each(data, function(k, v){
36
+ v.color = palette.color();
37
+ result.push(v);
38
+ });
39
+ return result;
40
+ }
41
+
42
+ graph = new Rickshaw.Graph({
43
+ element: this.$('.graph').get(0),
44
+ renderer: 'line',
45
+ series: addColorToSeries(this.series, spectrum14Palette)
46
+ });
47
+
48
+ function timeUnit(time) {
49
+ var timeFixture = new Rickshaw.Fixtures.Time();
50
+ var minuteCustom = {
51
+ name: 'minute',
52
+ seconds: 60,
53
+ formatter: function(d) { return d.getUTCHours()+':'+d.getUTCMinutes()+'h';}
54
+ };
55
+ var hourCustom = {
56
+ name: 'hour',
57
+ seconds: 60*15,
58
+ formatter: function(d) { return d.getUTCHours()+':'+d.getUTCMinutes()+'h';}
59
+ };
60
+ var dayCustom = {
61
+ name: 'day',
62
+ seconds: 60*60*2,
63
+ formatter: function(d) { return d.getUTCHours()+'h';}
64
+ };
65
+ var weekCustom = {
66
+ name: 'week',
67
+ seconds: 60*60*2*7*2,
68
+ formatter: function(d) { return d.getUTCDate()+'. '+d.getUTCMonth()+'.';}
69
+ };
70
+
71
+ switch(time){
72
+ case 'minute': return minuteCustom;
73
+ case 'hour': return hourCustom;
74
+ case 'day': return dayCustom;
75
+ case 'week': return weekCustom;
76
+ }
77
+ }
78
+
79
+ var x_axis = new Rickshaw.Graph.Axis.Time({
80
+ graph: graph,
81
+ timeUnit: timeUnit(this.minute)
82
+ });
83
+
84
+ var y_axis = new Rickshaw.Graph.Axis.Y({
85
+ graph: graph,
86
+ orientation: 'left',
87
+ tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
88
+ element: this.$('.y-axis').get(0)
89
+ });
90
+
91
+ graph.render();
92
+
93
+ var hoverDetail = new Rickshaw.Graph.HoverDetail({
94
+ graph: graph
95
+ });
96
+
97
+ return this;
98
+ }
99
+ });
100
+
101
+ })( app.views );
@@ -0,0 +1,82 @@
1
+ (function (views, collections){
2
+
3
+ views.Metric = Backbone.View.extend({
4
+ template: Handlebars.compile($("#metric-details").html()),
5
+
6
+ initialize: function() {
7
+ _.bindAll(this, "render");
8
+ },
9
+
10
+ render: function() {
11
+ $(this.el).html(this.template({ metric: this.model.toJSON() }));
12
+
13
+ // TODO: make code more DRY
14
+ var minuteGraphCollection = new collections.Graph({
15
+ targets: this.model.get('name'),
16
+ time: 'minute'
17
+ });
18
+
19
+ minuteGraphCollection.fetch({
20
+ success: function() {
21
+ var minuteView = new views.Graph({
22
+ series: minuteGraphCollection.toJSON(),
23
+ time: "minute",
24
+ el: this.$("#graph-container-minute")
25
+ });
26
+ minuteView.render();
27
+ }
28
+ });
29
+
30
+ var hourGraphCollection = new collections.Graph({
31
+ targets: this.model.get('name'),
32
+ time: 'hour'
33
+ });
34
+
35
+ hourGraphCollection.fetch({
36
+ success: function() {
37
+ var hourView = new views.Graph({
38
+ series: hourGraphCollection.toJSON(),
39
+ time: "hour",
40
+ el: this.$("#graph-container-hour")
41
+ });
42
+ hourView.render();
43
+ }
44
+ });
45
+
46
+ var dayGraphCollection = new collections.Graph({
47
+ targets: this.model.get('name'),
48
+ time: 'day'
49
+ });
50
+
51
+ dayGraphCollection.fetch({
52
+ success: function() {
53
+ var dayView = new views.Graph({
54
+ series: dayGraphCollection.toJSON(),
55
+ time: "day",
56
+ el: this.$("#graph-container-day")
57
+ });
58
+ dayView.render();
59
+ }
60
+ });
61
+
62
+ var weekGraphCollection = new collections.Graph({
63
+ targets: this.model.get('name'),
64
+ time: 'week'
65
+ });
66
+
67
+ weekGraphCollection.fetch({
68
+ success: function() {
69
+ var weekView = new views.Graph({
70
+ series: weekGraphCollection.toJSON(),
71
+ time: "week",
72
+ el: this.$("#graph-container-week")
73
+ });
74
+ weekView.render();
75
+ }
76
+ });
77
+
78
+ return this;
79
+ }
80
+ });
81
+
82
+ })(app.views, app.collections);
@@ -0,0 +1,10 @@
1
+ (function (views){
2
+
3
+ views.Metrics = Backbone.View.extend({
4
+ render: function() {
5
+ $(this.el).html("This is a metrics list view");
6
+ return this;
7
+ }
8
+ });
9
+
10
+ })(app.views);
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module SimpleMetrics
3
- VERSION = "0.3.4"
3
+ VERSION = "0.3.5"
4
4
  end
@@ -11,15 +11,6 @@
11
11
  <link rel='stylesheet' href='/css/rickshaw.min.css' type='text/css' media="screen, projection">
12
12
  <link rel='stylesheet' href='/css/graph.css' type='text/css' media="screen, projection">
13
13
 
14
- <script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
15
- <script src="js/bootstrap.min.js" type="text/javascript"></script>
16
- <script src="js/underscore-1.3.1.min.js" type="text/javascript"></script>
17
- <script src="js/backbone-0.9.2.min.js" type="text/javascript"></script>
18
- <script src="js/handlebars-1.0.0.beta.6.js" type="text/javascript"></script>
19
- <script src="js/d3.v2.min.js" type="text/javascript"></script>
20
- <script src="js/rickshaw.min.js" type="text/javascript"></script>
21
- <script src="js/application.js" type="text/javascript"></script>
22
-
23
14
  <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
24
15
  <!--[if lt IE 9]>
25
16
  <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
@@ -116,4 +107,28 @@
116
107
  <div class="container">
117
108
  <div id="main"></div>
118
109
  </div> <!-- /container -->
110
+
111
+ <script src="js/lib/jquery-1.7.1.min.js" type="text/javascript"></script>
112
+ <script src="js/lib/bootstrap.min.js" type="text/javascript"></script>
113
+ <script src="js/lib/underscore-1.3.1.min.js" type="text/javascript"></script>
114
+ <script src="js/lib/backbone-0.9.2.min.js" type="text/javascript"></script>
115
+ <script src="js/lib/handlebars-1.0.0.beta.6.js" type="text/javascript"></script>
116
+ <script src="js/lib/d3.v2.min.js" type="text/javascript"></script>
117
+ <script src="js/lib/rickshaw.min.js" type="text/javascript"></script>
118
+
119
+ <script src="js/app.js" type="text/javascript"></script>
120
+ <script src="js/router.js" type="text/javascript"></script>
121
+
122
+ <script src="js/models/metric.js" type="text/javascript"></script>
123
+ <script src="js/models/graph.js" type="text/javascript"></script>
124
+
125
+ <script src="js/collections/metric.js" type="text/javascript"></script>
126
+ <script src="js/collections/graph.js" type="text/javascript"></script>
127
+
128
+ <script src="js/views/app.js" type="text/javascript"></script>
129
+ <script src="js/views/metric.js" type="text/javascript"></script>
130
+ <script src="js/views/metrics.js" type="text/javascript"></script>
131
+ <script src="js/views/graph.js" type="text/javascript"></script>
132
+
133
+ </body>
119
134
  </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-13 00:00:00.000000000 Z
12
+ date: 2012-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70274892543080 !ruby/object:Gem::Requirement
16
+ requirement: &70100115893540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70274892543080
24
+ version_requirements: *70100115893540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70274892542460 !ruby/object:Gem::Requirement
27
+ requirement: &70100115892900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70274892542460
35
+ version_requirements: *70100115892900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rr
38
- requirement: &70274892541780 !ruby/object:Gem::Requirement
38
+ requirement: &70100115892380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70274892541780
46
+ version_requirements: *70100115892380
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: shotgun
49
- requirement: &70274892541240 !ruby/object:Gem::Requirement
49
+ requirement: &70100115891740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70274892541240
57
+ version_requirements: *70100115891740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: eventmachine
60
- requirement: &70274892540640 !ruby/object:Gem::Requirement
60
+ requirement: &70100115907580 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70274892540640
68
+ version_requirements: *70100115907580
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: daemons
71
- requirement: &70274892540080 !ruby/object:Gem::Requirement
71
+ requirement: &70100115907060 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70274892540080
79
+ version_requirements: *70100115907060
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: mongo
82
- requirement: &70274892539440 !ruby/object:Gem::Requirement
82
+ requirement: &70100115906360 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '1.6'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70274892539440
90
+ version_requirements: *70100115906360
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: bson
93
- requirement: &70274892555180 !ruby/object:Gem::Requirement
93
+ requirement: &70100115905600 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '1.6'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *70274892555180
101
+ version_requirements: *70100115905600
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: bson_ext
104
- requirement: &70274892554540 !ruby/object:Gem::Requirement
104
+ requirement: &70100115904980 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '1.6'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *70274892554540
112
+ version_requirements: *70100115904980
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: sinatra
115
- requirement: &70274892553960 !ruby/object:Gem::Requirement
115
+ requirement: &70100115904480 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *70274892553960
123
+ version_requirements: *70100115904480
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: erubis
126
- requirement: &70274892553260 !ruby/object:Gem::Requirement
126
+ requirement: &70100115903720 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *70274892553260
134
+ version_requirements: *70100115903720
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: vegas
137
- requirement: &70274892552580 !ruby/object:Gem::Requirement
137
+ requirement: &70100115903080 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ~>
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: 0.1.2
143
143
  type: :runtime
144
144
  prerelease: false
145
- version_requirements: *70274892552580
145
+ version_requirements: *70100115903080
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: json
148
- requirement: &70274892551940 !ruby/object:Gem::Requirement
148
+ requirement: &70100115902540 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,7 +153,7 @@ dependencies:
153
153
  version: '0'
154
154
  type: :runtime
155
155
  prerelease: false
156
- version_requirements: *70274892551940
156
+ version_requirements: *70100115902540
157
157
  description: SimpleMetrics
158
158
  email:
159
159
  - fdietz@gmail.com
@@ -198,14 +198,24 @@ files:
198
198
  - lib/simple_metrics/public/css/rickshaw.min.css
199
199
  - lib/simple_metrics/public/img/glyphicons-halflings-white.png
200
200
  - lib/simple_metrics/public/img/glyphicons-halflings.png
201
- - lib/simple_metrics/public/js/application.js
202
- - lib/simple_metrics/public/js/backbone-0.9.2.min.js
203
- - lib/simple_metrics/public/js/bootstrap.min.js
204
- - lib/simple_metrics/public/js/d3.v2.min.js
205
- - lib/simple_metrics/public/js/handlebars-1.0.0.beta.6.js
206
- - lib/simple_metrics/public/js/jquery-1.7.1.min.js
207
- - lib/simple_metrics/public/js/rickshaw.min.js
208
- - lib/simple_metrics/public/js/underscore-1.3.1.min.js
201
+ - lib/simple_metrics/public/js/app.js
202
+ - lib/simple_metrics/public/js/collections/graph.js
203
+ - lib/simple_metrics/public/js/collections/metric.js
204
+ - lib/simple_metrics/public/js/lib/backbone-0.9.2.min.js
205
+ - lib/simple_metrics/public/js/lib/bootstrap.min.js
206
+ - lib/simple_metrics/public/js/lib/d3.v2.min.js
207
+ - lib/simple_metrics/public/js/lib/handlebars-1.0.0.beta.6.js
208
+ - lib/simple_metrics/public/js/lib/jquery-1.7.1.min.js
209
+ - lib/simple_metrics/public/js/lib/rickshaw.min.js
210
+ - lib/simple_metrics/public/js/lib/underscore-1.3.1.min.js
211
+ - lib/simple_metrics/public/js/models/graph.js
212
+ - lib/simple_metrics/public/js/models/metric.js
213
+ - lib/simple_metrics/public/js/router.js
214
+ - lib/simple_metrics/public/js/views/app.js
215
+ - lib/simple_metrics/public/js/views/dashboard.js
216
+ - lib/simple_metrics/public/js/views/graph.js
217
+ - lib/simple_metrics/public/js/views/metric.js
218
+ - lib/simple_metrics/public/js/views/metrics.js
209
219
  - lib/simple_metrics/repository.rb
210
220
  - lib/simple_metrics/udp_server.rb
211
221
  - lib/simple_metrics/version.rb
@@ -235,7 +245,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
235
245
  version: '0'
236
246
  segments:
237
247
  - 0
238
- hash: -3260041322875483001
248
+ hash: 1510336325983770453
239
249
  required_rubygems_version: !ruby/object:Gem::Requirement
240
250
  none: false
241
251
  requirements:
@@ -244,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
254
  version: '0'
245
255
  segments:
246
256
  - 0
247
- hash: -3260041322875483001
257
+ hash: 1510336325983770453
248
258
  requirements: []
249
259
  rubyforge_project:
250
260
  rubygems_version: 1.8.15
@@ -1,278 +0,0 @@
1
- $(function(){
2
-
3
- var Metric = Backbone.Model.extend({
4
- urlRoot: '/api/metrics'
5
- });
6
-
7
- var MetricList = Backbone.Collection.extend({
8
- model: Metric,
9
- url: '/api/metrics'
10
- });
11
-
12
- var DashboardView = Backbone.View.extend({
13
- render: function() {
14
- $(this.el).html("This is a dashboard view");
15
- return this;
16
- }
17
- });
18
-
19
- var Graph = Backbone.Model.extend({
20
- });
21
-
22
- var GraphCollection = Backbone.Collection.extend({
23
- model: Graph,
24
-
25
- initialize: function(options) {
26
- this.targets = options.targets;
27
- this.time = options.time;
28
- },
29
-
30
- url: function() {
31
- return "/api/graph?targets[]="+this.targets+"&time="+this.time;
32
- }
33
- });
34
-
35
- var GraphView = Backbone.View.extend({
36
- template: Handlebars.compile($("#graph").html()),
37
-
38
- initialize: function(options) {
39
- _.bindAll(this, "render");
40
- this.time = this.options.time;
41
- this.series = this.options.series;
42
- },
43
-
44
- render: function() {
45
- $(this.el).html(this.template({ time: this.time }));
46
-
47
- var pastel = [
48
- '#239928',
49
- '#6CCC70',
50
- '#DEFFA1',
51
- '#DEFFA1',
52
- '#DEFFA1',
53
- '#362F2B',
54
- '#BFD657',
55
- '#FF6131',
56
- '#FFFF9D',
57
- '#BEEB9F',
58
- '#79BD8F',
59
- '#00A388'
60
- ].reverse();
61
-
62
- var customPalette = new Rickshaw.Color.Palette( { scheme: pastel } );
63
- var spectrum14Palette = new Rickshaw.Color.Palette( { scheme: "spectrum14" } );
64
-
65
- function addColorToSeries(data, palette) {
66
- var result = [];
67
- $.each(data, function(k, v){
68
- v.color = palette.color();
69
- result.push(v);
70
- });
71
- return result;
72
- }
73
-
74
- graph = new Rickshaw.Graph({
75
- element: this.$('.graph').get(0),
76
- renderer: 'line',
77
- series: addColorToSeries(this.series, spectrum14Palette)
78
- });
79
-
80
- function timeUnit(time) {
81
- var timeFixture = new Rickshaw.Fixtures.Time();
82
- var minuteCustom = {
83
- name: 'minute',
84
- seconds: 60,
85
- formatter: function(d) { return d.getUTCHours()+':'+d.getUTCMinutes()+'h';}
86
- };
87
- var hourCustom = {
88
- name: 'hour',
89
- seconds: 60*15,
90
- formatter: function(d) { return d.getUTCHours()+':'+d.getUTCMinutes()+'h';}
91
- };
92
- var dayCustom = {
93
- name: 'day',
94
- seconds: 60*60*2,
95
- formatter: function(d) { return d.getUTCHours()+'h';}
96
- };
97
- var weekCustom = {
98
- name: 'week',
99
- seconds: 60*60*2*7*2,
100
- formatter: function(d) { return d.getUTCDate()+'. '+d.getUTCMonth()+'.';}
101
- };
102
-
103
- switch(time){
104
- case 'minute': return minuteCustom;
105
- case 'hour': return hourCustom;
106
- case 'day': return dayCustom;
107
- case 'week': return weekCustom;
108
- }
109
- }
110
-
111
- var x_axis = new Rickshaw.Graph.Axis.Time({
112
- graph: graph,
113
- timeUnit: timeUnit(this.minute)
114
- });
115
-
116
- var y_axis = new Rickshaw.Graph.Axis.Y({
117
- graph: graph,
118
- orientation: 'left',
119
- tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
120
- element: this.$('.y-axis').get(0)
121
- });
122
-
123
- graph.render();
124
-
125
- var hoverDetail = new Rickshaw.Graph.HoverDetail({
126
- graph: graph
127
- });
128
-
129
- return this;
130
- }
131
- });
132
-
133
- var MetricDetailView = Backbone.View.extend({
134
- template: Handlebars.compile($("#metric-details").html()),
135
-
136
- initialize: function() {
137
- _.bindAll(this, "render");
138
- },
139
-
140
- render: function() {
141
- $(this.el).html(this.template({ metric: this.model.toJSON() }));
142
-
143
- // TODO: make code more DRY
144
- var minuteGraphCollection = new GraphCollection({
145
- targets: this.model.get('name'),
146
- time: 'minute'
147
- });
148
-
149
- minuteGraphCollection.fetch({
150
- success: function() {
151
- var minuteView = new GraphView({
152
- series: minuteGraphCollection.toJSON(),
153
- time: "minute",
154
- el: this.$("#graph-container-minute")
155
- });
156
- minuteView.render();
157
- }
158
- });
159
-
160
- var hourGraphCollection = new GraphCollection({
161
- targets: this.model.get('name'),
162
- time: 'hour'
163
- });
164
-
165
- hourGraphCollection.fetch({
166
- success: function() {
167
- var hourView = new GraphView({
168
- series: hourGraphCollection.toJSON(),
169
- time: "hour",
170
- el: this.$("#graph-container-hour")
171
- });
172
- hourView.render();
173
- }
174
- });
175
-
176
- var dayGraphCollection = new GraphCollection({
177
- targets: this.model.get('name'),
178
- time: 'day'
179
- });
180
-
181
- dayGraphCollection.fetch({
182
- success: function() {
183
- var dayView = new GraphView({
184
- series: dayGraphCollection.toJSON(),
185
- time: "day",
186
- el: this.$("#graph-container-day")
187
- });
188
- dayView.render();
189
- }
190
- });
191
-
192
- var weekGraphCollection = new GraphCollection({
193
- targets: this.model.get('name'),
194
- time: 'week'
195
- });
196
-
197
- weekGraphCollection.fetch({
198
- success: function() {
199
- var weekView = new GraphView({
200
- series: weekGraphCollection.toJSON(),
201
- time: "week",
202
- el: this.$("#graph-container-week")
203
- });
204
- weekView.render();
205
- }
206
- });
207
-
208
- return this;
209
- }
210
- });
211
-
212
- var MetricListView = Backbone.View.extend({
213
- render: function() {
214
- $(this.el).html("This is a metrics list view");
215
- return this;
216
- }
217
- });
218
-
219
- var AppView = Backbone.View.extend({
220
- template: Handlebars.compile($("#metric-list").html()),
221
-
222
- initialize: function(options) {
223
- _.bindAll(this, "render");
224
- this.collection.bind('reset', this.render);
225
- },
226
-
227
- render: function() {
228
- $(this.el).html(this.template({ metrics: this.collection.toJSON() }));
229
- return this;
230
- }
231
- });
232
-
233
- var metricList = new MetricList();
234
- metricList.fetch();
235
-
236
- var Router = Backbone.Router.extend({
237
- routes: {
238
- "": "home",
239
- "metrics": "metrics",
240
- "metrics/:name": "metric_details",
241
- "dashboard": "dashboard",
242
- "about": "about"
243
- },
244
-
245
- home: function() {
246
- console.log("ROUTER: home");
247
- new AppView({ el: "#main", collection: metricList }).render();
248
- },
249
- metrics: function() {
250
- console.log("ROUTER: metrics");
251
- new AppView({ el: "#main", collection: metricList }).render();
252
- },
253
- metric_details: function(name) {
254
- console.log("ROUTER: metric details:", name);
255
-
256
- metric = new Metric({ name: name});
257
- metric.fetch({
258
- success: function(model, resp) {
259
- new MetricDetailView({ el: "#main", model: model}).render();
260
- },
261
- error: function() {
262
- alert("Document not found:"+id);
263
- }
264
- });
265
- },
266
- dashboard: function() {
267
- console.log("ROUTER: dashboard");
268
- new DashboardView({ el: "#main" }).render();
269
- },
270
- about: function() {
271
- console.log("ROUTER: about");
272
- }
273
- });
274
-
275
- var router = new Router();
276
- Backbone.history.start({pushState: false});
277
-
278
- });