superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: [geo] JS function to receive the whole data array instead of individual object (#4262)
Date Wed, 24 Jan 2018 21:16:17 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new ff2f85f  [geo] JS function to receive the whole data array instead of individual
object (#4262)
ff2f85f is described below

commit ff2f85f39b03c9c65d959f0d1ead32ad62a56251
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Wed Jan 24 13:16:14 2018 -0800

    [geo] JS function to receive the whole data array instead of individual object (#4262)
    
    Moving from having the user define an interceptor function that operates
    on one object at a time.
    
    By passing the entire array, it's possible to do multiple pass where
    needed. A common pattern might be to figure out the max value in order
    to define a scaler function. That's only possible if dealing with the
    whole array.
---
 superset/assets/javascripts/explore/stores/controls.jsx |  9 +++++----
 superset/assets/javascripts/explore/stores/visTypes.js  |  8 ++++----
 .../assets/visualizations/deckgl/layers/geojson.jsx     | 17 ++++++++---------
 superset/assets/visualizations/deckgl/layers/path.jsx   |  6 +++---
 .../assets/visualizations/deckgl/layers/polygon.jsx     |  6 +++---
 .../assets/visualizations/deckgl/layers/scatter.jsx     |  6 +++---
 6 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/superset/assets/javascripts/explore/stores/controls.jsx b/superset/assets/javascripts/explore/stores/controls.jsx
index 9aac6cc..372a01f 100644
--- a/superset/assets/javascripts/explore/stores/controls.jsx
+++ b/superset/assets/javascripts/explore/stores/controls.jsx
@@ -1881,10 +1881,11 @@ export const controls = {
     },
   },
 
-  js_datapoint_mutator: jsFunctionControl(
-    t('Javascript data point mutator'),
-    t('Define a javascript function that receives each data point and can alter it ' +
-      'before getting sent to the deck.gl layer'),
+  js_data_mutator: jsFunctionControl(
+    t('Javascript data interceptor'),
+    t('Define a javascript function that receives the data array used in the visualization
' +
+      'and is expected to return a modified version of that array. This can be used ' +
+      'to alter properties of the data, filter, or enrich the array.'),
   ),
 
   js_data: jsFunctionControl(
diff --git a/superset/assets/javascripts/explore/stores/visTypes.js b/superset/assets/javascripts/explore/stores/visTypes.js
index b175ff3..4b0120d 100644
--- a/superset/assets/javascripts/explore/stores/visTypes.js
+++ b/superset/assets/javascripts/explore/stores/visTypes.js
@@ -437,7 +437,7 @@ export const visTypes = {
         label: t('Advanced'),
         controlSetRows: [
           ['js_columns'],
-          ['js_datapoint_mutator'],
+          ['js_data_mutator'],
           ['js_tooltip'],
           ['js_onclick_href'],
         ],
@@ -509,7 +509,7 @@ export const visTypes = {
         label: t('Advanced'),
         controlSetRows: [
           ['js_columns'],
-          ['js_datapoint_mutator'],
+          ['js_data_mutator'],
           ['js_tooltip'],
           ['js_onclick_href'],
         ],
@@ -549,7 +549,7 @@ export const visTypes = {
         label: t('Advanced'),
         controlSetRows: [
           ['js_columns'],
-          ['js_datapoint_mutator'],
+          ['js_data_mutator'],
           ['js_tooltip'],
           ['js_onclick_href'],
         ],
@@ -621,7 +621,7 @@ export const visTypes = {
         label: t('Advanced'),
         controlSetRows: [
           ['js_columns'],
-          ['js_datapoint_mutator'],
+          ['js_data_mutator'],
           ['js_tooltip'],
           ['js_onclick_href'],
         ],
diff --git a/superset/assets/visualizations/deckgl/layers/geojson.jsx b/superset/assets/visualizations/deckgl/layers/geojson.jsx
index c21ce3b..7792d23 100644
--- a/superset/assets/visualizations/deckgl/layers/geojson.jsx
+++ b/superset/assets/visualizations/deckgl/layers/geojson.jsx
@@ -35,10 +35,10 @@ const alterProps = (props, propOverrides) => {
   };
 };
 let features;
-const recurseGeoJson = (node, propOverrides, jsFnMutator, extraProps) => {
+const recurseGeoJson = (node, propOverrides, extraProps) => {
   if (node && node.features) {
     node.features.forEach((obj) => {
-      recurseGeoJson(obj, propOverrides, jsFnMutator, node.extraProps || extraProps);
+      recurseGeoJson(obj, propOverrides, node.extraProps || extraProps);
     });
   }
   if (node && node.geometry) {
@@ -46,9 +46,6 @@ const recurseGeoJson = (node, propOverrides, jsFnMutator, extraProps) =>
{
       ...node,
       properties: alterProps(node.properties, propOverrides),
     };
-    if (jsFnMutator) {
-      jsFnMutator(newNode);
-    }
     if (!newNode.extraProps) {
       newNode.extraProps = extraProps;
     }
@@ -70,14 +67,16 @@ export default function geoJsonLayer(formData, payload, slice) {
     propOverrides.strokeColor = strokeColor;
   }
 
+  features = [];
+  recurseGeoJson(payload.data, propOverrides);
+
   let jsFnMutator;
-  if (fd.js_datapoint_mutator) {
+  if (fd.js_data_mutator) {
     // Applying user defined data mutator if defined
-    jsFnMutator = sandboxedEval(fd.js_datapoint_mutator);
+    jsFnMutator = sandboxedEval(fd.js_data_mutator);
+    features = jsFnMutator(features);
   }
 
-  features = [];
-  recurseGeoJson(payload.data, propOverrides, jsFnMutator);
   return new GeoJsonLayer({
     id: `geojson-layer-${fd.slice_id}`,
     filled: fd.filled,
diff --git a/superset/assets/visualizations/deckgl/layers/path.jsx b/superset/assets/visualizations/deckgl/layers/path.jsx
index c69f236..df2c1b0 100644
--- a/superset/assets/visualizations/deckgl/layers/path.jsx
+++ b/superset/assets/visualizations/deckgl/layers/path.jsx
@@ -14,9 +14,9 @@ export default function getLayer(formData, payload, slice) {
     color: fixedColor,
   }));
 
-  if (fd.js_datapoint_mutator) {
-    const jsFnMutator = sandboxedEval(fd.js_datapoint_mutator);
-    data = data.map(jsFnMutator);
+  if (fd.js_data_mutator) {
+    const jsFnMutator = sandboxedEval(fd.js_data_mutator);
+    data = jsFnMutator(data);
   }
 
   return new PathLayer({
diff --git a/superset/assets/visualizations/deckgl/layers/polygon.jsx b/superset/assets/visualizations/deckgl/layers/polygon.jsx
index 05c32c6..8862827 100644
--- a/superset/assets/visualizations/deckgl/layers/polygon.jsx
+++ b/superset/assets/visualizations/deckgl/layers/polygon.jsx
@@ -11,10 +11,10 @@ export default function polygonLayer(formData, payload, slice) {
     fillColor: [fc.r, fc.g, fc.b, 255 * fc.a],
   }));
 
-  if (fd.js_datapoint_mutator) {
+  if (fd.js_data_mutator) {
     // Applying user defined data mutator if defined
-    const jsFnMutator = sandboxedEval(fd.js_datapoint_mutator);
-    data = data.map(jsFnMutator);
+    const jsFnMutator = sandboxedEval(fd.js_data_mutator);
+    data = jsFnMutator(data);
   }
 
   return new PolygonLayer({
diff --git a/superset/assets/visualizations/deckgl/layers/scatter.jsx b/superset/assets/visualizations/deckgl/layers/scatter.jsx
index eda1b7c..0f591a2 100644
--- a/superset/assets/visualizations/deckgl/layers/scatter.jsx
+++ b/superset/assets/visualizations/deckgl/layers/scatter.jsx
@@ -28,10 +28,10 @@ export default function getLayer(formData, payload, slice) {
     };
   });
 
-  if (fd.js_datapoint_mutator) {
+  if (fd.js_data_mutator) {
     // Applying user defined data mutator if defined
-    const jsFnMutator = sandboxedEval(fd.js_datapoint_mutator);
-    data = data.map(jsFnMutator);
+    const jsFnMutator = sandboxedEval(fd.js_data_mutator);
+    data = jsFnMutator(data);
   }
 
   return new ScatterplotLayer({

-- 
To stop receiving notification emails like this one, please contact
maximebeauchemin@apache.org.

Mime
View raw message