You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/08/30 19:59:06 UTC

[GitHub] hughhhh closed pull request #5753: [SIP-6] Refactor WordCloud

hughhhh closed pull request #5753: [SIP-6] Refactor WordCloud
URL: https://github.com/apache/incubator-superset/pull/5753
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/assets/src/visualizations/index.js b/superset/assets/src/visualizations/index.js
index df24b67158..c322bef528 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 75d68e9c60..d4d2d7e3b4 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 5f4cea8498..c456925819 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -468,7 +468,7 @@ def get_csv(self):
         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):
@@ -725,14 +725,6 @@ def query_obj(self):
         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):
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org