Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1DB39200C38 for ; Wed, 15 Mar 2017 16:42:18 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 1C3A5160B72; Wed, 15 Mar 2017 15:42:18 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5CCA8160B70 for ; Wed, 15 Mar 2017 16:42:17 +0100 (CET) Received: (qmail 14454 invoked by uid 500); 15 Mar 2017 15:42:16 -0000 Mailing-List: contact commits-help@zeppelin.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zeppelin.apache.org Delivered-To: mailing list commits@zeppelin.apache.org Received: (qmail 14404 invoked by uid 99); 15 Mar 2017 15:42:16 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Mar 2017 15:42:16 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9C5A5DFB7D; Wed, 15 Mar 2017 15:42:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: moon@apache.org To: commits@zeppelin.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: zeppelin git commit: [WIP] [Discuss] Make use of all grouped data to draw pie chart Date: Wed, 15 Mar 2017 15:42:15 +0000 (UTC) archived-at: Wed, 15 Mar 2017 15:42:18 -0000 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 This patch had conflicts when merged, resolved by Committer: Lee moon soo 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 Authored: Fri Mar 10 09:19:55 2017 +0530 Committer: Lee moon soo 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}); };