Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIP-6] Refactor WordCloud #5753

Merged
merged 1 commit into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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):
Expand Down Expand Up @@ -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):

Expand Down