-
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
Improvements to the polygon spatial viz #6178
Conversation
const DOUBLE_CLICK_TRESHOLD = 250; // milliseconds | ||
|
||
function getElevation(d, colorScaler) { | ||
/* in deck.gl, if a polygon has opacity zero it will make everything behind |
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: this looks like a deck.gl bug to me, we may want to comment more precisely: in deck.gl version x.x.x (used in Superset as of 2018-10-12), ...
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.
(y)
@@ -2319,15 +2319,19 @@ class DeckPathViz(BaseDeckGLViz): | |||
viz_type = 'deck_path' | |||
verbose_name = _('Deck.gl - Paths') | |||
deck_viz_key = 'path' | |||
is_timeseries = True |
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.
I think you'll want the control override time_grain_sqla: timeGrainSqlaAnimationOverrides
in visTypes.jsx
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.
Thanks, will add!
superset/viz.py
Outdated
@@ -2347,8 +2351,14 @@ def get_properties(self, d): | |||
d[self.deck_viz_key] = path | |||
if line_type != 'geohash': | |||
del d[line_column] | |||
d['metric'] = d.get(self.metric_label) |
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.
Does that do anything? I thought the query_obj
only took metrics
as an arg (?)
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.
It's leftover, will remove.
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.
A few minor comments, otherwise looks great!
return fd.break_points.sort((a, b) => parseFloat(a) - parseFloat(b)); | ||
} | ||
|
||
export function hexToRGB(hex, alpha = 255) { |
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.
There is already a hexToRGB
function in colors.js
.
Why create a new copy here?
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.
I think it got duplicated because of refactoring. Will remove this one.
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.
It seems like only deck.gl components are using hexToRGB
so you can consider moving it here too. I may try to refactor and deprecate colors.js
in the near term.
let scaler; | ||
let maskPoint; | ||
if (breakPoints !== null) { | ||
// bucket colors into discrete colors |
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.
There is d3.scale.quantize()
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.
I looked at it and it didn't work in this case because we want to quantize into buckets of different widths (eg, 0-10
and 10-100
).
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.
got it.
import Legend from '../../../Legend'; | ||
import { getBuckets, getBreakPointColorScaler } from '../../utils'; | ||
|
||
import * as common from '../common'; |
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.
better import specific functions import { fn }
than import *
to fully benefit from tree-shaking.
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.
Definitely, will fix.
import getSequentialSchemeRegistry from '../../modules/colors/SequentialSchemeRegistrySingleton'; | ||
import { colorScalerFactory } from '../../modules/colors'; | ||
|
||
export function getBreakPoints(fd, features) { |
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.
I would strongly recommend listing out the fields you need for this function than the ambiguous fd
. This will make it clearer what are needed for this function to work.
export function getBreakPoints({
break_points,
metric,
num_buckets,
}, features) {
}
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.
Cool, will do that. Thanks!
return [r, g, b, alpha]; | ||
} | ||
|
||
export function getBreakPointColorScaler(fd, features) { |
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.
Same issue with fd
as above.
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.
(y)
Codecov Report
@@ Coverage Diff @@
## master #6178 +/- ##
==========================================
+ Coverage 76.91% 76.93% +0.01%
==========================================
Files 47 47
Lines 9362 9386 +24
==========================================
+ Hits 7201 7221 +20
- Misses 2161 2165 +4
Continue to review full report at Codecov.
|
LGTM! |
* WIP * WIP * WIP * WIP * Fix color bucketing * Fixed colors * Fix no num categories selected * Colors working * Fix no metric selected * Visual cues for selection * Add unit tests * Remove jest from deps * Rename category to bucket * Small fixes * Fix lint * Fix unit tests * Remove duplicate hexToRGB * Fix import * Change order of arguments in getBuckets * Refactor function signature (cherry picked from commit f1089c4)
* WIP * WIP * WIP * WIP * Fix color bucketing * Fixed colors * Fix no num categories selected * Colors working * Fix no metric selected * Visual cues for selection * Add unit tests * Remove jest from deps * Rename category to bucket * Small fixes * Fix lint * Fix unit tests * Remove duplicate hexToRGB * Fix import * Change order of arguments in getBuckets * Refactor function signature (cherry picked from commit f1089c4) (cherry picked from commit 699813f)
* WIP * WIP * WIP * WIP * Fix color bucketing * Fixed colors * Fix no num categories selected * Colors working * Fix no metric selected * Visual cues for selection * Add unit tests * Remove jest from deps * Rename category to bucket * Small fixes * Fix lint * Fix unit tests * Remove duplicate hexToRGB * Fix import * Change order of arguments in getBuckets * Refactor function signature
Many improvements to the polygon spatial viz, ported from the (private) ZIP code viz:
Legend for the heatmap
When a metric is selected, we can optionally show a legend mapping values to colors. This uses the same
<Legend>
component used for showing/toggling categories:Bucketing data into groups
By default the legend shows 10 buckets, and the colors are linearly interpolated. It's possible to specify a different number of buckets, eg:
It's also possible to explicitly define the break points:
Anything outside the break points is masked out with opacity 0.
Map elevation to a secondary metric
It's now possible to represent elevation using a secondary metric, and users can also specify a multiplier for the elevation:
Play slider
The polygon spatial viz now can be animated using the play slider. Note that the CSS is broken in master — I'll fix that in a separate PR.
Toggling polygons
It's now possible to toggle polygons when sending events, when the "Multiple filtering" control is enabled. This allows the user to select multiple polygons and filter another chart accordingly:
(It also works when "extrude" is false and the viz has no elevation.)