Index: tracing/tracing/base/multi_dimensional_view.html |
diff --git a/tracing/tracing/base/multi_dimensional_view.html b/tracing/tracing/base/multi_dimensional_view.html |
index 7a26fe11a2459f25cb68a2b4186f43ddb76d9ce8..a6563c3a21ad197634c1f51a4c8b44503bc3e9eb 100644 |
--- a/tracing/tracing/base/multi_dimensional_view.html |
+++ b/tracing/tracing/base/multi_dimensional_view.html |
@@ -143,16 +143,18 @@ tr.exportTo('tr.b', function() { |
// Map from child name to child node for each dimension. |
var dimensions = title.length; |
this.children = new Array(dimensions); |
- for (var i = 0; i < dimensions; i++) |
+ for (var i = 0; i < dimensions; i++) { |
this.children[i] = new Map(); |
+ } |
// For each value index (from 0 to |valueCount| - 1), we store the self and |
// total values together with a Boolean flag whether the value is only a |
// lower bound (i.e. aggregated from children rather than provided |
// directly). |
this.values = new Array(valueCount); |
- for (var v = 0; v < valueCount; v++) |
+ for (var v = 0; v < valueCount; v++) { |
this.values[v] = { self: 0, total: 0, totalState: NOT_PROVIDED }; |
+ } |
} |
/** |
@@ -278,12 +280,14 @@ tr.exportTo('tr.b', function() { |
* @{constructor} |
*/ |
function MultiDimensionalViewBuilder(dimensions, valueCount) { |
- if (typeof(dimensions) !== 'number' || dimensions < 0) |
+ if (typeof(dimensions) !== 'number' || dimensions < 0) { |
throw new Error('Dimensions must be a non-negative number'); |
+ } |
this.dimensions_ = dimensions; |
- if (typeof(valueCount) !== 'number' || valueCount < 0) |
+ if (typeof(valueCount) !== 'number' || valueCount < 0) { |
throw new Error('Number of values must be a non-negative number'); |
+ } |
this.valueCount_ = valueCount; |
this.buildRoot_ = this.createRootNode_(); |
@@ -292,8 +296,9 @@ tr.exportTo('tr.b', function() { |
this.bottomUpHeavyViewNode_ = undefined; |
this.maxDimensionDepths_ = new Array(dimensions); |
- for (var d = 0; d < dimensions; d++) |
+ for (var d = 0; d < dimensions; d++) { |
this.maxDimensionDepths_[d] = 0; |
+ } |
} |
/** @{enum} */ |
@@ -357,10 +362,12 @@ tr.exportTo('tr.b', function() { |
throw new Error( |
'Paths cannot be added after either view has been built'); |
} |
- if (path.length !== this.dimensions_) |
+ if (path.length !== this.dimensions_) { |
throw new Error('Path must be ' + this.dimensions_ + '-dimensional'); |
- if (values.length !== this.valueCount_) |
+ } |
+ if (values.length !== this.valueCount_) { |
throw new Error('Must provide ' + this.valueCount_ + ' values'); |
+ } |
var isTotal; |
switch (valueKind) { |
@@ -380,14 +387,14 @@ tr.exportTo('tr.b', function() { |
var singleDimensionPathLength = singleDimensionPath.length; |
this.maxDimensionDepths_[d] = |
Math.max(this.maxDimensionDepths_[d], singleDimensionPathLength); |
- for (var i = 0; i < singleDimensionPathLength; i++) |
+ for (var i = 0; i < singleDimensionPathLength; i++) { |
node = this.getOrCreateChildNode_(node, d, singleDimensionPath[i]); |
+ } |
} |
for (var v = 0; v < this.valueCount_; v++) { |
var addedValue = values[v]; |
- if (addedValue === undefined) |
- continue; |
+ if (addedValue === undefined) continue; |
var nodeValue = node.values[v]; |
if (isTotal) { |
nodeValue.total += addedValue; |
@@ -470,14 +477,16 @@ tr.exportTo('tr.b', function() { |
getOrCreateChildNode_: function( |
parentNode, dimension, childDimensionTitle) { |
- if (dimension < 0 || dimension >= this.dimensions_) |
+ if (dimension < 0 || dimension >= this.dimensions_) { |
throw new Error('Invalid dimension'); |
+ } |
var dimensionChildren = parentNode.children[dimension]; |
var childNode = dimensionChildren.get(childDimensionTitle); |
- if (childNode !== undefined) |
+ if (childNode !== undefined) { |
return childNode; |
+ } |
var childTitle = parentNode.title.slice(); |
childTitle[dimension] = childDimensionTitle; |
@@ -705,27 +714,29 @@ tr.exportTo('tr.b', function() { |
// Value index V -> minResidual(|node|, V). |
var minResidual = new Array(this.valueCount_); |
- for (var v = 0; v < this.valueCount_; v++) |
- minResidual[v] = 0; |
+ for (var v = 0; v < this.valueCount_; v++) minResidual[v] = 0; |
// Value index V -> |node| value V. |
var nodeValues = node.values; |
// Value index V -> dimensionalSelfSum(|node|, V)[|d|]. |
var nodeSelfSums = new Array(this.valueCount_); |
- for (var v = 0; v < this.valueCount_; v++) |
+ for (var v = 0; v < this.valueCount_; v++) { |
nodeSelfSums[v] = nodeValues[v].self; |
+ } |
for (var d = 0; d < this.dimensions_; d++) { |
// Value index V -> sum over children C of |node| at dimension |d| { |
// residual(C, V) }. |
var childResidualSums = new Array(this.valueCount_); |
- for (var v = 0; v < this.valueCount_; v++) |
+ for (var v = 0; v < this.valueCount_; v++) { |
childResidualSums[v] = 0; |
+ } |
for (var childNode of node.children[d].values()) { |
- if (d >= firstDimensionToFinalize) |
+ if (d >= firstDimensionToFinalize) { |
this.finalizeTotalValues_(childNode, d, dimensionalSelfSumsMap); |
+ } |
// Dimension D -> Value index V -> |
// dimensionalSelfSum(|childNode|, V)[D]. |
var childNodeSelfSums = dimensionalSelfSumsMap.get(childNode); |
@@ -743,8 +754,9 @@ tr.exportTo('tr.b', function() { |
} |
dimensionalSelfSums[d] = nodeSelfSums.slice(); |
- for (var v = 0; v < this.valueCount_; v++) |
+ for (var v = 0; v < this.valueCount_; v++) { |
minResidual[v] = Math.max(minResidual[v], childResidualSums[v]); |
+ } |
} |
for (var v = 0; v < this.valueCount_; v++) { |
@@ -752,8 +764,9 @@ tr.exportTo('tr.b', function() { |
nodeValues[v].total, nodeSelfSums[v] + minResidual[v]); |
} |
- if (dimensionalSelfSumsMap.has(node)) |
+ if (dimensionalSelfSumsMap.has(node)) { |
throw new Error('Internal error: Node finalized more than once'); |
+ } |
dimensionalSelfSumsMap.set(node, dimensionalSelfSums); |
}, |
@@ -1049,8 +1062,9 @@ tr.exportTo('tr.b', function() { |
RecursionDepthTracker.prototype = { |
push: function(viewNode) { |
- if (this.bottomIndex === 0) |
+ if (this.bottomIndex === 0) { |
throw new Error('Cannot push to a full tracker'); |
+ } |
var title = viewNode.title[this.dimension_]; |
this.bottomIndex--; |
this.titlePath[this.bottomIndex] = title; |
@@ -1067,8 +1081,9 @@ tr.exportTo('tr.b', function() { |
// depth. |
var maxLengths = zFunction(this.titlePath, this.bottomIndex); |
var recursionDepth = 0; |
- for (var i = 0; i < maxLengths.length; i++) |
+ for (var i = 0; i < maxLengths.length; i++) { |
recursionDepth = Math.max(recursionDepth, maxLengths[i]); |
+ } |
childTrackerNode = |
this.createNode_(recursionDepth, this.currentTrackerNode_); |
@@ -1077,8 +1092,9 @@ tr.exportTo('tr.b', function() { |
}, |
pop: function() { |
- if (this.bottomIndex === this.topIndex) |
+ if (this.bottomIndex === this.topIndex) { |
throw new Error('Cannot pop from an empty tracker'); |
+ } |
this.titlePath[this.bottomIndex] = undefined; |
this.viewNodePath[this.bottomIndex] = undefined; |
@@ -1125,18 +1141,18 @@ tr.exportTo('tr.b', function() { |
*/ |
function zFunction(list, startIndex) { |
var n = list.length - startIndex; |
- if (n === 0) |
- return []; |
+ if (n === 0) return []; |
var z = new Array(n); |
z[0] = 0; |
for (var i = 1, left = 0, right = 0; i < n; ++i) { |
var maxLength; |
- if (i <= right) |
+ if (i <= right) { |
maxLength = Math.min(right - i + 1, z[i - left]); |
- else |
+ } else { |
maxLength = 0; |
+ } |
while (i + maxLength < n && list[startIndex + maxLength] === |
list[startIndex + i + maxLength]) { |