Fixed bugs with viz in exploreV2 (#1609)

* 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
This commit is contained in:
vera-liu 2016-11-17 12:31:36 -08:00 committed by GitHub
parent bce02e3f51
commit d5ef937b31
5 changed files with 55 additions and 19 deletions

View File

@ -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;
}

View File

@ -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'],
@ -140,7 +143,7 @@ export const visTypes = {
controlPanelSections: [
{
label: null,
fields: [
fieldSetRows: [
['metrics', 'groupby'],
['limit'],
['pie_label_type'],
@ -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: [
@ -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),
@ -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),
@ -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',
@ -1036,7 +1064,8 @@ export const fields = {
'expression',
},
time_grain: {
time_grain_sqla: {
type: 'SelectField',
label: 'Time Grain',
choices: [],
default: 'Time Column',
@ -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',
},

View File

@ -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()]
);
}

View File

@ -2152,11 +2152,15 @@ class Superset(BaseSupersetView):
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,
@ -2165,18 +2169,19 @@ class Superset(BaseSupersetView):
'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(

View File

@ -429,7 +429,7 @@ class CoreTests(SupersetTestCase):
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__':