-
Notifications
You must be signed in to change notification settings - Fork 13.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added DeckGL.Polygon Layer w/ JS controls #4227
Changes from 6 commits
a2304b6
9e94150
1ec204a
4e99c37
835a13e
e549c9a
2a7ae47
b42f06e
f75dc51
828014c
65e6e60
cd33bee
7e8726b
3173cdc
d49bcbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { PolygonLayer } from 'deck.gl'; | ||
|
||
import * as common from './common'; | ||
import sandboxedEval from '../../../javascripts/modules/sandbox'; | ||
|
||
export default function polygonLayer(formData, payload, slice) { | ||
const fd = formData; | ||
const fc = fd.fill_color_picker; | ||
let data = payload.data.features.map(d => ({ | ||
...d, | ||
fillColor: [fc.r, fc.g, fc.b, 255 * fc.a], | ||
})); | ||
|
||
if (fd.js_datapoint_mutator) { | ||
// Applying user defined data mutator if defined | ||
const jsFnMutator = sandboxedEval(fd.js_datapoint_mutator); | ||
data = data.map(jsFnMutator); | ||
} | ||
|
||
return new PolygonLayer({ | ||
id: `path-layer-${fd.slice_id}`, | ||
data, | ||
filled: fd.filled, | ||
stroked: fd.stoked, | ||
extruded: fd.extruded, | ||
...common.commonLayerProps(fd, slice), | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1895,6 +1895,7 @@ def get_data(self, df): | |
if extra_props: | ||
feature['extraProps'] = extra_props | ||
features.append(feature) | ||
|
||
return { | ||
'features': features, | ||
'mapboxApiKey': config.get('MAPBOX_API_KEY'), | ||
|
@@ -1982,7 +1983,6 @@ class DeckPathViz(BaseDeckGLViz): | |
'json': json.loads, | ||
'polyline': polyline.decode, | ||
} | ||
spatial_control_keys = ['spatial'] | ||
|
||
def query_obj(self): | ||
d = super(DeckPathViz, self).query_obj() | ||
|
@@ -2062,6 +2062,40 @@ def get_data(self, df): | |
} | ||
|
||
|
||
class DeckPolygon(BaseDeckGLViz): | ||
|
||
"""deck.gl's Polygon Layer""" | ||
|
||
viz_type = 'deck_polygon' | ||
verbose_name = _('Deck.gl - Polygon') | ||
deser_map = { | ||
'json': json.loads, | ||
'polyline': polyline.decode, | ||
} | ||
|
||
def get_position(self, d): | ||
return d[self.form_data.get('line_column')] | ||
|
||
def query_obj(self): | ||
d = super(DeckPolygon, self).query_obj() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mistercrunch not sure if you wanted me to move this functionality into the baseClass? I think this is fine since we are still leveraging the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In theory we could have some intermediate (or mixin class) in between the base class that would be common to deck_path and deck_polygon, but in general the python philosophy is to keep inheritance schemes simple when possible. I'm fine leaving it as is as it's little code duplication as it is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I think about it, could we just have |
||
line_col = self.form_data.get('line_column') | ||
if d['metrics']: | ||
d['groupby'].append(line_col) | ||
else: | ||
d['columns'].append(line_col) | ||
return d | ||
|
||
def get_properties(self, d): | ||
fd = self.form_data | ||
deser = self.deser_map[fd.get('line_type')] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could save one hash lookup per row ( |
||
polygon = deser(d[fd.get('line_column')]) | ||
if fd.get('reverse_long_lat'): | ||
polygon = (polygon[1], polygon[0]) | ||
return { | ||
'polygon': polygon, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is pretty much the only difference between DeckPath and DeckPolyline, I'd suggest have |
||
} | ||
|
||
|
||
class EventFlowViz(BaseViz): | ||
|
||
"""A visualization to explore patterns in event sequences""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My recent PR got rid of
get_position
, you may need to rebase and remove this method.