| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright (c) 2015 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2015 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/color_scheme.html"> | 8 <link rel="import" href="/tracing/base/color_scheme.html"> |
| 9 <link rel="import" href="/tracing/base/range.html"> | 9 <link rel="import" href="/tracing/base/range.html"> |
| 10 <link rel="import" href="/tracing/base/unit.html"> | 10 <link rel="import" href="/tracing/base/unit.html"> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * A vertical axis for a (set of) chart series which maps an arbitrary range | 23 * A vertical axis for a (set of) chart series which maps an arbitrary range |
| 24 * of values [min, max] to the unit range [0, 1]. | 24 * of values [min, max] to the unit range [0, 1]. |
| 25 * | 25 * |
| 26 * @constructor | 26 * @constructor |
| 27 */ | 27 */ |
| 28 function ChartSeriesYAxis(opt_min, opt_max) { | 28 function ChartSeriesYAxis(opt_min, opt_max) { |
| 29 this.guid_ = tr.b.GUID.allocateSimple(); | 29 this.guid_ = tr.b.GUID.allocateSimple(); |
| 30 this.bounds = new tr.b.Range(); | 30 this.bounds = new tr.b.Range(); |
| 31 if (opt_min !== undefined) | 31 if (opt_min !== undefined) { |
| 32 this.bounds.addValue(opt_min); | 32 this.bounds.addValue(opt_min); |
| 33 if (opt_max !== undefined) | 33 } |
| 34 if (opt_max !== undefined) { |
| 34 this.bounds.addValue(opt_max); | 35 this.bounds.addValue(opt_max); |
| 36 } |
| 35 } | 37 } |
| 36 | 38 |
| 37 ChartSeriesYAxis.prototype = { | 39 ChartSeriesYAxis.prototype = { |
| 38 get guid() { | 40 get guid() { |
| 39 return this.guid_; | 41 return this.guid_; |
| 40 }, | 42 }, |
| 41 | 43 |
| 42 valueToUnitRange: function(value) { | 44 valueToUnitRange: function(value) { |
| 43 if (this.bounds.isEmpty) | 45 if (this.bounds.isEmpty) { |
| 44 throw new Error('Chart series y-axis bounds are empty'); | 46 throw new Error('Chart series y-axis bounds are empty'); |
| 47 } |
| 45 var bounds = this.bounds; | 48 var bounds = this.bounds; |
| 46 if (bounds.range === 0) | 49 if (bounds.range === 0) return 0; |
| 47 return 0; | |
| 48 return (value - bounds.min) / bounds.range; | 50 return (value - bounds.min) / bounds.range; |
| 49 }, | 51 }, |
| 50 | 52 |
| 51 unitRangeToValue: function(unitRange) { | 53 unitRangeToValue: function(unitRange) { |
| 52 if (this.bounds.isEmpty) { | 54 if (this.bounds.isEmpty) { |
| 53 throw new Error('Chart series y-axis bounds are empty'); | 55 throw new Error('Chart series y-axis bounds are empty'); |
| 54 } | 56 } |
| 55 return unitRange * this.bounds.range + this.bounds.min; | 57 return unitRange * this.bounds.range + this.bounds.min; |
| 56 }, | 58 }, |
| 57 | 59 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 88 * value range is non-empty and valid. | 90 * value range is non-empty and valid. |
| 89 * | 91 * |
| 90 * Note that unless expanding/shrinking a bound is explicitly enabled in | 92 * Note that unless expanding/shrinking a bound is explicitly enabled in |
| 91 * the configuration, non-empty bounds will not be changed under any | 93 * the configuration, non-empty bounds will not be changed under any |
| 92 * circumstances. | 94 * circumstances. |
| 93 * | 95 * |
| 94 * Observe that if no configuration is provided (or all flags are set to | 96 * Observe that if no configuration is provided (or all flags are set to |
| 95 * false), this method will only modify the y-axis bounds if they are empty. | 97 * false), this method will only modify the y-axis bounds if they are empty. |
| 96 */ | 98 */ |
| 97 autoSetFromRange: function(range, opt_config) { | 99 autoSetFromRange: function(range, opt_config) { |
| 98 if (range.isEmpty) | 100 if (range.isEmpty) return; |
| 99 return; | |
| 100 | 101 |
| 101 var bounds = this.bounds; | 102 var bounds = this.bounds; |
| 102 if (bounds.isEmpty) { | 103 if (bounds.isEmpty) { |
| 103 bounds.addRange(range); | 104 bounds.addRange(range); |
| 104 return; | 105 return; |
| 105 } | 106 } |
| 106 | 107 |
| 107 if (!opt_config) | 108 if (!opt_config) return; |
| 108 return; | |
| 109 | 109 |
| 110 var useRangeMin = (opt_config.expandMin && range.min < bounds.min || | 110 var useRangeMin = (opt_config.expandMin && range.min < bounds.min || |
| 111 opt_config.shrinkMin && range.min > bounds.min); | 111 opt_config.shrinkMin && range.min > bounds.min); |
| 112 var useRangeMax = (opt_config.expandMax && range.max > bounds.max || | 112 var useRangeMax = (opt_config.expandMax && range.max > bounds.max || |
| 113 opt_config.shrinkMax && range.max < bounds.max); | 113 opt_config.shrinkMax && range.max < bounds.max); |
| 114 | 114 |
| 115 // Neither bound is modified. | 115 // Neither bound is modified. |
| 116 if (!useRangeMin && !useRangeMax) | 116 if (!useRangeMin && !useRangeMax) return; |
| 117 return; | |
| 118 | 117 |
| 119 // Both bounds are modified. Assuming the range argument is a valid | 118 // Both bounds are modified. Assuming the range argument is a valid |
| 120 // range, no extra checks are necessary. | 119 // range, no extra checks are necessary. |
| 121 if (useRangeMin && useRangeMax) { | 120 if (useRangeMin && useRangeMax) { |
| 122 bounds.min = range.min; | 121 bounds.min = range.min; |
| 123 bounds.max = range.max; | 122 bounds.max = range.max; |
| 124 return; | 123 return; |
| 125 } | 124 } |
| 126 | 125 |
| 127 // Only one bound is modified. We must ensure that it doesn't go | 126 // Only one bound is modified. We must ensure that it doesn't go |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 ctx.stroke(); | 208 ctx.stroke(); |
| 210 ctx.restore(); | 209 ctx.restore(); |
| 211 } | 210 } |
| 212 }; | 211 }; |
| 213 | 212 |
| 214 return { | 213 return { |
| 215 ChartSeriesYAxis, | 214 ChartSeriesYAxis, |
| 216 }; | 215 }; |
| 217 }); | 216 }); |
| 218 </script> | 217 </script> |
| OLD | NEW |