Skip to content

Commit

Permalink
Update to handle warning instead of error
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Duberstein committed Oct 11, 2019
1 parent e9e64f4 commit 5981060
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
13 changes: 5 additions & 8 deletions bindings/python/pydeck/pydeck/widget/widget.py
Expand Up @@ -2,8 +2,9 @@
# coding: utf-8
from __future__ import unicode_literals


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

from ._frontend import module_name, module_version

Expand All @@ -30,8 +31,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
js_warning : str, default None
JS console warning, if any
"""
_model_name = Unicode('DeckGLModel').tag(sync=True)
_model_module = Unicode(module_name).tag(sync=True)
Expand All @@ -45,8 +46,4 @@ 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'])
js_warning = Unicode(None, allow_none=True).tag(sync=True)
32 changes: 19 additions & 13 deletions modules/jupyter-widget/src/utils.js
Expand Up @@ -24,18 +24,15 @@ export function updateDeck(inputJSON, {jsonConverter, deckgl}) {
deckgl.setProps(results);
}

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
}
) {
export function initDeck({
mapboxApiKey,
container,
jsonInput,
tooltip,
onComplete,
handleClick,
handleWarning
}) {
require(['mapbox-gl', 'h3', 's2Geometry'], mapboxgl => {
require(['deck.gl', 'loaders.gl/csv'], (deck, loaders) => {
try {
Expand Down Expand Up @@ -66,15 +63,24 @@ export function initDeck(
getTooltip,
container
});
const warn = deck.log.warn;
deck.log.warn = wrapWarn(warn, handleWarning);
if (onComplete) {
onComplete({jsonConverter, deckgl});
}
} catch (err) {
// This will fail in node tests
// eslint-disable-next-line
handleError(err);
console.error(err);
}
return {};
});
});
}

function wrapWarn(warnFunction, messageHandler) {
return (message, err) => {
messageHandler(message);
return warnFunction(message, err);
};
}
10 changes: 5 additions & 5 deletions modules/jupyter-widget/src/widget.js
Expand Up @@ -24,7 +24,7 @@ export class DeckGLModel extends DOMWidgetModel {
tooltip: null,
width: '100%',
height: 500,
js_error: null
js_warning: null
};
}

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

Expand Down Expand Up @@ -117,11 +117,11 @@ export class DeckGLView extends DOMWidgetView {
this.model.save_changes();
}

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

0 comments on commit 5981060

Please sign in to comment.