Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions caravel/assets/visualizations/sunburst.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ function sunburstVis(slice) {
slice.error(error.responseText);
return '';
}

createBreadcrumbs(rawData);
createVisualization(rawData);

Expand Down Expand Up @@ -299,7 +298,8 @@ function sunburstVis(slice) {
name: "root",
children: []
};
for (var i = 0; i < rows.length; i++) {

for (var i = 0; i < rows.length; i++) { // each record [groupby1val, groupby2val, (<string> or 0)n, m1, m2]
var row = rows[i];
var m1 = Number(row[row.length - 2]);
var m2 = Number(row[row.length - 1]);
Expand All @@ -308,19 +308,22 @@ function sunburstVis(slice) {
continue;
}
var currentNode = root;
for (var j = 0; j < levels.length; j++) {
for (var level = 0; level < levels.length; level++) {
var children = currentNode.children || [];
var nodeName = levels[j];
var nodeName = levels[level];
// If the next node has the name "0", it will
var isLeafNode = (j >= levels.length - 1) || levels[j+1] === 0;
var childNode;
var isLeafNode = (level >= levels.length - 1) || levels[level+1] === 0;
var childNode, currChild;

if (!isLeafNode) {
// Not yet at the end of the sequence; move down the tree.
var foundChild = false;
for (var k = 0; k < children.length; k++) {
if (children[k].name === nodeName) {
childNode = children[k];
currChild = children[k];
if (currChild.name === nodeName &&
currChild.level === level) { // must match name AND level

childNode = currChild;
foundChild = true;
break;
}
Expand All @@ -329,11 +332,13 @@ function sunburstVis(slice) {
if (!foundChild) {
childNode = {
name: nodeName,
children: []
children: [],
level: level
};
children.push(childNode);
}
currentNode = childNode;

} else if (nodeName !== 0) {
// Reached the end of the sequence; create a leaf node.
childNode = {
Expand Down Expand Up @@ -361,6 +366,7 @@ function sunburstVis(slice) {
}
return [node.m1, node.m2];
}

recurse(root);
return root;
}
Expand Down