diff --git a/superset/assets/javascripts/explorev2/components/ControlPanelsContainer.jsx b/superset/assets/javascripts/explorev2/components/ControlPanelsContainer.jsx index 8452e377c7..fd8cfd0d06 100644 --- a/superset/assets/javascripts/explorev2/components/ControlPanelsContainer.jsx +++ b/superset/assets/javascripts/explorev2/components/ControlPanelsContainer.jsx @@ -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; } diff --git a/superset/assets/javascripts/explorev2/stores/store.js b/superset/assets/javascripts/explorev2/stores/store.js index fc07f502a7..103b7bb66f 100644 --- a/superset/assets/javascripts/explorev2/stores/store.js +++ b/superset/assets/javascripts/explorev2/stores/store.js @@ -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', }, diff --git a/superset/assets/javascripts/modules/utils.js b/superset/assets/javascripts/modules/utils.js index a4409bbe27..157aa0ea4f 100644 --- a/superset/assets/javascripts/modules/utils.js +++ b/superset/assets/javascripts/modules/utils.js @@ -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()] ); } diff --git a/superset/views.py b/superset/views.py index 05aaa76b81..475a6ca90e 100755 --- a/superset/views.py +++ b/superset/views.py @@ -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( diff --git a/tests/core_tests.py b/tests/core_tests.py index b848ba853b..82093bec44 100644 --- a/tests/core_tests.py +++ b/tests/core_tests.py @@ -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__':