Skip to content

Commit

Permalink
Fixed bugs with viz in exploreV2 (#1609)
Browse files Browse the repository at this point in the history
* Fixed bugs with viz in exploreV2

Done:
 - fix typo in pie viz
 - add metrics/groupby to dist_bar viz
 - fix typo in heatmap viz
 - add big_number_total to viz
 - fixed problem with fetching columns for datasource
 - add sqlaTimeSeries to viz
 - change row_limit and limit from number to strings so that we
 don't need to parse integers in bootstrap data

* Fix python tests

* Added order_bars checkbox for dist_bar viz
  • Loading branch information
vera-liu authored Nov 17, 2016
1 parent bce02e3 commit d5ef937
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ class ControlPanelsContainer extends React.Component {

sectionsToRender() {
const viz = visTypes[this.props.form_data.viz_type];
const timeSection = this.props.datasource_type === 'table' ?
commonControlPanelSections.sqlaTimeSeries : commonControlPanelSections.druidTimeSeries;
const { datasourceAndVizType, sqlClause } = commonControlPanelSections;
const sectionsToRender = [datasourceAndVizType].concat(viz.controlPanelSections, sqlClause);

const sectionsToRender = [datasourceAndVizType].concat(
viz.controlPanelSections, timeSection, sqlClause);
return sectionsToRender;
}

Expand Down
43 changes: 36 additions & 7 deletions superset/assets/javascripts/explorev2/stores/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ export const visTypes = {
label: 'Chart Options',
description: 'tooltip text here',
fieldSetRows: [
['metrics'],
['groupby'],
['columns'],
['row_limit'],
['show_legend', 'show_bar_value', 'bar_stacked'],
['show_legend', 'show_bar_value'],
['bar_stacked', 'order_bars'],
['y_axis_format', 'bottom_margin'],
['x_axis_label', 'y_axis_label'],
['reduce_x_ticks', 'contribution'],
Expand All @@ -140,7 +143,7 @@ export const visTypes = {
controlPanelSections: [
{
label: null,
fields: [
fieldSetRows: [
['metrics', 'groupby'],
['limit'],
['pie_label_type'],
Expand Down Expand Up @@ -409,6 +412,24 @@ export const visTypes = {
},
},

big_number_total: {
controlPanelSections: [
{
label: null,
fieldSetRows: [
['metric'],
['subheader'],
['y_axis_format'],
],
},
],
fieldOverrides: {
y_axis_format: {
label: 'Number format',
},
},
},

histogram: {
label: 'Histogram',
controlPanelSections: [
Expand Down Expand Up @@ -811,7 +832,7 @@ export const fields = {
'defines how the browser scales up the image',
},

x_scale_interval: {
xscale_interval: {
type: 'SelectField',
label: 'XScale Interval',
choices: formatSelectOptionsForRange(1, 50),
Expand All @@ -820,7 +841,7 @@ export const fields = {
'displaying the X scale',
},

y_scale_interval: {
yscale_interval: {
type: 'SelectField',
label: 'YScale Interval',
choices: formatSelectOptionsForRange(1, 50),
Expand Down Expand Up @@ -850,6 +871,13 @@ export const fields = {
description: 'Show the value on top of the bar',
},

order_bars: {
type: 'CheckboxField',
label: 'Sort Bars',
default: false,
description: 'Sort bars by x labels.',
},

show_controls: {
type: 'CheckboxField',
label: 'Extra Controls',
Expand Down Expand Up @@ -1036,7 +1064,8 @@ export const fields = {
'expression',
},

time_grain: {
time_grain_sqla: {
type: 'SelectField',
label: 'Time Grain',
choices: [],
default: 'Time Column',
Expand Down Expand Up @@ -1281,8 +1310,8 @@ export const fields = {
series_height: {
type: 'FreeFormSelectField',
label: 'Series Height',
default: 25,
choices: formatSelectOptions([10, 25, 40, 50, 75, 100, 150, 200]),
default: '25',
choices: formatSelectOptions(['10', '25', '40', '50', '75', '100', '150', '200']),
description: 'Pixel height of each series',
},

Expand Down
4 changes: 2 additions & 2 deletions superset/assets/javascripts/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ export function formatSelectOptionsForRange(start, end) {
// returns [[1,1], [2,2], [3,3], [4,4], [5,5]]
const options = [];
for (let i = start; i <= end; i++) {
options.push([i, i]);
options.push([i.toString(), i.toString()]);
}
return options;
}

export function formatSelectOptions(options) {
return options.map((opt) =>
[opt, opt]
[opt.toString(), opt.toString()]
);
}

Expand Down
19 changes: 12 additions & 7 deletions superset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2152,11 +2152,15 @@ def fetch_datasource_metadata(self):
return json_error_response(DATASOURCE_ACCESS_ERR)

gb_cols = [(col, col) for col in datasource.groupby_column_names]
all_cols = [(c, c) for c in datasource.column_names]
order_by_choices = []
for s in sorted(datasource.column_names):
order_by_choices.append((json.dumps([s, True]), s + ' [asc]'))
order_by_choices.append((json.dumps([s, False]), s + ' [desc]'))

grains = datasource.database.grains()
grain_choices = []
if grains:
grain_choices = [(grain.name, grain.name) for grain in grains]
field_options = {
'datasource': [(d.id, d.full_name) for d in datasources],
'metrics': datasource.metrics_combo,
Expand All @@ -2165,18 +2169,19 @@ def fetch_datasource_metadata(self):
'secondary_metric': datasource.metrics_combo,
'groupby': gb_cols,
'columns': gb_cols,
'all_columns': datasource.column_names,
'all_columns_x': datasource.column_names,
'all_columns_y': datasource.column_names,
'granularity_sqla': datasource.dttm_cols,
'all_columns': all_cols,
'all_columns_x': all_cols,
'all_columns_y': all_cols,
'granularity_sqla': [(c, c) for c in datasource.dttm_cols],
'time_grain_sqla': grain_choices,
'timeseries_limit_metric': [('', '')] + datasource.metrics_combo,
'series': gb_cols,
'entity': gb_cols,
'x': datasource.metrics_combo,
'y': datasource.metrics_combo,
'size': datasource.metrics_combo,
'mapbox_label': datasource.column_names,
'point_radius': ["Auto"] + datasource.column_names,
'mapbox_label': all_cols,
'point_radius': [(c, c) for c in (["Auto"] + datasource.column_names)],
}

return Response(
Expand Down
2 changes: 1 addition & 1 deletion tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def test_fetch_datasource_metadata(self):
self.login(username='admin')
url = '/superset/fetch_datasource_metadata?datasource_type=table&datasource_id=1';
resp = json.loads(self.get_resp(url))
self.assertEqual(len(resp['field_options']), 19)
self.assertEqual(len(resp['field_options']), 20)


if __name__ == '__main__':
Expand Down

0 comments on commit d5ef937

Please sign in to comment.