OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright 2016 The Chromium Authors. All rights reserved. | 3 Copyright 2016 The Chromium Authors. All rights reserved. |
4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 | 7 |
8 <link rel="import" href="/tracing/base/iteration_helpers.html"> | 8 <link rel="import" href="/tracing/base/iteration_helpers.html"> |
9 <link rel="import" href="/tracing/value/diagnostics/diagnostic_map.html"> | 9 <link rel="import" href="/tracing/value/diagnostics/diagnostic_map.html"> |
10 <link rel="import" href="/tracing/value/unit.html"> | 10 <link rel="import" href="/tracing/value/unit.html"> |
11 | 11 |
12 <script> | 12 <script> |
13 'use strict'; | 13 'use strict'; |
14 | 14 |
15 tr.exportTo('tr.v', function() { | 15 tr.exportTo('tr.v', function() { |
16 var MAX_DIAGNOSTIC_MAPS = 16; | 16 var MAX_DIAGNOSTIC_MAPS = 16; |
17 | 17 |
18 class NumericBase { | 18 class NumericBase { |
19 constructor(unit) { | 19 constructor(unit) { |
20 if (!(unit instanceof tr.v.Unit)) | 20 if (!(unit instanceof tr.v.Unit)) |
21 throw new Error('Expected provided unit to be instance of Unit'); | 21 throw new Error('Expected provided unit to be instance of Unit'); |
22 | 22 |
23 this.unit = unit; | 23 this.unit = unit; |
24 } | 24 } |
25 | 25 |
26 merge(other) { | 26 merge(other) { |
27 if (this.unit !== other.unit) | 27 if (this.unit !== other.unit) |
28 throw new Error('Merging Numerics with different units'); | 28 throw new Error('Merging Numerics with different units'); |
29 | 29 |
30 // Two Numerics that were built using the same NumericBuilder | 30 // Two Numerics that were built with the same boundaries |
31 // can be merged using addNumeric(). | 31 // can be merged using addNumeric(). |
32 if (this instanceof tr.v.Histogram && other instanceof tr.v.Histogram && | 32 if (this instanceof tr.v.Histogram && other instanceof tr.v.Histogram && |
33 this.canAddNumeric(other)) { | 33 this.canAddNumeric(other)) { |
34 var result = this.clone(); | 34 var result = this.clone(); |
35 result.addNumeric(other.clone()); | 35 result.addNumeric(other.clone()); |
36 return result; | 36 return result; |
37 } | 37 } |
38 | 38 |
39 // Either a Scalar and a Histogram, or two Scalars... | 39 // Either a Scalar and a Histogram, or two Scalars... |
40 // or two Numerics that were not built using the same NumericBuilder, | 40 // or two Numerics that were not built with the same boundaries should be |
41 // should be built from their raw samples. | 41 // built from their raw samples. |
42 var samples = []; | 42 var samples = []; |
43 this.sampleValuesInto(samples); | 43 this.sampleValuesInto(samples); |
44 other.sampleValuesInto(samples); | 44 other.sampleValuesInto(samples); |
45 return tr.v.Histogram.buildFromSamples(this.unit, samples); | 45 return tr.v.Histogram.buildFromSamples(this.unit, samples); |
46 } | 46 } |
47 | 47 |
48 sampleValuesInto(samples) { | 48 sampleValuesInto(samples) { |
49 throw new Error('Not implemented'); | 49 throw new Error('Not implemented'); |
50 } | 50 } |
51 | 51 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 return new ScalarNumeric(tr.v.Unit.fromJSON(d.unit), d.value); | 120 return new ScalarNumeric(tr.v.Unit.fromJSON(d.unit), d.value); |
121 } | 121 } |
122 }; | 122 }; |
123 | 123 |
124 return { | 124 return { |
125 NumericBase: NumericBase, | 125 NumericBase: NumericBase, |
126 ScalarNumeric: ScalarNumeric | 126 ScalarNumeric: ScalarNumeric |
127 }; | 127 }; |
128 }); | 128 }); |
129 </script> | 129 </script> |
OLD | NEW |