OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * A TimelineDataSeries collects an ordered series of (time, value) pairs, | 6 * A TimelineDataSeries collects an ordered series of (time, value) pairs, |
7 * and converts them to graph points. It also keeps track of its color and | 7 * and converts them to graph points. It also keeps track of its color and |
8 * current visibility state. | 8 * current visibility state. |
| 9 * It keeps MAX_STATS_DATA_POINT_BUFFER_SIZE data points at most. Old data |
| 10 * points will be dropped when it reaches this size. |
9 */ | 11 */ |
10 var TimelineDataSeries = (function() { | 12 var TimelineDataSeries = (function() { |
11 'use strict'; | 13 'use strict'; |
12 | 14 |
13 /** | 15 /** |
14 * @constructor | 16 * @constructor |
15 */ | 17 */ |
16 function TimelineDataSeries() { | 18 function TimelineDataSeries() { |
17 // List of DataPoints in chronological order. | 19 // List of DataPoints in chronological order. |
18 this.dataPoints_ = []; | 20 this.dataPoints_ = []; |
19 | 21 |
20 // Default color. Should always be overridden prior to display. | 22 // Default color. Should always be overridden prior to display. |
21 this.color_ = 'red'; | 23 this.color_ = 'red'; |
22 // Whether or not the data series should be drawn. | 24 // Whether or not the data series should be drawn. |
23 this.isVisible_ = true; | 25 this.isVisible_ = true; |
24 | 26 |
25 this.cacheStartTime_ = null; | 27 this.cacheStartTime_ = null; |
26 this.cacheStepSize_ = 0; | 28 this.cacheStepSize_ = 0; |
27 this.cacheValues_ = []; | 29 this.cacheValues_ = []; |
28 } | 30 } |
29 | 31 |
30 TimelineDataSeries.prototype = { | 32 TimelineDataSeries.prototype = { |
31 /** | 33 /** |
32 * Adds a DataPoint to |this| with the specified time and value. | 34 * Adds a DataPoint to |this| with the specified time and value. |
33 * DataPoints are assumed to be received in chronological order. | 35 * DataPoints are assumed to be received in chronological order. |
34 */ | 36 */ |
35 addPoint: function(timeTicks, value) { | 37 addPoint: function(timeTicks, value) { |
36 var time = new Date(timeTicks); | 38 var time = new Date(timeTicks); |
37 this.dataPoints_.push(new DataPoint(time, value)); | 39 this.dataPoints_.push(new DataPoint(time, value)); |
| 40 |
| 41 if (this.dataPoints_.length > MAX_STATS_DATA_POINT_BUFFER_SIZE) |
| 42 this.dataPoints_.shift(); |
38 }, | 43 }, |
39 | 44 |
40 isVisible: function() { | 45 isVisible: function() { |
41 return this.isVisible_; | 46 return this.isVisible_; |
42 }, | 47 }, |
43 | 48 |
44 show: function(isVisible) { | 49 show: function(isVisible) { |
45 this.isVisible_ = isVisible; | 50 this.isVisible_ = isVisible; |
46 }, | 51 }, |
47 | 52 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 * milliseconds since the Unix epoch, and a numeric value. | 105 * milliseconds since the Unix epoch, and a numeric value. |
101 * @constructor | 106 * @constructor |
102 */ | 107 */ |
103 function DataPoint(time, value) { | 108 function DataPoint(time, value) { |
104 this.time = time; | 109 this.time = time; |
105 this.value = value; | 110 this.value = value; |
106 } | 111 } |
107 | 112 |
108 return TimelineDataSeries; | 113 return TimelineDataSeries; |
109 })(); | 114 })(); |
OLD | NEW |