forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WiP] Integrate Kepler.gl as a new visualization type
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)
- Loading branch information
1 parent
8a4fd72
commit 791776e
Showing
13 changed files
with
1,390 additions
and
284 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: { | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
superset/assets/src/visualizations/Kepler/KeplerChartPlugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
33 changes: 33 additions & 0 deletions
33
superset/assets/src/visualizations/Kepler/transformProps.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* 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. | ||
*/ | ||
export default function transformProps(chartProps) { | ||
const { formData, height, width, payload, setControlValue } = chartProps; | ||
const { mapboxApiAccessToken, features } = payload.data; | ||
const { config, autozoom, readonly } = formData; | ||
return { | ||
height, | ||
width, | ||
config, | ||
autozoom, | ||
readonly, | ||
features, | ||
setControlValue, | ||
mapboxApiAccessToken, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters