Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

cherry pick mapbox and annotation fix #24

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ export default class TextControl extends React.Component {
this.onChange = this.onChange.bind(this);
}
onChange(event) {
let value = event.target.value || '';
let value = event.target.value;

// Validation & casting
const errors = [];
if (this.props.isFloat) {
if (value !== '' && this.props.isFloat) {
const error = v.numeric(value);
if (error) {
errors.push(error);
} else {
value = parseFloat(value);
}
}
if (this.props.isInt) {
if (value !== '' && this.props.isInt) {
const error = v.integer(value);
if (error) {
errors.push(error);
Expand All @@ -54,7 +54,8 @@ export default class TextControl extends React.Component {
this.props.onChange(value, errors);
}
render() {
const value = this.props.value ? this.props.value.toString() : '';
const { value: rawValue } = this.props;
const value = typeof rawValue !== 'undefined' && rawValue !== null ? rawValue.toString() : '';
return (
<div>
<ControlHeader {...this.props} />
Expand Down
4 changes: 2 additions & 2 deletions superset/assets/visualizations/mapbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ScatterPlotGlowOverlay extends React.Component {
const canvas = this.refs.overlay;
const ctx = canvas.getContext('2d');
const radius = props.dotRadius;
const mercator = ViewportMercator(props);
const mercator = new ViewportMercator(props);
const rgb = props.rgb;
const clusterLabelMap = [];
let maxLabel = -1;
Expand Down Expand Up @@ -264,7 +264,7 @@ class MapboxViz extends React.Component {
}

render() {
const mercator = ViewportMercator({
const mercator = new ViewportMercator({
width: this.props.sliceWidth,
height: this.props.sliceHeight,
longitude: this.state.viewport.longitude,
Expand Down
52 changes: 41 additions & 11 deletions superset/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ function nvd3Vis(slice, payload) {
// on scroll, hide tooltips. throttle to only 4x/second.
$(window).scroll(throttle(hideTooltips, 250));

const annotationLayers = (slice.formData.annotation_layers || [])
.filter(x => x.show);
const annotationLayers = (slice.formData.annotation_layers || []).filter(x => x.show);

if (isTimeSeries && annotationLayers) {
// Formula annotations
const formulas = annotationLayers.filter(a => a.annotationType === AnnotationTypes.FORMULA)
Expand Down Expand Up @@ -629,13 +629,27 @@ function nvd3Vis(slice, payload) {

const tip = tipFactory(e);
const records = (slice.annotationData[e.name].records || []).map((r) => {
const timeColumn = new Date(moment.utc(r[e.timeColumn]));
const timeValue = new Date(moment.utc(r[e.timeColumn]));

return {
...r,
[e.timeColumn]: timeColumn,
[e.timeColumn]: timeValue,
};
}).filter(r => !Number.isNaN(r[e.timeColumn].getMilliseconds()));
}).filter(record => !Number.isNaN(record[e.timeColumn].getMilliseconds()));

// account for the annotation in the x domain
records.forEach((record) => {
const timeValue = record[e.timeColumn];

xMin = Math.min(...[xMin, timeValue]);
xMax = Math.max(...[xMax, timeValue]);
});

if (records.length) {
const domain = [xMin, xMax];
xScale.domain(domain);
chart.xDomain(domain);

annotations.selectAll('line')
.data(records)
.enter()
Expand Down Expand Up @@ -670,16 +684,32 @@ function nvd3Vis(slice, payload) {
const tip = tipFactory(e);

const records = (slice.annotationData[e.name].records || []).map((r) => {
const timeColumn = new Date(r[e.timeColumn]);
const intervalEndColumn = new Date(r[e.intervalEndColumn]);
const timeValue = new Date(r[e.timeColumn]);
const intervalEndValue = new Date(r[e.intervalEndColumn]);
return {
...r,
[e.timeColumn]: timeColumn,
[e.intervalEndColumn]: intervalEndColumn,
[e.timeColumn]: timeValue,
[e.intervalEndColumn]: intervalEndValue,
};
}).filter(r => !Number.isNaN(r[e.timeColumn].getMilliseconds()) &&
!Number.isNaN(r[e.intervalEndColumn].getMilliseconds()));
}).filter(record => (
!Number.isNaN(record[e.timeColumn].getMilliseconds()) &&
!Number.isNaN(record[e.intervalEndColumn].getMilliseconds())
));

// account for the annotation in the x domain
records.forEach((record) => {
const timeValue = record[e.timeColumn];
const intervalEndValue = record[e.intervalEndColumn];

xMin = Math.min(...[xMin, timeValue, intervalEndValue]);
xMax = Math.max(...[xMax, timeValue, intervalEndValue]);
});

if (records.length) {
const domain = [xMin, xMax];
xScale.domain(domain);
chart.xDomain(domain);

annotations.selectAll('rect')
.data(records)
.enter()
Expand Down
9 changes: 5 additions & 4 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ def get_form_data(self, slice_id=None):
# the form_data from the DB with the other form_data provided
slice_id = form_data.get('slice_id') or slice_id
slc = None

if slice_id:
slc = db.session.query(models.Slice).filter_by(id=slice_id).first()
slice_form_data = slc.form_data.copy()
Expand Down Expand Up @@ -1110,10 +1111,10 @@ def generate_json(self, datasource_type, datasource_id, form_data,
@expose('/slice_json/<slice_id>')
def slice_json(self, slice_id):
try:
viz_obj = self.get_viz(slice_id)
datasource_type = viz_obj.datasource.type
datasource_id = viz_obj.datasource.id
form_data, slc = self.get_form_data()
form_data, slc = self.get_form_data(slice_id)
datasource_type = slc.datasource.type
datasource_id = slc.datasource.id

except Exception as e:
return json_error_response(
utils.error_msg_from_exception(e),
Expand Down