Skip to content

Commit

Permalink
A set of minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Jun 21, 2017
1 parent 593861e commit 5144b16
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 26 deletions.
5 changes: 4 additions & 1 deletion superset/assets/javascripts/explore/stores/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ export const controls = {
type: 'SelectControl',
label: 'Entity',
default: null,
validators: [v.nonEmpty],
description: 'This define the element to be plotted on the chart',
mapStateToProps: state => ({
choices: (state.datasource) ? state.datasource.gb_cols : [],
Expand Down Expand Up @@ -761,7 +762,9 @@ export const controls = {
type: 'SelectControl',
freeForm: true,
label: 'Table Timestamp Format',
default: 'smart_date',
default: '%Y-%m-%d %H:%M:%S',
validators: [v.nonEmpty],
clearable: false,
choices: D3_TIME_FORMAT_OPTIONS,
description: 'Timestamp Format',
},
Expand Down
15 changes: 12 additions & 3 deletions superset/assets/javascripts/explore/stores/visTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ const visTypes = {
y_axis_format: {
label: 'Left Axis Format',
},
x_axis_format: {
choices: D3_TIME_FORMAT_OPTIONS,
},
},
},

Expand Down Expand Up @@ -211,6 +214,13 @@ const visTypes = {
},
sections.NVD3TimeSeries[1],
],
controlOverrides: {
x_axis_format: {
choices: D3_TIME_FORMAT_OPTIONS,
default: control =>
control.choices && control.choices.length > 0 ? [control.choices[0][0]] : null,
},
},
},

compare: {
Expand Down Expand Up @@ -475,9 +485,8 @@ const visTypes = {
label: null,
controlSetRows: [
['metric'],
['compare_lag'],
['compare_suffix'],
['y_axis_format'],
['compare_lag', 'compare_suffix'],
['y_axis_format', null],
],
},
],
Expand Down
7 changes: 4 additions & 3 deletions superset/assets/visualizations/big_number.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import d3 from 'd3';
import d3tip from 'd3-tip';
import { formatDate } from '../javascripts/modules/dates';
import { d3FormatPreset, d3TimeFormatPreset } from '../javascripts/modules/utils';

import './big_number.css';
import '../stylesheets/d3tip.css';
Expand All @@ -12,8 +12,9 @@ function bigNumberVis(slice, payload) {
const fd = slice.formData;
const json = payload.data;

const f = d3.format(fd.y_axis_format);
const f = d3FormatPreset(fd.y_axis_format);
const fp = d3.format('+.1%');
const formatDate = d3TimeFormatPreset('smart_date');
const width = slice.width();
const height = slice.height();
const svg = div.append('svg');
Expand Down Expand Up @@ -138,7 +139,7 @@ function bigNumberVis(slice, payload) {
const yAxis = d3.svg.axis()
.scale(scaleY)
.orient('left')
.tickFormat(d3.format(fd.y_axis_format))
.tickFormat(f)
.tickValues(valueExt);

g.call(yAxis);
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function nvd3Vis(slice, payload) {
chart.x2Axis.tickFormat(xAxisFormatter);
height += 30;
}
if (chart.xAxis && chart.xAxis.tickFormat) {
if (isTimeSeries && chart.xAxis && chart.xAxis.tickFormat) {
chart.xAxis.tickFormat(xAxisFormatter);
}

Expand Down
14 changes: 4 additions & 10 deletions superset/assets/visualizations/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import 'datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.css';
import 'datatables.net';
import dt from 'datatables.net-bs';

import { fixDataTableBodyHeight } from '../javascripts/modules/utils';
import { timeFormatFactory, formatDate } from '../javascripts/modules/dates';
import { fixDataTableBodyHeight, d3TimeFormatPreset } from '../javascripts/modules/utils';
import './table.css';

const $ = require('jquery');
Expand All @@ -14,7 +13,6 @@ dt(window, $);
function tableVis(slice, payload) {
const container = $(slice.selector);
const fC = d3.format('0,000');
let timestampFormatter;

const data = payload.data;
const fd = slice.formData;
Expand All @@ -35,11 +33,7 @@ function tableVis(slice, payload) {
maxes[metrics[i]] = d3.max(col(metrics[i]));
}

if (fd.table_timestamp_format === 'smart_date') {
timestampFormatter = formatDate;
} else if (fd.table_timestamp_format !== undefined) {
timestampFormatter = timeFormatFactory(fd.table_timestamp_format);
}
const tsFormatter = d3TimeFormatPreset(fd.table_timestamp_format);

const div = d3.select(slice.selector);
div.html('');
Expand Down Expand Up @@ -70,8 +64,8 @@ function tableVis(slice, payload) {
const val = row[c];
let html;
const isMetric = metrics.indexOf(c) >= 0;
if (c === 'timestamp') {
html = timestampFormatter(val);
if (c === '__timestamp') {
html = tsFormatter(val);
}
if (typeof (val) === 'string') {
html = `<span class="like-pre">${val}</span>`;
Expand Down
14 changes: 6 additions & 8 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,6 @@ def get_data(self, df):
columns=list(df.columns),
)

def json_dumps(self, obj):
return json.dumps(obj, default=utils.json_iso_dttm_ser)


class PivotTableViz(BaseViz):

Expand Down Expand Up @@ -650,23 +647,24 @@ class BubbleViz(NVD3Viz):
def query_obj(self):
form_data = self.form_data
d = super(BubbleViz, self).query_obj()
d['groupby'] = list({
form_data.get('series'),
d['groupby'] = [
form_data.get('entity')
})
]
if form_data.get('series'):
d['groupby'].append(form_data.get('series'))
self.x_metric = form_data.get('x')
self.y_metric = form_data.get('y')
self.z_metric = form_data.get('size')
self.entity = form_data.get('entity')
self.series = form_data.get('series')
self.series = form_data.get('series') or self.entity
d['row_limit'] = form_data.get('limit')

d['metrics'] = [
self.z_metric,
self.x_metric,
self.y_metric,
]
if not all(d['metrics'] + [self.entity, self.series]):
if not all(d['metrics'] + [self.entity]):
raise Exception("Pick a metric for x, y and size")
return d

Expand Down

0 comments on commit 5144b16

Please sign in to comment.