hughhhh closed pull request #4131: [Geo] Added DeckGL Arcs Layer
URL: https://github.com/apache/incubator-superset/pull/4131
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/assets/javascripts/explore/stores/controls.jsx 
b/superset/assets/javascripts/explore/stores/controls.jsx
index 70cc2314a2..b89c891f54 100644
--- a/superset/assets/javascripts/explore/stores/controls.jsx
+++ b/superset/assets/javascripts/explore/stores/controls.jsx
@@ -499,6 +499,26 @@ export const controls = {
     }),
   },
 
+  start_spatial: {
+    type: 'SpatialControl',
+    label: t('Start Longitude & Latitude'),
+    validators: [v.nonEmpty],
+    description: t('Point to your spatial columns'),
+    mapStateToProps: state => ({
+      choices: (state.datasource) ? state.datasource.all_cols : [],
+    }),
+  },
+
+  end_spatial: {
+    type: 'SpatialControl',
+    label: t('End Longitude & Latitude'),
+    validators: [v.nonEmpty],
+    description: t('Point to your spatial columns'),
+    mapStateToProps: state => ({
+      choices: (state.datasource) ? state.datasource.all_cols : [],
+    }),
+  },
+
   longitude: {
     type: 'SelectControl',
     label: t('Longitude'),
diff --git a/superset/assets/javascripts/explore/stores/visTypes.js 
b/superset/assets/javascripts/explore/stores/visTypes.js
index f2e668f8f1..dd5a359b30 100644
--- a/superset/assets/javascripts/explore/stores/visTypes.js
+++ b/superset/assets/javascripts/explore/stores/visTypes.js
@@ -497,6 +497,27 @@ export const visTypes = {
     ],
   },
 
+  deck_arc: {
+    label: t('Deck.gl - Arc'),
+    requiresTime: true,
+    controlPanelSections: [
+      {
+        label: t('Query'),
+        expanded: true,
+        controlSetRows: [
+          ['start_spatial', 'end_spatial'],
+          ['row_limit', null],
+        ],
+      },
+      {
+        label: t('Map'),
+        controlSetRows: [
+          ['mapbox_style', 'viewport'],
+        ],
+      },
+    ],
+  },
+
   deck_scatter: {
     label: t('Deck.gl - Scatter plot'),
     requiresTime: true,
diff --git a/superset/assets/visualizations/deckgl/layers/arc.jsx 
b/superset/assets/visualizations/deckgl/layers/arc.jsx
new file mode 100644
index 0000000000..44da3d9651
--- /dev/null
+++ b/superset/assets/visualizations/deckgl/layers/arc.jsx
@@ -0,0 +1,15 @@
+import { ArcLayer } from 'deck.gl';
+import { hexToRGB } from '../../../javascripts/modules/colors';
+
+export default function arcLayer(formData, payload) {
+  const fd = formData;
+  const data = payload.data.arcs;
+  return new ArcLayer({
+    id: `path-layer-${fd.slice_id}`,
+    data,
+    filled: true,
+    stroked: false,
+    extruded: true,
+    pointRadiusScale: fd.point_radius_scale,
+  });
+}
diff --git a/superset/assets/visualizations/deckgl/layers/index.js 
b/superset/assets/visualizations/deckgl/layers/index.js
index a382af55b8..4d14196cc2 100644
--- a/superset/assets/visualizations/deckgl/layers/index.js
+++ b/superset/assets/visualizations/deckgl/layers/index.js
@@ -5,6 +5,7 @@ import deck_path from './path';
 import deck_hex from './hex';
 import deck_scatter from './scatter';
 import deck_geojson from './geojson';
+import deck_arc from './arc';
 
 const layerGenerators = {
   deck_grid,
@@ -13,5 +14,6 @@ const layerGenerators = {
   deck_hex,
   deck_scatter,
   deck_geojson,
+  deck_arc,
 };
 export default layerGenerators;
diff --git a/superset/assets/visualizations/main.js 
b/superset/assets/visualizations/main.js
index af7b040101..7cb040bc4c 100644
--- a/superset/assets/visualizations/main.js
+++ b/superset/assets/visualizations/main.js
@@ -46,6 +46,7 @@ export const VIZ_TYPES = {
   deck_path: 'deck_path',
   deck_geojson: 'deck_geojson',
   deck_multi: 'deck_multi',
+  deck_arc: 'deck_arc',
 };
 
 const vizMap = {
@@ -92,6 +93,7 @@ const vizMap = {
   [VIZ_TYPES.deck_hex]: deckglFactory,
   [VIZ_TYPES.deck_path]: deckglFactory,
   [VIZ_TYPES.deck_geojson]: deckglFactory,
+  [VIZ_TYPES.deck_arc]: deckglFactory,
   [VIZ_TYPES.deck_multi]: require('./deckgl/multi.jsx'),
 };
 export default vizMap;
diff --git a/superset/viz.py b/superset/viz.py
index e649456de1..d8192a5704 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -1824,15 +1824,16 @@ def query_obj(self):
 
         gb = []
 
-        spatial = fd.get('spatial')
-        if spatial:
-            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')]
+        for spatial_key in ['spatial', 'start_spatial', 'end_spatial']:
+            spatial = fd.get(spatial_key)
+            if spatial:
+                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')]
 
         if fd.get('dimension'):
             gb += [fd.get('dimension')]
@@ -1847,28 +1848,30 @@ def query_obj(self):
 
     def get_data(self, df):
         fd = self.form_data
-        spatial = fd.get('spatial')
-        if spatial:
-            if spatial.get('type') == 'latlong':
-                df = df.rename(columns={
-                    spatial.get('lonCol'): 'lon',
-                    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])
-                df['lon'] = latlong.apply(lambda x: x[1])
-                del df['geohash']
+
+        for spatial_key in ['spatial', 'start_spatial', 'end_spatial']:
+            spatial = fd.get(spatial_key)
+            if spatial:
+                if spatial.get('type') == 'latlong':
+                    df = df.rename(columns={
+                        spatial.get('lonCol'): 'lon',
+                        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])
+                    df['lon'] = latlong.apply(lambda x: x[1])
+                    del df['geohash']
 
         features = []
         for d in df.to_dict(orient='records'):
@@ -1998,6 +2001,42 @@ 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()
+        from pprint import pprint
+        pprint(d)
+        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_lat, start_lon))
+        target_pos = list(zip(end_lat, end_lon))
+
+        data = []
+        for pos in list(zip(source_pos, target_pos)):
+            data.append({
+                         'sourcePosition': pos[1],
+                         'targetPosition': pos[0],
+                         'color': [255, 0, 0],
+                         })
+
+        return {
+            'arcs': data,
+            'mapboxApiKey': config.get('MAPBOX_API_KEY'),
+        }
+
+
 class EventFlowViz(BaseViz):
 
     """A visualization to explore patterns in event sequences"""


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to