superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject [incubator-superset] branch master updated: remove backend logic for wordcloud (#5753)
Date Thu, 30 Aug 2018 19:59:07 GMT
This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 9f2b502  remove backend logic for wordcloud (#5753)
9f2b502 is described below

commit 9f2b502eb6e9f9f0b67f5655ad2fbf5d06036c83
Author: Conglei <shiconglei@gmail.com>
AuthorDate: Thu Aug 30 12:59:05 2018 -0700

    remove backend logic for wordcloud (#5753)
---
 superset/assets/src/visualizations/index.js         |  2 +-
 .../{word_cloud.js => wordcloud/WordCloud.js}       | 21 +++++++++++++++++++--
 superset/viz.py                                     | 10 +---------
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/superset/assets/src/visualizations/index.js b/superset/assets/src/visualizations/index.js
index df24b67..c322bef 100644
--- a/superset/assets/src/visualizations/index.js
+++ b/superset/assets/src/visualizations/index.js
@@ -106,7 +106,7 @@ const vizMap = {
   [VIZ_TYPES.country_map]: () =>
     loadVis(import(/* webpackChunkName: "country_map" */ './country_map.js')),
   [VIZ_TYPES.word_cloud]: () =>
-    loadVis(import(/* webpackChunkName: "word_cloud" */ './word_cloud.js')),
+    loadVis(import(/* webpackChunkName: "word_cloud" */ './wordcloud/WordCloud.js')),
   [VIZ_TYPES.world_map]: () =>
     loadVis(import(/* webpackChunkName: "world_map" */ './world_map.js')),
   [VIZ_TYPES.dual_line]: loadNvd3,
diff --git a/superset/assets/src/visualizations/word_cloud.js b/superset/assets/src/visualizations/wordcloud/WordCloud.js
similarity index 87%
rename from superset/assets/src/visualizations/word_cloud.js
rename to superset/assets/src/visualizations/wordcloud/WordCloud.js
index 75d68e9..d4d2d7e 100644
--- a/superset/assets/src/visualizations/word_cloud.js
+++ b/superset/assets/src/visualizations/wordcloud/WordCloud.js
@@ -1,7 +1,7 @@
 import d3 from 'd3';
 import PropTypes from 'prop-types';
 import cloudLayout from 'd3-cloud';
-import { getColorFromScheme } from '../modules/colors';
+import { getColorFromScheme } from '../../modules/colors';
 
 const ROTATION = {
   square: () => Math.floor((Math.random() * 2)) * 90,
@@ -78,8 +78,23 @@ function wordCloud(element, props) {
 
 wordCloud.propTypes = propTypes;
 
+function transform(data, formData) {
+  const {
+    metric,
+    series,
+  } = formData;
+
+  const transformedData = data.map(datum => ({
+    text: datum[series],
+    size: datum[metric],
+  }));
+
+  return transformedData;
+}
+
 function adaptor(slice, payload) {
   const { selector, formData } = slice;
+
   const {
     rotation,
     size_to: sizeTo,
@@ -88,8 +103,10 @@ function adaptor(slice, payload) {
   } = formData;
   const element = document.querySelector(selector);
 
+  const data = transform(payload.data, formData);
+
   return wordCloud(element, {
-    data: payload.data,
+    data,
     width: slice.width(),
     height: slice.height(),
     rotation,
diff --git a/superset/viz.py b/superset/viz.py
index 19b8a66..90c209e 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -473,7 +473,7 @@ class BaseViz(object):
         return df.to_csv(index=include_index, **config.get('CSV_EXPORT'))
 
     def get_data(self, df):
-        return []
+        return self.get_df().to_dict(orient='records')
 
     @property
     def json_data(self):
@@ -730,14 +730,6 @@ class WordCloudViz(BaseViz):
         d['groupby'] = [self.form_data.get('series')]
         return d
 
-    def get_data(self, df):
-        fd = self.form_data
-        # Ordering the columns
-        df = df[[fd.get('series'), self.metric_labels[0]]]
-        # Labeling the columns for uniform json schema
-        df.columns = ['text', 'size']
-        return df.to_dict(orient='records')
-
 
 class TreemapViz(BaseViz):
 


Mime
View raw message