-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
[Geo] Added DeckGL Arc Layer and Refactor on BaseDeckGL class #4134
Changes from 4 commits
1b0357e
5a28349
d26118b
8254487
1ca1ba0
b83048e
d81936c
1018e7b
723a18a
1614b22
8d01b2a
854affc
ac84c6f
1569d6f
7fda2a9
2a8935b
93294ea
80cc345
3856a15
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,16 @@ | ||
import { ArcLayer } from 'deck.gl'; | ||
|
||
export default function arcLayer(formData, payload) { | ||
const fd = formData; | ||
const fc = fd.color_picker; | ||
const data = payload.data.arcs.map(d => ({ | ||
...d, | ||
color: [fc.r, fc.g, fc.b, 255 * fc.a], | ||
})); | ||
|
||
return new ArcLayer({ | ||
id: `path-layer-${fd.slice_id}`, | ||
data, | ||
strokeWidth: (fd.stroke_width) ? fd.stroke_width : 3, | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1818,6 +1818,58 @@ def get_position(self, d): | |
d.get('lat'), | ||
] | ||
|
||
def process_spatial_query_obj(self, spatial_key): | ||
fd = self.form_data | ||
gb = [] | ||
spatial = fd.get(spatial_key) | ||
|
||
if spatial is None: | ||
raise Exception(_('Bad spatial key')) | ||
|
||
if spatial.get('type') == 'latlong': | ||
gb += [spatial.get('lonCol')] | ||
gb += [spatial.get('latCol')] | ||
elif spatial.get('type') == 'delimited': | ||
gb += [spatial.get('lonlatCol')] | ||
elif spatial.get('type') == 'geohash': | ||
gb += [spatial.get('geohashCol')] | ||
|
||
return gb | ||
|
||
def process_spatial_data_obj(self, df, spatial_key): | ||
fd = self.form_data | ||
spatial = fd.get(spatial_key) | ||
if spatial is None: | ||
raise Exception(_('Bad spatial key')) | ||
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. nit: |
||
|
||
if spatial.get('type') == 'latlong': | ||
df = df.rename(columns={ | ||
spatial.get('lonCol'): 'lon', | ||
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. Aren't names conflicting here when there are multiple spatial controls? For that reason I think it'd be ideal to use the key as the column name in the dataframe, and store a tuple with lat & long as the value. |
||
spatial.get('latCol'): 'lat'}) | ||
elif spatial.get('type') == 'delimited': | ||
cols = ['lon', 'lat'] | ||
if spatial.get('reverseCheckbox'): | ||
cols.reverse() | ||
df[cols] = ( | ||
df[spatial.get('lonlatCol')] | ||
.str | ||
.split(spatial.get('delimiter'), expand=True) | ||
.astype(np.float64) | ||
) | ||
del df[spatial.get('lonlatCol')] | ||
elif spatial.get('type') == 'geohash': | ||
latlong = df[spatial.get('geohashCol')].map(geohash.decode) | ||
df['lat'] = latlong.apply(lambda x: x[0]) | ||
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. Idea: it may be less complex overall to simply store the lat/long as a tuple in a single column |
||
df['lon'] = latlong.apply(lambda x: x[1]) | ||
del df['geohash'] | ||
|
||
features = [] | ||
for d in df.to_dict(orient='records'): | ||
d = dict(position=self.get_position(d), **self.get_properties(d)) | ||
features.append(d) | ||
|
||
return features | ||
|
||
def query_obj(self): | ||
d = super(BaseDeckGLViz, self).query_obj() | ||
fd = self.form_data | ||
|
@@ -1847,6 +1899,7 @@ def query_obj(self): | |
|
||
def get_data(self, df): | ||
fd = self.form_data | ||
|
||
spatial = fd.get('spatial') | ||
if spatial: | ||
if spatial.get('type') == 'latlong': | ||
|
@@ -1998,6 +2051,51 @@ def get_data(self, df): | |
} | ||
|
||
|
||
class DeckArc(BaseDeckGLViz): | ||
|
||
"""deck.gl's Arc Layer""" | ||
|
||
viz_type = 'deck_arc' | ||
verbose_name = _('Deck.gl - Arc') | ||
|
||
def query_obj(self): | ||
d = super(DeckArc, self).query_obj() | ||
|
||
gb = [] | ||
for spatial_key in ['start_spatial', 'end_spatial']: | ||
gb += self.process_spatial_query_obj(spatial_key) | ||
|
||
metrics = self.get_metrics() | ||
if metrics: | ||
d['groupby'] = gb | ||
d['metrics'] = self.get_metrics() | ||
else: | ||
d['columns'] = gb | ||
|
||
return d | ||
|
||
def get_data(self, df): | ||
fd = self.form_data | ||
start_lat = df[fd.get('start_spatial').get('latCol')] | ||
start_lon = df[fd.get('start_spatial').get('lonCol')] | ||
end_lat = df[fd.get('end_spatial').get('latCol')] | ||
end_lon = df[fd.get('end_spatial').get('lonCol')] | ||
source_pos = list(zip(start_lon, start_lat)) | ||
target_pos = list(zip(end_lon, end_lat)) | ||
|
||
data = [] | ||
for pos in list(zip(source_pos, target_pos)): | ||
data.append({ | ||
'sourcePosition': pos[0], | ||
'targetPosition': pos[1], | ||
}) | ||
|
||
return { | ||
'arcs': data, | ||
'mapboxApiKey': config.get('MAPBOX_API_KEY'), | ||
} | ||
|
||
|
||
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.
nit: ValueError