Skip to content

Commit

Permalink
remove backend logic for wordcloud (apache#5753)
Browse files Browse the repository at this point in the history
  • Loading branch information
conglei authored and betodealmeida committed Oct 12, 2018
1 parent d97736c commit 6d1e0f2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion superset/assets/src/visualizations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 1 addition & 9 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,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):
Expand Down Expand Up @@ -730,14 +730,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):

Expand Down

0 comments on commit 6d1e0f2

Please sign in to comment.