You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2017/03/15 15:42:15 UTC

zeppelin git commit: [WIP] [Discuss] Make use of all grouped data to draw pie chart

Repository: zeppelin
Updated Branches:
  refs/heads/master f2c865aaa -> a2cd4ae4e


[WIP] [Discuss] Make use of all grouped data to draw pie chart

### What is this PR for?
Now, grouped pie charts only uses the data from the first group
With this fix-
* Add data from all groups to variable d3g, so all groups could be rendered
* Rewrite for loop with map and concat
* Refactor some variables to const and let

### What type of PR is it?
[Bug Fix]

### What is the Jira issue?
*  [ZEPPELIN-2237](https://issues.apache.org/jira/browse/ZEPPELIN-2237)

### How should this be tested?
* Create a built in pie chart visualization
* Select a column to group the data
* Should display the visualization based on all the available grouped data

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: ess_ess <sr...@gmail.com>

This patch had conflicts when merged, resolved by
Committer: Lee moon soo <mo...@apache.org>

Closes #2128 from sravan-s/ZEPPELIN-2237-grouped-piechart and squashes the following commits:

652c943 [ess_ess] Make use of all grouped data to draw pie chart


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/a2cd4ae4
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/a2cd4ae4
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/a2cd4ae4

Branch: refs/heads/master
Commit: a2cd4ae4e17024501bb0654e71747a07ff68600d
Parents: f2c865a
Author: ess_ess <sr...@gmail.com>
Authored: Fri Mar 10 09:19:55 2017 +0530
Committer: Lee moon soo <mo...@apache.org>
Committed: Wed Mar 15 08:42:11 2017 -0700

----------------------------------------------------------------------
 .../builtins/visualization-piechart.js          | 30 +++++++++++++-------
 1 file changed, 19 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/a2cd4ae4/zeppelin-web/src/app/visualization/builtins/visualization-piechart.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/visualization/builtins/visualization-piechart.js b/zeppelin-web/src/app/visualization/builtins/visualization-piechart.js
index 9cc7922..f74ecd0 100644
--- a/zeppelin-web/src/app/visualization/builtins/visualization-piechart.js
+++ b/zeppelin-web/src/app/visualization/builtins/visualization-piechart.js
@@ -35,7 +35,7 @@ export default class PiechartVisualization extends Nvd3ChartVisualization {
   render(pivot) {
     // [ZEPPELIN-2253] New chart function will be created each time inside super.render()
     this.chart = null;
-    var d3Data = this.d3DataFromPivot(
+    const d3Data = this.d3DataFromPivot(
       pivot.schema,
       pivot.rows,
       pivot.keys,
@@ -44,17 +44,25 @@ export default class PiechartVisualization extends Nvd3ChartVisualization {
       true,
       false,
       false);
-    var d = d3Data.d3g;
-    var d3g = [];
-    if (d.length > 0) {
-      for (var i = 0; i < d[0].values.length ; i++) {
-        var e = d[0].values[i];
-        d3g.push({
-          label: e.x,
-          value: e.y
-        });
-      }
+    const d = d3Data.d3g;
+
+    let generateLabel;
+    // data is grouped
+    if (pivot.groups && pivot.groups.length > 0) {
+      generateLabel = (suffix, prefix) => `${prefix}.${suffix}`;
+    } else { // data isn't grouped
+      generateLabel = suffix => suffix;
     }
+
+    let d3g = d.map(group => {
+      return group.values.map(row => ({
+        label: generateLabel(row.x, group.key),
+        value: row.y
+      }));
+    });
+    // the map function returns d3g as a nested array
+    // [].concat flattens it, http://stackoverflow.com/a/10865042/5154397
+    d3g = [].concat.apply([], d3g);
     super.render({d3g: d3g});
   };