A set of minor fixes (#3014)

This commit is contained in:
Maxime Beauchemin 2017-06-21 12:09:49 -07:00 committed by GitHub
parent 5344a80535
commit 99e1de58bc
6 changed files with 31 additions and 26 deletions

View File

@ -655,6 +655,7 @@ export const controls = {
type: 'SelectControl', type: 'SelectControl',
label: 'Entity', label: 'Entity',
default: null, default: null,
validators: [v.nonEmpty],
description: 'This define the element to be plotted on the chart', description: 'This define the element to be plotted on the chart',
mapStateToProps: state => ({ mapStateToProps: state => ({
choices: (state.datasource) ? state.datasource.gb_cols : [], choices: (state.datasource) ? state.datasource.gb_cols : [],
@ -761,7 +762,9 @@ export const controls = {
type: 'SelectControl', type: 'SelectControl',
freeForm: true, freeForm: true,
label: 'Table Timestamp Format', label: 'Table Timestamp Format',
default: 'smart_date', default: '%Y-%m-%d %H:%M:%S',
validators: [v.nonEmpty],
clearable: false,
choices: D3_TIME_FORMAT_OPTIONS, choices: D3_TIME_FORMAT_OPTIONS,
description: 'Timestamp Format', description: 'Timestamp Format',
}, },

View File

@ -183,6 +183,9 @@ const visTypes = {
y_axis_format: { y_axis_format: {
label: 'Left Axis Format', label: 'Left Axis Format',
}, },
x_axis_format: {
choices: D3_TIME_FORMAT_OPTIONS,
},
}, },
}, },
@ -211,6 +214,13 @@ const visTypes = {
}, },
sections.NVD3TimeSeries[1], 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: { compare: {
@ -475,9 +485,8 @@ const visTypes = {
label: null, label: null,
controlSetRows: [ controlSetRows: [
['metric'], ['metric'],
['compare_lag'], ['compare_lag', 'compare_suffix'],
['compare_suffix'], ['y_axis_format', null],
['y_axis_format'],
], ],
}, },
], ],

View File

@ -1,6 +1,6 @@
import d3 from 'd3'; import d3 from 'd3';
import d3tip from 'd3-tip'; import d3tip from 'd3-tip';
import { formatDate } from '../javascripts/modules/dates'; import { d3FormatPreset, d3TimeFormatPreset } from '../javascripts/modules/utils';
import './big_number.css'; import './big_number.css';
import '../stylesheets/d3tip.css'; import '../stylesheets/d3tip.css';
@ -12,8 +12,9 @@ function bigNumberVis(slice, payload) {
const fd = slice.formData; const fd = slice.formData;
const json = payload.data; 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 fp = d3.format('+.1%');
const formatDate = d3TimeFormatPreset('smart_date');
const width = slice.width(); const width = slice.width();
const height = slice.height(); const height = slice.height();
const svg = div.append('svg'); const svg = div.append('svg');
@ -138,7 +139,7 @@ function bigNumberVis(slice, payload) {
const yAxis = d3.svg.axis() const yAxis = d3.svg.axis()
.scale(scaleY) .scale(scaleY)
.orient('left') .orient('left')
.tickFormat(d3.format(fd.y_axis_format)) .tickFormat(f)
.tickValues(valueExt); .tickValues(valueExt);
g.call(yAxis); g.call(yAxis);

View File

@ -331,7 +331,7 @@ function nvd3Vis(slice, payload) {
chart.x2Axis.tickFormat(xAxisFormatter); chart.x2Axis.tickFormat(xAxisFormatter);
height += 30; height += 30;
} }
if (chart.xAxis && chart.xAxis.tickFormat) { if (isTimeSeries && chart.xAxis && chart.xAxis.tickFormat) {
chart.xAxis.tickFormat(xAxisFormatter); chart.xAxis.tickFormat(xAxisFormatter);
} }

View File

@ -3,8 +3,7 @@ import 'datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.css';
import 'datatables.net'; import 'datatables.net';
import dt from 'datatables.net-bs'; import dt from 'datatables.net-bs';
import { fixDataTableBodyHeight } from '../javascripts/modules/utils'; import { fixDataTableBodyHeight, d3TimeFormatPreset } from '../javascripts/modules/utils';
import { timeFormatFactory, formatDate } from '../javascripts/modules/dates';
import './table.css'; import './table.css';
const $ = require('jquery'); const $ = require('jquery');
@ -14,7 +13,6 @@ dt(window, $);
function tableVis(slice, payload) { function tableVis(slice, payload) {
const container = $(slice.selector); const container = $(slice.selector);
const fC = d3.format('0,000'); const fC = d3.format('0,000');
let timestampFormatter;
const data = payload.data; const data = payload.data;
const fd = slice.formData; const fd = slice.formData;
@ -35,11 +33,7 @@ function tableVis(slice, payload) {
maxes[metrics[i]] = d3.max(col(metrics[i])); maxes[metrics[i]] = d3.max(col(metrics[i]));
} }
if (fd.table_timestamp_format === 'smart_date') { const tsFormatter = d3TimeFormatPreset(fd.table_timestamp_format);
timestampFormatter = formatDate;
} else if (fd.table_timestamp_format !== undefined) {
timestampFormatter = timeFormatFactory(fd.table_timestamp_format);
}
const div = d3.select(slice.selector); const div = d3.select(slice.selector);
div.html(''); div.html('');
@ -70,8 +64,8 @@ function tableVis(slice, payload) {
const val = row[c]; const val = row[c];
let html; let html;
const isMetric = metrics.indexOf(c) >= 0; const isMetric = metrics.indexOf(c) >= 0;
if (c === 'timestamp') { if (c === '__timestamp') {
html = timestampFormatter(val); html = tsFormatter(val);
} }
if (typeof (val) === 'string') { if (typeof (val) === 'string') {
html = `<span class="like-pre">${val}</span>`; html = `<span class="like-pre">${val}</span>`;

View File

@ -352,9 +352,6 @@ class TableViz(BaseViz):
columns=list(df.columns), columns=list(df.columns),
) )
def json_dumps(self, obj):
return json.dumps(obj, default=utils.json_iso_dttm_ser)
class PivotTableViz(BaseViz): class PivotTableViz(BaseViz):
@ -650,15 +647,16 @@ class BubbleViz(NVD3Viz):
def query_obj(self): def query_obj(self):
form_data = self.form_data form_data = self.form_data
d = super(BubbleViz, self).query_obj() d = super(BubbleViz, self).query_obj()
d['groupby'] = list({ d['groupby'] = [
form_data.get('series'),
form_data.get('entity') form_data.get('entity')
}) ]
if form_data.get('series'):
d['groupby'].append(form_data.get('series'))
self.x_metric = form_data.get('x') self.x_metric = form_data.get('x')
self.y_metric = form_data.get('y') self.y_metric = form_data.get('y')
self.z_metric = form_data.get('size') self.z_metric = form_data.get('size')
self.entity = form_data.get('entity') 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['row_limit'] = form_data.get('limit')
d['metrics'] = [ d['metrics'] = [
@ -666,7 +664,7 @@ class BubbleViz(NVD3Viz):
self.x_metric, self.x_metric,
self.y_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") raise Exception("Pick a metric for x, y and size")
return d return d