in src/dataViewBuilder/matrixBuilder.ts [391:435]
private findValueInHierarchy(
isMatch: (node: powerbi.DataViewMatrixNode, level: number) => boolean,
root: powerbi.DataViewMatrixNode,
hierarchyDepth: number): number {
let count = 0;
let stack: {
level: number;
partialMatch: boolean;
node: powerbi.DataViewMatrixNode
}[] = [];
stack.unshift({
partialMatch: true,
level: -1,
node: root,
});
while (stack.length > 0) {
const { node, level, partialMatch } = stack.shift();
const atLeaf = level >= hierarchyDepth; // columnValues.length - 2;
const match = partialMatch
&& (level === -1 // root node does not have levelValues
|| isMatch(node, level));
if (!atLeaf) {
stack.unshift(...map(node.children, (child) => ({
partialMatch: match,
level: level + 1,
node: child,
})));
}
else {
if (match) {
return count;
}
else {
// Assumes there is only 1 level of children under this node, the nodes for the measures
count += node.children.length;
}
}
}
return count;
}