Skip to content

Commit

Permalink
Merge branch 'master' into refactor_imoprt_csv
Browse files Browse the repository at this point in the history
  • Loading branch information
timifasubaa committed Jan 26, 2018
2 parents 509b9a2 + b9299d6 commit 6c43b4c
Show file tree
Hide file tree
Showing 28 changed files with 319 additions and 109 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_git_sha():
'flask-sqlalchemy==2.1',
'flask-testing==0.6.2',
'flask-wtf==0.14.2',
'flower==0.9.1',
'flower==0.9.2',
'future>=0.16.0, <0.17',
'python-geohash==0.8.5',
'humanize==0.5.1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function mapStateToProps(state) {
return {
datasource: state.datasource,
errorMessage: state.errorMessage,
timeout: state.common ? state.common.SUPERSET_WEBSERVER_TIMEOUT : null,
timeout: state.common ? state.common.conf.SUPERSET_WEBSERVER_TIMEOUT : null,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ export default class DateFilterControl extends React.Component {
setType(type) {
this.setState({ type });
}
setValue(val) {
this.setState({ type: 'free', free: val });
this.close();
setValueAndClose(val) {
this.setState({ type: 'free', free: val }, this.close);
}
setDatetime(dttm) {
this.setState({ dttm: dttm.format().substring(0, 19) });
Expand Down Expand Up @@ -175,13 +174,15 @@ export default class DateFilterControl extends React.Component {
>
<Button
bsSize="small"
onClick={this.setValue.bind(this, 'now')}
className="now"
onClick={this.setValueAndClose.bind(this, 'now')}
>
now
</Button>
<Button
bsSize="small"
onClick={this.setValue.bind(this, '')}
className="clear"
onClick={this.setValueAndClose.bind(this, '')}
>
clear
</Button>
Expand Down
12 changes: 7 additions & 5 deletions superset/assets/javascripts/explore/stores/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ export const controls = {
type: 'CheckboxControl',
label: t('Range Filter'),
renderTrigger: true,
default: true,
default: false,
description: t('Whether to display the time range interactive selector'),
},

Expand Down Expand Up @@ -1486,6 +1486,7 @@ export const controls = {
point_radius_fixed: {
type: 'FixedOrMetricControl',
label: t('Point Size'),
default: { type: 'fix', value: 1000 },
description: t('Fixed point radius'),
mapStateToProps: state => ({
datasource: state.datasource,
Expand Down Expand Up @@ -1881,10 +1882,11 @@ export const controls = {
},
},

js_datapoint_mutator: jsFunctionControl(
t('Javascript data point mutator'),
t('Define a javascript function that receives each data point and can alter it ' +
'before getting sent to the deck.gl layer'),
js_data_mutator: jsFunctionControl(
t('Javascript data interceptor'),
t('Define a javascript function that receives the data array used in the visualization ' +
'and is expected to return a modified version of that array. This can be used ' +
'to alter properties of the data, filter, or enrich the array.'),
),

js_data: jsFunctionControl(
Expand Down
44 changes: 40 additions & 4 deletions superset/assets/javascripts/explore/stores/visTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,15 @@ export const visTypes = {
['grid_size', 'extruded'],
],
},
{
label: t('Advanced'),
controlSetRows: [
['js_columns'],
['js_data_mutator'],
['js_tooltip'],
['js_onclick_href'],
],
},
],
controlOverrides: {
size: {
Expand Down Expand Up @@ -402,6 +411,15 @@ export const visTypes = {
['grid_size', 'extruded'],
],
},
{
label: t('Advanced'),
controlSetRows: [
['js_columns'],
['js_data_mutator'],
['js_tooltip'],
['js_onclick_href'],
],
},
],
controlOverrides: {
size: {
Expand Down Expand Up @@ -437,7 +455,7 @@ export const visTypes = {
label: t('Advanced'),
controlSetRows: [
['js_columns'],
['js_datapoint_mutator'],
['js_data_mutator'],
['js_tooltip'],
['js_onclick_href'],
],
Expand Down Expand Up @@ -469,6 +487,15 @@ export const visTypes = {
['grid_size', 'color_picker'],
],
},
{
label: t('Advanced'),
controlSetRows: [
['js_columns'],
['js_data_mutator'],
['js_tooltip'],
['js_onclick_href'],
],
},
],
controlOverrides: {
size: {
Expand Down Expand Up @@ -509,7 +536,7 @@ export const visTypes = {
label: t('Advanced'),
controlSetRows: [
['js_columns'],
['js_datapoint_mutator'],
['js_data_mutator'],
['js_tooltip'],
['js_onclick_href'],
],
Expand Down Expand Up @@ -549,7 +576,7 @@ export const visTypes = {
label: t('Advanced'),
controlSetRows: [
['js_columns'],
['js_datapoint_mutator'],
['js_data_mutator'],
['js_tooltip'],
['js_onclick_href'],
],
Expand Down Expand Up @@ -582,6 +609,15 @@ export const visTypes = {
['stroke_width', null],
],
},
{
label: t('Advanced'),
controlSetRows: [
['js_columns'],
['js_data_mutator'],
['js_tooltip'],
['js_onclick_href'],
],
},
],
},

Expand Down Expand Up @@ -621,7 +657,7 @@ export const visTypes = {
label: t('Advanced'),
controlSetRows: [
['js_columns'],
['js_datapoint_mutator'],
['js_data_mutator'],
['js_tooltip'],
['js_onclick_href'],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ describe('DateFilterControl', () => {
expect(wrapper.state().num).to.equal('90');
}, 10);
});
it('sets now and closes', () => {
const label = wrapper.find('.now').first();
label.simulate('click');
setTimeout(() => {
expect(wrapper.state().free).to.equal('now');
expect(wrapper.find('.popover')).to.have.length(0);
}, 10);
});
it('renders 2 dimmed sections', () => {
const label = wrapper.find('.label').first();
label.simulate('click');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('VisualizeModal', () => {
const mockStore = configureStore(middlewares);
const initialState = sqlLabReducer({}, {});
initialState.common = {
SUPERSET_WEBSERVER_TIMEOUT: 45,
conf: { SUPERSET_WEBSERVER_TIMEOUT: 45 },
};
const store = mockStore(initialState);
const mockedProps = {
Expand Down
6 changes: 6 additions & 0 deletions superset/assets/visualizations/cal_heatmap.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.cal_heatmap .slice_container {
padding: 10px;
position: static !important;
}

.cal_heatmap .slice_container .ch-tooltip {
margin-left: 20px;
margin-top: 5px;
}
14 changes: 12 additions & 2 deletions superset/assets/visualizations/deckgl/layers/arc.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { ArcLayer } from 'deck.gl';

export default function arcLayer(formData, payload) {
import * as common from './common';
import sandboxedEval from '../../../javascripts/modules/sandbox';

export default function arcLayer(formData, payload, slice) {
const fd = formData;
const fc = fd.color_picker;
const data = payload.data.arcs.map(d => ({
let data = payload.data.arcs.map(d => ({
...d,
color: [fc.r, fc.g, fc.b, 255 * fc.a],
}));

if (fd.js_data_mutator) {
// Applying user defined data mutator if defined
const jsFnMutator = sandboxedEval(fd.js_data_mutator);
data = jsFnMutator(data);
}

return new ArcLayer({
id: `path-layer-${fd.slice_id}`,
data,
strokeWidth: (fd.stroke_width) ? fd.stroke_width : 3,
...common.commonLayerProps(fd, slice),
});
}
17 changes: 8 additions & 9 deletions superset/assets/visualizations/deckgl/layers/geojson.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,17 @@ const alterProps = (props, propOverrides) => {
};
};
let features;
const recurseGeoJson = (node, propOverrides, jsFnMutator, extraProps) => {
const recurseGeoJson = (node, propOverrides, extraProps) => {
if (node && node.features) {
node.features.forEach((obj) => {
recurseGeoJson(obj, propOverrides, jsFnMutator, node.extraProps || extraProps);
recurseGeoJson(obj, propOverrides, node.extraProps || extraProps);
});
}
if (node && node.geometry) {
const newNode = {
...node,
properties: alterProps(node.properties, propOverrides),
};
if (jsFnMutator) {
jsFnMutator(newNode);
}
if (!newNode.extraProps) {
newNode.extraProps = extraProps;
}
Expand All @@ -70,14 +67,16 @@ export default function geoJsonLayer(formData, payload, slice) {
propOverrides.strokeColor = strokeColor;
}

features = [];
recurseGeoJson(payload.data, propOverrides);

let jsFnMutator;
if (fd.js_datapoint_mutator) {
if (fd.js_data_mutator) {
// Applying user defined data mutator if defined
jsFnMutator = sandboxedEval(fd.js_datapoint_mutator);
jsFnMutator = sandboxedEval(fd.js_data_mutator);
features = jsFnMutator(features);
}

features = [];
recurseGeoJson(payload.data, propOverrides, jsFnMutator);
return new GeoJsonLayer({
id: `geojson-layer-${fd.slice_id}`,
filled: fd.filled,
Expand Down
15 changes: 13 additions & 2 deletions superset/assets/visualizations/deckgl/layers/grid.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { GridLayer } from 'deck.gl';

export default function getLayer(formData, payload) {
import * as common from './common';
import sandboxedEval from '../../../javascripts/modules/sandbox';

export default function getLayer(formData, payload, slice) {
const fd = formData;
const c = fd.color_picker;
const data = payload.data.features.map(d => ({
let data = payload.data.features.map(d => ({
...d,
color: [c.r, c.g, c.b, 255 * c.a],
}));

if (fd.js_data_mutator) {
// Applying user defined data mutator if defined
const jsFnMutator = sandboxedEval(fd.js_data_mutator);
data = jsFnMutator(data);
}

return new GridLayer({
id: `grid-layer-${fd.slice_id}`,
data,
Expand All @@ -18,5 +28,6 @@ export default function getLayer(formData, payload) {
outline: false,
getElevationValue: points => points.reduce((sum, point) => sum + point.weight, 0),
getColorValue: points => points.reduce((sum, point) => sum + point.weight, 0),
...common.commonLayerProps(fd, slice),
});
}
14 changes: 12 additions & 2 deletions superset/assets/visualizations/deckgl/layers/hex.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { HexagonLayer } from 'deck.gl';

export default function getLayer(formData, payload) {
import * as common from './common';
import sandboxedEval from '../../../javascripts/modules/sandbox';

export default function getLayer(formData, payload, slice) {
const fd = formData;
const c = fd.color_picker;
const data = payload.data.features.map(d => ({
let data = payload.data.features.map(d => ({
...d,
color: [c.r, c.g, c.b, 255 * c.a],
}));

if (fd.js_data_mutator) {
// Applying user defined data mutator if defined
const jsFnMutator = sandboxedEval(fd.js_data_mutator);
data = jsFnMutator(data);
}

return new HexagonLayer({
id: `hex-layer-${fd.slice_id}`,
data,
Expand All @@ -19,5 +28,6 @@ export default function getLayer(formData, payload) {
outline: false,
getElevationValue: points => points.reduce((sum, point) => sum + point.weight, 0),
getColorValue: points => points.reduce((sum, point) => sum + point.weight, 0),
...common.commonLayerProps(fd, slice),
});
}
6 changes: 3 additions & 3 deletions superset/assets/visualizations/deckgl/layers/path.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export default function getLayer(formData, payload, slice) {
color: fixedColor,
}));

if (fd.js_datapoint_mutator) {
const jsFnMutator = sandboxedEval(fd.js_datapoint_mutator);
data = data.map(jsFnMutator);
if (fd.js_data_mutator) {
const jsFnMutator = sandboxedEval(fd.js_data_mutator);
data = jsFnMutator(data);
}

return new PathLayer({
Expand Down
6 changes: 3 additions & 3 deletions superset/assets/visualizations/deckgl/layers/polygon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export default function polygonLayer(formData, payload, slice) {
fillColor: [fc.r, fc.g, fc.b, 255 * fc.a],
}));

if (fd.js_datapoint_mutator) {
if (fd.js_data_mutator) {
// Applying user defined data mutator if defined
const jsFnMutator = sandboxedEval(fd.js_datapoint_mutator);
data = data.map(jsFnMutator);
const jsFnMutator = sandboxedEval(fd.js_data_mutator);
data = jsFnMutator(data);
}

return new PolygonLayer({
Expand Down
6 changes: 3 additions & 3 deletions superset/assets/visualizations/deckgl/layers/scatter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export default function getLayer(formData, payload, slice) {
};
});

if (fd.js_datapoint_mutator) {
if (fd.js_data_mutator) {
// Applying user defined data mutator if defined
const jsFnMutator = sandboxedEval(fd.js_datapoint_mutator);
data = data.map(jsFnMutator);
const jsFnMutator = sandboxedEval(fd.js_data_mutator);
data = jsFnMutator(data);
}

return new ScatterplotLayer({
Expand Down
Loading

0 comments on commit 6c43b4c

Please sign in to comment.