Skip to content

Commit 65386b5

Browse files
Fix get max level
1 parent e8e84dd commit 65386b5

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "LightPivotTable",
33
"author": "ZitRo",
4-
"version": "1.8.7",
4+
"version": "1.8.8",
55
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
66
"main": "test/testServer.js",
77
"repository": {

source/js/DataController.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,30 @@ DataController.prototype.resetRawData = function () {
443443
}
444444
};
445445

446-
var getMaxLevel = function (c) {
447-
var lev = 0;
448-
for (var i in c) {
449-
if (c[i].children && c[i].children.length) {
450-
lev = Math.max(lev, getMaxLevel(c[i].children));
446+
var getMaxLevel = function (children, level) {
447+
448+
if (typeof level === "undefined")
449+
level = 0;
450+
451+
function maxLevel (node, level) {
452+
if (node.children) {
453+
var max = 0;
454+
for (var i in node.children) {
455+
max = Math.max(max, maxLevel(node.children[i], level + 1));
456+
}
457+
return max;
458+
} else {
459+
if (node["type"] === "msr" && MEASURES_HIDDEN)
460+
return level - 1;
461+
return level;
451462
}
452463
}
453-
return lev + 1;
464+
465+
return children.reduce(
466+
function (acc, node) { return Math.max(acc, maxLevel(node, 1)) },
467+
level
468+
);
469+
454470
};
455471

456472
var dim1raw = function (a, c, arr, hor, level, maxLevel) {

0 commit comments

Comments
 (0)