Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Jupyter] [Bug] fix lab widget window responsiveness, add version to header (#771)

Shan Hef039c9e40425
diff --git a/bindings/kepler.gl-jupyter/.gitignore b/bindings/kepler.gl-jupyter/.gitignore
index 995560053..af7afd15e 100644
--- a/bindings/kepler.gl-jupyter/.gitignore
+++ b/bindings/kepler.gl-jupyter/.gitignore
@@ -7,7 +7,9 @@ dist/
build/
*.py[cod]
node_modules/
-env/
+ENV/
+ENV3/
+
# OS X
.DS_Store
.vs_code/
diff --git a/bindings/kepler.gl-jupyter/js/.babelrc b/bindings/kepler.gl-jupyter/js/.babelrc
deleted file mode 100644
index 2bad34aa6..000000000
--- a/bindings/kepler.gl-jupyter/js/.babelrc
+++ /dev/null
@@ -1,34 +0,0 @@
-{
- "presets": [
- "@babel/preset-env",
- "@babel/preset-react"
- ],
- "plugins": [
- ["@babel/plugin-proposal-decorators", { "legacy": true }],
- "@babel/plugin-proposal-class-properties",
- ["@babel/transform-runtime", {
- "regenerator": true
- }],
- "@babel/plugin-syntax-dynamic-import",
- "@babel/plugin-syntax-import-meta",
- "@babel/plugin-proposal-json-strings",
- "@babel/plugin-proposal-function-sent",
- "@babel/plugin-proposal-export-namespace-from",
- "@babel/plugin-proposal-numeric-separator",
- "@babel/plugin-proposal-throw-expressions",
- "@babel/plugin-proposal-export-default-from",
- "@babel/plugin-proposal-logical-assignment-operators",
- "@babel/plugin-proposal-optional-chaining",
- [
- "@babel/plugin-proposal-pipeline-operator",
- {
- "proposal": "minimal"
- }
- ],
- "@babel/plugin-transform-react-jsx",
- "transform-inline-environment-variables",
- "@babel/plugin-proposal-nullish-coalescing-operator",
- "@babel/plugin-proposal-do-expressions",
- "@babel/plugin-proposal-function-bind"
- ]
-}
diff --git a/bindings/kepler.gl-jupyter/js/babel.config.js b/bindings/kepler.gl-jupyter/js/babel.config.js
new file mode 100644
index 000000000..f84301474
--- /dev/null
+++ b/bindings/kepler.gl-jupyter/js/babel.config.js
@@ -0,0 +1,73 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+const KeplerPackage = require('./package');
+
+module.exports = function babel(api) {
+ api.cache(true);
+
+ const presets = ['@babel/preset-env', '@babel/preset-react'];
+ const plugins = [
+ '@babel/plugin-proposal-class-properties',
+ [
+ '@babel/transform-runtime',
+ {
+ regenerator: true
+ }
+ ],
+ '@babel/plugin-syntax-dynamic-import',
+ '@babel/plugin-syntax-import-meta',
+ '@babel/plugin-proposal-json-strings',
+ '@babel/plugin-proposal-function-sent',
+ '@babel/plugin-proposal-export-namespace-from',
+ '@babel/plugin-proposal-numeric-separator',
+ '@babel/plugin-proposal-throw-expressions',
+ '@babel/plugin-proposal-export-default-from',
+ '@babel/plugin-proposal-logical-assignment-operators',
+ '@babel/plugin-proposal-optional-chaining',
+ [
+ '@babel/plugin-proposal-pipeline-operator',
+ {
+ proposal: 'minimal'
+ }
+ ],
+ '@babel/plugin-transform-react-jsx',
+ 'transform-inline-environment-variables',
+ '@babel/plugin-proposal-nullish-coalescing-operator',
+ '@babel/plugin-proposal-do-expressions',
+ '@babel/plugin-proposal-function-bind',
+ [
+ 'search-and-replace',
+ {
+ rules: [
+ {
+ search: '__PACKAGE_VERSION__',
+ replace: KeplerPackage.version
+ }
+ ]
+ }
+ ]
+ ];
+
+ return {
+ presets,
+ plugins
+ };
+};
diff --git a/bindings/kepler.gl-jupyter/js/lib/keplergl/components/app.js b/bindings/kepler.gl-jupyter/js/lib/keplergl/components/app.js
index b8df57833..9640e4d75 100644
--- a/bindings/kepler.gl-jupyter/js/lib/keplergl/components/app.js
+++ b/bindings/kepler.gl-jupyter/js/lib/keplergl/components/app.js
@@ -31,6 +31,7 @@ import {
import CustomPanelHeaderFactory from './panel-header';
import CustomSidebarFactory from './side-bar';
+export const KEPLER_GL_JUPYTER_VERSION = "__PACKAGE_VERSION__";
const CustomAddDataButtonFactory = () => {
const CustomAddDataButton = () => <div />;
@@ -46,6 +47,7 @@ const KeplerGl = injectComponents([
const MAPBOX_TOKEN = process.env.MapboxAccessTokenJupyter; // eslint-disable-line
function App() {
+
const rootElm = useRef(null);
const [windowDimension, setDimension] = useState({});
@@ -53,15 +55,24 @@ function App() {
if (!rootElm.current) {
return;
}
- const {width, height} = rootElm.current.getBoundingClientRect();
- if (width !== windowDimension.width || height !== windowDimension.height) {
- setDimension({width, height});
- }
+
+ const width = rootElm.current.offsetWidth;
+ const height = rootElm.current.offsetHeight;
+ const dimensionToSet = {
+ ...(width && width !== windowDimension.width ? {width} : {}),
+ ...(height && height !== windowDimension.height ? {height} : {})
+ };
+
+ setDimension(dimensionToSet);
};
+ // in Jupyter Lab, parent component has transition when window resize.
+ // need to delay call to get the final parent width,
+ const resizeDelay = () => window.setTimeout(handleResize, 500);
+
useEffect(() => {
- window.addEventListener('resize', handleResize);
- return () => window.removeEventListener('resize', handleResize);
+ window.addEventListener('resize', resizeDelay);
+ return () => window.removeEventListener('resize', resizeDelay);
}, []);
return (
@@ -87,6 +98,7 @@ function App() {
font-weight: 400;
font-size: 0.875em;
line-height: 1.71429;
+
*,
*:before,
*:after {
@@ -100,9 +112,20 @@ function App() {
.kepler-gl .ReactModal__Overlay.ReactModal__Overlay--after-open {
position: absolute !important;
}
+
+ .jupyter-widgets.keplergl-jupyter-widgets {
+ overflow: hidden;
+ }
+
+ .p-Widget.p-Panel.jp-OutputArea-output.jupyter-widgets {
+ overflow: hidden
+ }
`}
</style>
- <script async src="https://www.googletagmanager.com/gtag/js?id=UA-64694404-19"/>
+ <script
+ async
+ src="https://www.googletagmanager.com/gtag/js?id=UA-64694404-19"
+ />
<script>{`window.dataLayer=window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'UA-64694404-19', {page_path: '/keplergl-jupyter-widget'});`}</script>
</Helmet>
) : null}
@@ -111,7 +134,7 @@ function App() {
width={windowDimension.width || 800}
height={windowDimension.height || 400}
appName="Kepler.gl Jupyter"
- version="0.1.0a9"
+ version={KEPLER_GL_JUPYTER_VERSION}
getMapboxRef={handleResize}
/>
</div>
diff --git a/bindings/kepler.gl-jupyter/js/lib/keplergl/kepler.gl.js b/bindings/kepler.gl-jupyter/js/lib/keplergl/kepler.gl.js
index e5fbc1c0f..261cab37e 100644
--- a/bindings/kepler.gl-jupyter/js/lib/keplergl/kepler.gl.js
+++ b/bindings/kepler.gl-jupyter/js/lib/keplergl/kepler.gl.js
@@ -101,9 +101,13 @@ class KeplerGlJupyter {
const height = getHeight(that);
+ that.el.classList.add('jupyter-widgets');
+ that.el.classList.add('keplergl-jupyter-widgets');
+
const divElmt = document.createElement('div');
divElmt.setAttribute('id', this.id);
- divElmt.setAttribute('style', `width: 100%; height: ${height}px`);
+ divElmt.classList.add('kepler-gl');
+ divElmt.setAttribute('style', ` width: 100%; height: ${height}px;`);
that.el.appendChild(divElmt);
renderRoot({id: this.id, store: this.store, ele: divElmt});
diff --git a/bindings/kepler.gl-jupyter/js/webpack/config.js b/bindings/kepler.gl-jupyter/js/webpack/config.js
index 20ba9d36d..811ffd913 100644
--- a/bindings/kepler.gl-jupyter/js/webpack/config.js
+++ b/bindings/kepler.gl-jupyter/js/webpack/config.js
@@ -29,12 +29,6 @@ const rules = [
loader: 'babel-loader',
include: path.join(__dirname, '../lib', 'keplergl'),
exclude: [/node_modules/]
- },
- {
- // The example has some JSON data
- test: /\.json$/,
- loader: 'json-loader',
- exclude: [/node_modules|package.json/]
}
];
diff --git a/bindings/kepler.gl-jupyter/notebooks/DataFrame.ipynb b/bindings/kepler.gl-jupyter/notebooks/DataFrame.ipynb
index b5f47974e..cb280a9b7 100644
--- a/bindings/kepler.gl-jupyter/notebooks/DataFrame.ipynb
+++ b/bindings/kepler.gl-jupyter/notebooks/DataFrame.ipynb
@@ -84,7 +84,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "94e4cf1bad504cb2b2001960a45743ae",
+ "model_id": "1f2d7f90715c4b6e8fa4355be8a2b895",
"version_major": 2,
"version_minor": 0
},
@@ -118,6 +118,29 @@
"source": [
"w1.save_to_html(file_name='keplergl_map_time_test_1.html')"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "ImportError",
+ "evalue": "No module named ipyleaflet",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m<ipython-input-5-5d01f050433e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mipyleaflet\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mm\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcenter\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m52\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mzoom\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m8\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbasemap\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mbasemaps\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mHydda\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mFull\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mm\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;31mImportError\u001b[0m: No module named ipyleaflet"
+ ]
+ }
+ ],
+ "source": [
+ "from ipyleaflet import *\n",
+ "m = Map(center=(52, 10), zoom=8, basemap=basemaps.Hydda.Full)\n",
+ "m"
+ ]
}
],
"metadata": {
diff --git a/bindings/kepler.gl-jupyter/notebooks/Load kepler.gl.ipynb b/bindings/kepler.gl-jupyter/notebooks/Load kepler.gl.ipynb
index 37d01eaa1..30f56d96e 100644
--- a/bindings/kepler.gl-jupyter/notebooks/Load kepler.gl.ipynb
+++ b/bindings/kepler.gl-jupyter/notebooks/Load kepler.gl.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
@@ -12,7 +12,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
@@ -25,7 +25,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
@@ -35,7 +35,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 24,
"metadata": {
"scrolled": false
},
@@ -44,13 +44,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Documentation: https://github.com/keplergl/kepler.gl/blob/master/docs/keplergl-jupyter/user-guide.md\n"
+ "User Guide: https://github.com/keplergl/kepler.gl/blob/master/docs/keplergl-jupyter/user-guide.md\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "0db03064b7604fa6ad3928b6ba7998b2",
+ "model_id": "f7b4dcebf5a44c0f99c3ba0eb9bd51b7",
"version_major": 2,
"version_minor": 0
},
@@ -311,7 +311,7 @@
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": 21,
"metadata": {},
"outputs": [
{