-
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
Fix multilayer geoviz and color picker error #5767
Changes from 3 commits
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 |
---|---|---|
|
@@ -30,11 +30,11 @@ function getCategories(fd, data) { | |
|
||
const propTypes = { | ||
slice: PropTypes.object.isRequired, | ||
data: PropTypes.array.isRequired, | ||
mapboxApiKey: PropTypes.string.isRequired, | ||
setControlValue: PropTypes.func.isRequired, | ||
viewport: PropTypes.object.isRequired, | ||
getLayer: PropTypes.func.isRequired, | ||
payload: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default class CategoricalDeckGLContainer extends React.PureComponent { | ||
|
@@ -50,9 +50,9 @@ export default class CategoricalDeckGLContainer extends React.PureComponent { | |
const fd = nextProps.slice.formData; | ||
|
||
const timeGrain = fd.time_grain_sqla || fd.granularity || 'PT1M'; | ||
const timestamps = nextProps.data.map(f => f.__timestamp); | ||
const timestamps = nextProps.payload.data.features.map(f => f.__timestamp); | ||
const { start, end, step, values, disabled } = getPlaySliderParams(timestamps, timeGrain); | ||
const categories = getCategories(fd, nextProps.data); | ||
const categories = getCategories(fd, nextProps.payload.data.features); | ||
|
||
return { start, end, step, values, disabled, categories }; | ||
} | ||
|
@@ -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]; | ||
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. Here you're making a copy of let data = this.props.payload.data.features; And then as you mutate it, 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. Did some test and found it does not work. I guess it is because the location that This is part of the code:
If we change it to |
||
|
||
// Add colors from categories or fixed color | ||
data = this.addColor(data, fd); | ||
|
@@ -103,7 +103,9 @@ export default class CategoricalDeckGLContainer extends React.PureComponent { | |
data = data.filter(d => this.state.categories[d.cat_color].enabled); | ||
} | ||
|
||
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)]; | ||
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. 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 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. A lot of good educations here! Thanks! 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. well. I am wrong. Only state change will cause re-render. |
||
} | ||
toggleCategory(category) { | ||
const categoryState = this.state.categories[category]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ function getPoints(data) { | |
return points; | ||
} | ||
|
||
function getLayer(fd, data, slice) { | ||
function getLayer(fd, payload, slice) { | ||
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. Good catch, I simplified the |
||
const data = payload.data.features; | ||
const sc = fd.color_picker; | ||
const tc = fd.target_color_picker; | ||
return new ArcLayer({ | ||
|
@@ -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)); | ||
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: you can use 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. Seems not.
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. Oh, you're right. I got confused by the hidden lines, my bad! |
||
} | ||
|
||
ReactDOM.render( | ||
<CategoricalDeckGLContainer | ||
slice={slice} | ||
data={payload.data.arcs} | ||
mapboxApiKey={payload.data.mapboxApiKey} | ||
setControlValue={setControlValue} | ||
viewport={viewport} | ||
getLayer={getLayer} | ||
payload={payload} | ||
/>, | ||
document.getElementById(slice.containerId), | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,18 @@ function getPoints(data) { | |
return data.map(d => d.position); | ||
} | ||
|
||
function getLayer(fd, data, slice) { | ||
const dataWithRadius = data.map((d) => { | ||
function getLayer(fd, payload, slice) { | ||
const dataWithRadius = payload.data.features.map((d) => { | ||
let radius = unitToRadius(fd.point_unit, d.radius) || 10; | ||
if (fd.multiplier) { | ||
radius *= fd.multiplier; | ||
} | ||
return { ...d, radius }; | ||
if (d.color) { | ||
return { ...d, radius }; | ||
} | ||
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 }; | ||
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. Thanks for fixing this, I think I must've removed it by mistake. |
||
}); | ||
|
||
return new ScatterplotLayer({ | ||
|
@@ -49,11 +54,11 @@ function deckScatter(slice, payload, setControlValue) { | |
ReactDOM.render( | ||
<CategoricalDeckGLContainer | ||
slice={slice} | ||
data={payload.data.features} | ||
mapboxApiKey={payload.data.mapboxApiKey} | ||
setControlValue={setControlValue} | ||
viewport={viewport} | ||
getLayer={getLayer} | ||
payload={payload} | ||
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. Remove 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. Sure! make sense |
||
/>, | ||
document.getElementById(slice.containerId), | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2161,7 +2161,7 @@ def query_obj(self): | |
fd = self.form_data | ||
|
||
# add NULL filters | ||
if fd.get('filter_nulls'): | ||
if fd.get('filter_nulls', True): | ||
self.add_null_filters() | ||
|
||
d = super(BaseDeckGLViz, self).query_obj() | ||
|
@@ -2409,10 +2409,9 @@ def get_properties(self, d): | |
|
||
def get_data(self, df): | ||
d = super(DeckArc, self).get_data(df) | ||
arcs = d['features'] | ||
|
||
return { | ||
'arcs': arcs, | ||
'features': d['features'], | ||
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. +1 I think it's good to standardize on the key value here. |
||
'mapboxApiKey': config.get('MAPBOX_API_KEY'), | ||
} | ||
|
||
|
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.
Let's remove
data
from the props, since it can fetched from the payload.