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. | |
11 */ | 9 */ |
12 var TimelineDataSeries = (function() { | 10 var TimelineDataSeries = (function() { |
13 'use strict'; | 11 'use strict'; |
14 | 12 |
15 /** | 13 /** |
16 * @constructor | 14 * @constructor |
17 */ | 15 */ |
18 function TimelineDataSeries() { | 16 function TimelineDataSeries() { |
19 // List of DataPoints in chronological order. | 17 // List of DataPoints in chronological order. |
20 this.dataPoints_ = []; | 18 this.dataPoints_ = []; |
21 | 19 |
22 // Default color. Should always be overridden prior to display. | 20 // Default color. Should always be overridden prior to display. |
23 this.color_ = 'red'; | 21 this.color_ = 'red'; |
24 // Whether or not the data series should be drawn. | 22 // Whether or not the data series should be drawn. |
25 this.isVisible_ = true; | 23 this.isVisible_ = true; |
26 | 24 |
27 this.cacheStartTime_ = null; | 25 this.cacheStartTime_ = null; |
28 this.cacheStepSize_ = 0; | 26 this.cacheStepSize_ = 0; |
29 this.cacheValues_ = []; | 27 this.cacheValues_ = []; |
30 } | 28 } |
31 | 29 |
32 TimelineDataSeries.prototype = { | 30 TimelineDataSeries.prototype = { |
33 /** | 31 /** |
34 * Adds a DataPoint to |this| with the specified time and value. | 32 * Adds a DataPoint to |this| with the specified time and value. |
35 * DataPoints are assumed to be received in chronological order. | 33 * DataPoints are assumed to be received in chronological order. |
36 */ | 34 */ |
37 addPoint: function(timeTicks, value) { | 35 addPoint: function(timeTicks, value) { |
38 var time = new Date(timeTicks); | 36 var time = new Date(timeTicks); |
39 this.dataPoints_.push(new DataPoint(time, value)); | 37 this.dataPoints_.push(new DataPoint(time, value)); |
40 | |
41 if (this.dataPoints_.length > MAX_STATS_DATA_POINT_BUFFER_SIZE) | |
42 this.dataPoints_.shift(); | |
43 }, | 38 }, |
44 | 39 |
45 isVisible: function() { | 40 isVisible: function() { |
46 return this.isVisible_; | 41 return this.isVisible_; |
47 }, | 42 }, |
48 | 43 |
49 show: function(isVisible) { | 44 show: function(isVisible) { |
50 this.isVisible_ = isVisible; | 45 this.isVisible_ = isVisible; |
51 }, | 46 }, |
52 | 47 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 * milliseconds since the Unix epoch, and a numeric value. | 100 * milliseconds since the Unix epoch, and a numeric value. |
106 * @constructor | 101 * @constructor |
107 */ | 102 */ |
108 function DataPoint(time, value) { | 103 function DataPoint(time, value) { |
109 this.time = time; | 104 this.time = time; |
110 this.value = value; | 105 this.value = value; |
111 } | 106 } |
112 | 107 |
113 return TimelineDataSeries; | 108 return TimelineDataSeries; |
114 })(); | 109 })(); |
OLD | NEW |