Skip to content

Commit

Permalink
Shorten line
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Duberstein committed Oct 11, 2019
1 parent d5b5d5c commit e9e64f4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
3 changes: 2 additions & 1 deletion bindings/python/pydeck/pydeck/bindings/view_state.py
Expand Up @@ -3,7 +3,8 @@
class ViewState(JSONMixin):
"""An object that represents where the state of a viewport, essentially where the screen is focused.
If you have two dimensional data and you don't want to set this manually, see :func:`pydeck.data_utils.viewport_helpers.compute_view`.
If you have two dimensional data and you don't want to set this manually,
see :func:`pydeck.data_utils.viewport_helpers.compute_view`.
Parameters
Expand Down
11 changes: 8 additions & 3 deletions bindings/python/pydeck/pydeck/widget/widget.py
Expand Up @@ -3,7 +3,7 @@
from __future__ import unicode_literals

import ipywidgets as widgets
from traitlets import Any, Int, Unicode
from traitlets import Any, Int, Unicode, observe

from ._frontend import module_name, module_version

Expand All @@ -30,8 +30,8 @@ class DeckGLWidget(widgets.DOMWidget):
Data passed from Jupyter widget frontend back to Python backend
tooltip : bool or dict of {str: str}, default True
See the ``Deck`` constructor.
js_error : str, default None
JS console error, if any
"""
_model_name = Unicode('DeckGLModel').tag(sync=True)
_model_module = Unicode(module_name).tag(sync=True)
Expand All @@ -45,3 +45,8 @@ class DeckGLWidget(widgets.DOMWidget):
width = Any('100%').tag(sync=True)
selected_data = Any().tag(sync=True)
tooltip = Any(True).tag(sync=True)
js_error = Unicode(None, allow_none=True).tag(sync=True)

@observe('js_error')
def _observe_js_error(self, change):
widgets.append_stderr('JavaScript error detected: %s' % change['new'])
15 changes: 13 additions & 2 deletions modules/jupyter-widget/src/utils.js
Expand Up @@ -24,7 +24,18 @@ export function updateDeck(inputJSON, {jsonConverter, deckgl}) {
deckgl.setProps(results);
}

export function initDeck({mapboxApiKey, container, jsonInput, tooltip, onComplete, handleClick}) {
export function initDeck(
{mapboxApiKey, container, jsonInput, tooltip, onComplete, handleClick, handleError} = {
mapboxApiKey: null,
container: null,
jsonInput: null,
tooltip: null,
onComplete: null,
handleClick: null,
// eslint-disable-next-line
handleError: console.error
}
) {
require(['mapbox-gl', 'h3', 's2Geometry'], mapboxgl => {
require(['deck.gl', 'loaders.gl/csv'], (deck, loaders) => {
try {
Expand Down Expand Up @@ -61,7 +72,7 @@ export function initDeck({mapboxApiKey, container, jsonInput, tooltip, onComplet
} catch (err) {
// This will fail in node tests
// eslint-disable-next-line
console.error(err);
handleError(err);
}
return {};
});
Expand Down
14 changes: 12 additions & 2 deletions modules/jupyter-widget/src/widget.js
Expand Up @@ -23,7 +23,8 @@ export class DeckGLModel extends DOMWidgetModel {
selected_data: null,
tooltip: null,
width: '100%',
height: 500
height: 500,
js_error: null
};
}

Expand Down Expand Up @@ -81,7 +82,8 @@ export class DeckGLView extends DOMWidgetView {
onComplete: ({jsonConverter, deckgl}) => {
this.jsonDeck = {jsonConverter, deckgl};
},
handleClick: this.handleClick.bind(this)
handleClick: this.handleClick.bind(this),
handleError: this.handleError
});
}

Expand Down Expand Up @@ -114,4 +116,12 @@ export class DeckGLView extends DOMWidgetView {
}
this.model.save_changes();
}

handleError(err) {
if (!err) {
return;
}
this.model.set('js_error', err);
this.model.save_changes();
}
}

0 comments on commit e9e64f4

Please sign in to comment.