Skip to content
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

Fix multilayer geoviz and color picker error #5767

Merged
merged 4 commits into from Aug 29, 2018

Conversation

youngyjd
Copy link
Contributor

@youngyjd youngyjd commented Aug 28, 2018

Several improvements and bug fixes in this PR.

  1. The multilayer geoviz was unable to be rendered because queries did not filter out null locations by default. Changing if fd.get('filter_nulls') to if fd.get('filter_nulls', True) fixed the issue.
  2. getLayer() function in scatter.jsx is also called by multilayer geoviz directly. After introducing component CategoricalDeckGLContainer, the getLayer() interface got changed so scatterplot failed to be rendered in multilayer geoviz.
  3. color picker does not work with scatter plot and it is always showing black point. This issue is fixed as well.

screen shot 2018-08-28 at 4 02 10 pm

@youngyjd
Copy link
Contributor Author

@codecov-io
Copy link

codecov-io commented Aug 28, 2018

Codecov Report

Merging #5767 into master will increase coverage by <.01%.
The diff coverage is 4.54%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5767      +/-   ##
==========================================
+ Coverage   63.81%   63.81%   +<.01%     
==========================================
  Files         364      364              
  Lines       23055    23080      +25     
  Branches     2568     2572       +4     
==========================================
+ Hits        14713    14729      +16     
- Misses       8327     8336       +9     
  Partials       15       15
Impacted Files Coverage Δ
...et/assets/src/visualizations/deckgl/layers/arc.jsx 0% <0%> (ø) ⬆️
...ssets/src/visualizations/deckgl/layers/scatter.jsx 0% <0%> (ø) ⬆️
...sualizations/deckgl/CategoricalDeckGLContainer.jsx 0% <0%> (ø) ⬆️
...uperset/assets/src/visualizations/deckgl/multi.jsx 0% <0%> (ø) ⬆️
superset/viz.py 81.38% <100%> (+0.09%) ⬆️
superset/assets/src/visualizations/world_map.js 0% <0%> (ø) ⬆️
superset/assets/src/visualizations/rose.js 0% <0%> (ø) ⬆️
superset/connectors/sqla/models.py 80.91% <0%> (+2.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2da5db9...ea6ef50. Read the comment docs.

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for catching all these little problems! There's just one modification we should do: before we were passing payload, I changed it to pass only data (breaking the generic interface), and now you've changed it to pass both. Let's pass only the payload, and extract data from it.

let filters = subslice.form_data.filters.concat(fd.filters);
let filters = [];
if (subslice.form_data.filters) {
filters = filters.concat(subslice.form_data.filters);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, can you use array spread here instead of concat?

filters = [...filters, ...subslice.form_data.filters];

Same below, in the two uses of concat. It's the new preferred way of concatenating arrays.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got you. Thank!

}
if (fd.filters) {
filters = filters.concat(fd.filters);
}
if (fd.extra_filters) {
filters = filters.concat(fd.extra_filters);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could do it in a single pass:

const filters = [
    ...(subslice.form_data.filters || [])
    ...(fd.filters || [])
    ...(fd.extra_filters || [])
];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! thanks


return {
'arcs': arcs,
'features': d['features'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 I think it's good to standardize on the key value here.

}
const c = fd.color_picker || { r: 0, g: 0, b: 0, a: 1 };
const color = [c.r, c.g, c.b, c.a * 255];
return { ...d, radius, color };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this, I think I must've removed it by mistake.

@@ -18,7 +18,8 @@ function getPoints(data) {
return points;
}

function getLayer(fd, data, slice) {
function getLayer(fd, payload, slice) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I simplified the getLayer interface but forgot that other deck.gl vizs need other attributes in the payload.

}

ReactDOM.render(
<CategoricalDeckGLContainer
slice={slice}
data={payload.data.arcs}
data={payload.data.features}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're passing payload below then we shouldn't pass data.

@@ -54,6 +59,7 @@ function deckScatter(slice, payload, setControlValue) {
setControlValue={setControlValue}
viewport={viewport}
getLayer={getLayer}
payload={payload}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove data above, since we're passing the payload.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! make sense

@@ -35,6 +35,7 @@ const propTypes = {
setControlValue: PropTypes.func.isRequired,
viewport: PropTypes.object.isRequired,
getLayer: PropTypes.func.isRequired,
payload: PropTypes.object.isRequired,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove data from the props, since it can fetched from the payload.

@youngyjd
Copy link
Contributor Author

@betodealmeida Comments addressed. PTAL

@youngyjd youngyjd force-pushed the fix-multilayer-and-color-picker branch from 339a8c9 to fd85b97 Compare August 29, 2018 03:04
Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@youngyjd looks great! I have just a small comment on the payload inside getLayer, we can change it so data doesn't get copied.

@@ -80,7 +80,7 @@ export default class CategoricalDeckGLContainer extends React.PureComponent {
}
getLayers(values) {
const fd = this.props.slice.formData;
let data = [...this.props.data];
let data = [...this.props.payload.data.features];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you're making a copy of this.props.payload.data.features, mutating it, and then assigning it back to payload in line 107. Here you can simply do:

let data = this.props.payload.data.features;

And then as you mutate it, payload.data.features is also mutated. This way you can simply pass the original payload to getLayer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some test and found it does not work. I guess it is because the location that data references got changed so payload.data.features will not get updated.

This is part of the code:

    let data = [...this.props.payload.data.features];

    // Add colors from categories or fixed color
    data = this.addColor(data, fd);

If we change it to let data = this.props.payload.data.features; and then data get reassigned by data = this.addColor(data, fd);, it is not referencing to the location of this.props.payload.data.features anymore so this.props.payload.data.features will not be changed.

return [this.props.getLayer(fd, data, this.props.slice)];
const payload = this.props.payload;
payload.data.features = data;
return [this.props.getLayer(fd, payload, this.props.slice)];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can simply be written as:

return [this.props.getLayer(fd, this.props.payload, this.props.slice)];

If you follow my comment above. You can also do in the beginning of the function:

const { getLayer, payload, slice } = this.props;

The you can simple refer to getLayer, payload and slice inside the function, instead of this.props.getLayer, this.props.payload and this.props.slice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of good educations here! Thanks!
The reason why I am making a copy of this.props.payload.data.features, mutating it, and then assigning it back to payload in line 107 is that if I understand correctly, changing in this.props will result in re-render. As we are only passing it to getLayer function and don't need it to be re-rendered, I copy it so props is unaffected and unnecessary re-render can be avoided. This is my understanding but I am not very sure whether it is correct based on your suggestion. Please correct me if I am wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well. I am wrong. Only state change will cause re-render.

@@ -40,17 +41,17 @@ function deckArc(slice, payload, setControlValue) {
};

if (fd.autozoom) {
viewport = common.fitViewport(viewport, getPoints(payload.data.arcs));
viewport = common.fitViewport(viewport, getPoints(payload.data.features));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you can use data here instead of payload.data.features.

Copy link
Contributor Author

@youngyjd youngyjd Aug 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems not. data is not defined in function deckArc(slice, payload, setControlValue){} so I feel using data here will not work. It is extracted in function getLayer(fd, payload, slice){} instead.

function getLayer(fd, payload, slice) {
  const data = payload.data.features;
  const sc = fd.color_picker;
  const tc = fd.target_color_picker;
  return new ArcLayer({
    id: `path-layer-${fd.slice_id}`,
    data,
    getSourceColor: d => d.sourceColor || d.color || [sc.r, sc.g, sc.b, 255 * sc.a],
    getTargetColor: d => d.targetColor || d.color || [tc.r, tc.g, tc.b, 255 * tc.a],
    strokeWidth: (fd.stroke_width) ? fd.stroke_width : 3,
    ...common.commonLayerProps(fd, slice),
  });
}

function deckArc(slice, payload, setControlValue) {
  const fd = slice.formData;
  let viewport = {
    ...fd.viewport,
    width: slice.width(),
    height: slice.height(),
  };

  if (fd.autozoom) {
    viewport = common.fitViewport(viewport, getPoints(payload.data.features));
  }
...
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right. I got confused by the hidden lines, my bad!

@youngyjd
Copy link
Contributor Author

Ready for another review @betodealmeida

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks! :)

@@ -40,17 +41,17 @@ function deckArc(slice, payload, setControlValue) {
};

if (fd.autozoom) {
viewport = common.fitViewport(viewport, getPoints(payload.data.arcs));
viewport = common.fitViewport(viewport, getPoints(payload.data.features));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right. I got confused by the hidden lines, my bad!

@betodealmeida betodealmeida merged commit 5437efa into apache:master Aug 29, 2018
youngyjd added a commit to lyft/incubator-superset that referenced this pull request Aug 30, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 11, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 11, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 11, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
youngyjd added a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
youngyjd added a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
youngyjd added a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
youngyjd added a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
youngyjd added a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Oct 29, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
youngyjd added a commit to lyft/incubator-superset that referenced this pull request Nov 2, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
youngyjd added a commit to lyft/incubator-superset that referenced this pull request Nov 2, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit

(cherry picked from commit 5437efa)
wenchma pushed a commit to wenchma/incubator-superset that referenced this pull request Nov 16, 2018
* Fix multilayer goeviz and color picker error

* fix lint

* remove props.data and improve merging list

* nit
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants