Skip to content

Commit

Permalink
[WiP] Integrate Kepler.gl as a new visualization type
Browse files Browse the repository at this point in the history
Kepler.gl is an amazing geospatial React application. It offers a very
well designed user interface to compose geo layers and slice and dice
geospatial data.

As it turns out, Kepler is designed to be embedded as part of React
apps. It took me only a few hours to get to a working prototype.

Next steps:
* allow to save the state, without the data
* restore the state, and merge with the new data
* tweak styles, make a light style that looks decent within Superste,
  Kepler uses stylable components, so that should be somewhat
  straigthforward

(cherry picked from commit 43ed9a6)
(cherry picked from commit 595832a)
(cherry picked from commit 1fa1d05)
(cherry picked from commit 791776e)
(cherry picked from commit 568afd4)
  • Loading branch information
mistercrunch authored and xtinec committed Mar 29, 2019
1 parent a457b47 commit 472564b
Show file tree
Hide file tree
Showing 14 changed files with 8,685 additions and 7,033 deletions.
15,339 changes: 8,369 additions & 6,970 deletions superset/assets/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion superset/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@
"d3-color": "^1.2.0",
"d3-scale": "^2.1.2",
"d3-selection": "^1.3.2",
"deck.gl": "^5.3.5",
"deck.gl": "^5.3.4",
"dnd-core": "^2.6.0",
"dompurify": "^1.0.3",
"geolib": "^2.0.24",
"immutable": "^3.8.2",
"jquery": "3.1.1",
"json-bigint": "^0.3.0",
"kepler.gl": "0.1.6",
"lodash": "^4.17.11",
"mapbox-gl": "^0.53.0",
"mathjs": "^3.20.2",
Expand Down
62 changes: 0 additions & 62 deletions superset/assets/src/dashboard/components/BuilderComponentPane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ import InsertComponentPane, {
} from './InsertComponentPane';
import ColorComponentPane from './ColorComponentPane';
import { BUILDER_PANE_TYPE } from '../util/constants';
import NewColumn from './gridComponents/new/NewColumn';
import NewDivider from './gridComponents/new/NewDivider';
import NewHeader from './gridComponents/new/NewHeader';
import NewRow from './gridComponents/new/NewRow';
import NewTabs from './gridComponents/new/NewTabs';
import NewTags from './gridComponents/new/NewTags';
import NewMarkdown from './gridComponents/new/NewMarkdown';
import SliceAdder from '../containers/SliceAdder';

const propTypes = {
topOffset: PropTypes.number,
Expand Down Expand Up @@ -74,7 +66,6 @@ class BuilderComponentPane extends React.PureComponent {
className="viewport"
style={isSticky ? { ...style, top: topOffset } : null}
>
<<<<<<< HEAD
{builderPaneType === BUILDER_PANE_TYPE.ADD_COMPONENTS && (
<InsertComponentPane
height={height}
Expand All @@ -91,59 +82,6 @@ class BuilderComponentPane extends React.PureComponent {
colorScheme={colorScheme}
/>
)}
=======
<div
className={cx(
'slider-container',
this.state.slideDirection,
)}
>
<div className="component-layer slide-content">
<div className="dashboard-builder-sidepane-header">
<span>{t('Insert components')}</span>
<i
className="fa fa-times trigger"
onClick={this.props.toggleBuilderPane}
role="none"
/>
</div>
<div
className="new-component static"
role="none"
onClick={this.openSlicesPane}
>
<div className="new-component-placeholder fa fa-area-chart" />
<div className="new-component-label">
{t('Your charts & filters')}
</div>

<i className="fa fa-arrow-right trigger" />
</div>
<NewTabs />
<NewRow />
<NewColumn />
<NewHeader />
<NewMarkdown />
<NewDivider />
<NewTags />
</div>
<div className="slices-layer slide-content">
<div
className="dashboard-builder-sidepane-header"
onClick={this.closeSlicesPane}
role="none"
>
<i className="fa fa-arrow-left trigger" />
<span>{t('Your charts and filters')}</span>
</div>
<SliceAdder
height={
height + (isSticky ? SUPERSET_HEADER_HEIGHT : 0)
}
/>
</div>
</div>
>>>>>>> e3a562176... Landing Page (frontend only)
</div>
)}
</Sticky>
Expand Down
44 changes: 44 additions & 0 deletions superset/assets/src/explore/controlPanels/Kepler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { t } from '@superset-ui/translation';

export default {
controlPanelSections: [
{
label: t('Query'),
expanded: true,
controlSetRows: [
['all_columns'],
['order_by_cols'],
['row_limit', null],
['adhoc_filters'],
],
},
{
label: t('Advanced'),
expanded: true,
controlSetRows: [
['autozoom', 'readonly'],
['config'],
],
},
],
controlOverrides: {
},
};
2 changes: 2 additions & 0 deletions superset/assets/src/explore/controlPanels/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import TimeTable from './TimeTable';
import Treemap from './Treemap';
import WordCloud from './WordCloud';
import WorldMap from './WorldMap';
import Kepler from './Kepler';
import DeckArc from './DeckArc';
import DeckGeojson from './DeckGeojson';
import DeckGrid from './DeckGrid';
Expand Down Expand Up @@ -113,6 +114,7 @@ export const controlPanelConfigs = extraOverrides({
treemap: Treemap,
word_cloud: WordCloud,
world_map: WorldMap,
kepler: Kepler,
deck_arc: DeckArc,
deck_geojson: DeckGeojson,
deck_grid: DeckGrid,
Expand Down
16 changes: 16 additions & 0 deletions superset/assets/src/explore/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ export const controls = {
description: t('When checked, the map will zoom to your data after each query'),
},

readonly: {
type: 'CheckboxControl',
label: t('Read Only Mode'),
default: false,
renderTrigger: true,
description: t('Whether to show/hide the left panel'),
},

show_perc: {
type: 'CheckboxControl',
label: t('Show percentage'),
Expand Down Expand Up @@ -1341,6 +1349,14 @@ export const controls = {
default: '',
},

config: {
type: 'TextAreaControl',
renderTrigger: true,
language: 'json',
label: t('Config'),
default: '',
},

pandas_aggfunc: {
type: 'SelectControl',
label: t('Aggregation function'),
Expand Down
20 changes: 20 additions & 0 deletions superset/assets/src/visualizations/Kepler/Kepler.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
.kepler {
}
132 changes: 132 additions & 0 deletions superset/assets/src/visualizations/Kepler/Kepler.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import { connect, Provider } from 'react-redux';
import PropTypes from 'prop-types';
import KeplerGl from 'kepler.gl';
import KeplerGlSchema from 'kepler.gl/schemas';
import { addDataToMap } from 'kepler.gl/actions';
import Processors from 'kepler.gl/processors';
import shortid from 'shortid';
import { createStore, combineReducers } from 'redux';
import keplerGlReducer from 'kepler.gl/reducers';

import './Kepler.css';

const propTypes = {
height: PropTypes.number,
setControlValue: PropTypes.func,
readonly: PropTypes.boolean,
};
const reducers = combineReducers({
// <-- mount kepler.gl reducer in your app
keplerGl: keplerGlReducer,
readonly: false,
});

class Kepler extends React.PureComponent {
constructor(props) {
super(props);
this.setMapConfig = this.setMapConfig.bind(this);
this.state = {
keplerId: shortid.generate(),
};
}
componentDidMount() {
this.addDataToMap(this.props);
this.setMapConfig();
}
componentWillReceiveProps(nextProps) {
if (nextProps.features !== this.props.features) {
this.addDataToMap(nextProps, false);
this.setMapConfig();
}
}
getCurrentConfig() {
try {
const { keplerGl } = this.props;
return KeplerGlSchema.getConfigToSave(keplerGl[this.state.keplerId]);
} catch (e) {
return null;
}
}
setMapConfig() {
const { setControlValue } = this.props;
const config = this.getCurrentConfig();
if (config) {
setControlValue('config', JSON.stringify(this.getCurrentConfig(), null, 2));
}
}
addDataToMap(props, useControlConfig = true) {
let config = props.config;
if (!config) {
config = null;
} else {
config = useControlConfig ? JSON.parse(config) : this.getCurrentConfig();
}
const data = Processors.processRowObject(props.features);
const datasets = [{
data,
info: {
id: 'main',
label: 'Superset Data',
},
}];
const options = { readOnly: this.props.readonly };
if (this.props.autozoom) {
options.centerMap = true;
if (config && config.config) {
config.config.mapState = {};
}
}
props.dispatch(addDataToMap({ datasets, config, options }));
}
render() {
return (
<div>
<KeplerGl
id={this.state.keplerId}
onSaveMap={this.setMapConfig}
{...this.props}
/>
</div>);
}
}

Kepler.displayName = 'Kepler';
Kepler.propTypes = propTypes;

const mapStateToProps = state => ({ keplerGl: state.keplerGl });
const dispatchToProps = dispatch => ({ dispatch });
const KeplerConnected = connect(mapStateToProps, dispatchToProps)(Kepler);

// eslint-disable-next-line react/no-multi-comp
export default class SubApp extends React.Component {
constructor(props) {
super(props);
this.store = createStore(reducers);
}
render() {
return (
<Provider store={this.store}>
<KeplerConnected {...this.props} />
</Provider>
);
}
}
39 changes: 39 additions & 0 deletions superset/assets/src/visualizations/Kepler/KeplerChartPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { t } from '@superset-ui/translation';
import { ChartMetadata, ChartPlugin } from '@superset-ui/chart';
import transformProps from './transformProps';
import thumbnail from './images/thumbnail.png';

const metadata = new ChartMetadata({
name: t('Kepler.gl'),
description: '',
credits: ['https://github.com/uber/kepler.gl'],
thumbnail,
});

export default class KeplerChartPlugin extends ChartPlugin {
constructor() {
super({
metadata,
transformProps,
loadChart: () => import('./Kepler.jsx'),
});
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 472564b

Please sign in to comment.