From ca7d8699c8ba59867607a7ae960a06b7e4dce2f2 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Sun, 31 Jul 2016 23:05:00 +0300 Subject: [PATCH] Add additional results format for sunburst --- .../visualizations/sunburst_sequence.js | 34 ++++++++++++++----- .../sunburst_sequence_editor.html | 13 ++++++- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/rd_ui/app/scripts/visualizations/sunburst_sequence.js b/rd_ui/app/scripts/visualizations/sunburst_sequence.js index ca1457ddb..2565f229f 100644 --- a/rd_ui/app/scripts/visualizations/sunburst_sequence.js +++ b/rd_ui/app/scripts/visualizations/sunburst_sequence.js @@ -417,6 +417,7 @@ var nodeName = nodes[j]; var isLeaf = j + 1 === nodes.length; + if (!children) { currentNode.children = children = []; children.push({ @@ -455,16 +456,31 @@ } function buildNodes(raw) { - var grouped = _.groupBy(raw, 'sequence'); + var values; - var values = _.map(grouped, function(value, key) { - var sorted = _.sortBy(value, 'stage'); - return { - size: value[0].value, - sequence: value[0].sequence, - nodes: _.pluck(sorted, 'node') - } - }); + if (_.has(raw[0], 'sequence') && _.has(raw[0], 'stage') && _.has(raw[0], 'node') && _.has(raw[0], 'value')) { + + var grouped = _.groupBy(raw, 'sequence'); + + var values = _.map(grouped, function(value, key) { + var sorted = _.sortBy(value, 'stage'); + return { + size: value[0].value, + sequence: value[0].sequence, + nodes: _.pluck(sorted, 'node') + } + }); + } else { + var keys = _.sortBy(_.without(_.keys(raw[0]), 'value'), _.identity); + + values = _.map(raw, function(row, sequence) { + return { + size: row.value, + sequence: sequence, + nodes: _.compact(_.map(keys, function(key) { return row[key] })) + } + }) + } return values; } diff --git a/rd_ui/app/views/visualizations/sunburst_sequence_editor.html b/rd_ui/app/views/visualizations/sunburst_sequence_editor.html index 4f9e95ab8..b85f5051d 100644 --- a/rd_ui/app/views/visualizations/sunburst_sequence_editor.html +++ b/rd_ui/app/views/visualizations/sunburst_sequence_editor.html @@ -7,13 +7,24 @@

- This visualization expects the query result to have rows with the following columns: + This visualization expects the query result to have rows in one of the following formats: + Option 1: + + Option 2: +