-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Conversation
Could you also add a |
71c779e
to
ec425ff
Compare
Noting here that I would prefer doing expression filter support as tailwork. Would love to get some feedback on this PR first before moving forward on that. This PR is ready for review. |
👍, especially since expression-based filters are still to be done in core |
ec425ff
to
98597e1
Compare
Ok, that explains a couple of things :) I initially thought I had to wire those up myself but now seeing that |
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.
Looks great!
public class Expression { | ||
|
||
private final String operator; | ||
private final Object[] values; |
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.
The word "value" gets so easily overloaded -- would it make sense to call this arguments
, which is how we refer to them in the style spec as well?
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.
Intuitively, I'd have expected this to be Expression[]
rather than Object[]
. I'm guessing it's Object[]
so that string/number/boolean literals can be used directly?
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.
Yes, that is correct, capturing from chat that I will look into the feasibility to use something as Expression instead.
*/ | ||
public static Expression var(Object... expressions) { | ||
return new Expression("var", expressions); | ||
} |
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.
The variable name argument must be a string literal -- it can't be a subexpression -- so it might make sense to remove this overload.
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.
can the string literal come from another expression?
eg.
var(get("featureKey"))
If that is the case I will remove the varargs approach and expose the following:
- var(Expression expression)
- var(String string)
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.
Nope -- "literal" here means it can't be the output of an expression, but has to be a string directly.
* @param stops pair of input and output values | ||
* @return expression | ||
*/ | ||
public static Expression step(Expression expression, Object... stops) { |
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.
Maybe rename expression
to input
for consistency with docs?
* @param stops pair of input and output values | ||
* @return expression | ||
*/ | ||
public static Expression interpolate(Expression interpolation, Number number, Object... stops) { |
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.
Similar to step: maybe rename number
to input
?
* @param stops pair of input and output values | ||
* @return expression | ||
*/ | ||
public static Expression interpolate(Expression interpolation, Expression number, Object... stops) { |
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 could see the case for creating a separate Interpolation
type for the first argument here. (So linear()
, exponential()
, and cubicBezier()
would return an Interpolation
value.) Not sure whether it's actually better to do so, just mentioning it as an alternative.
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.
One benefit of doing it that way is that users couldn't do something weird like sum(linear(), 2)
. As it stands now, if they did this, they'd get an error message that linear
is an unknown expression operator -- which might be confusing to them, since the linear()
method claims to produce an expression.
@@ -27,9 +28,17 @@ public void setProperties(@NonNull PropertyValue<?>... properties) { | |||
for (PropertyValue<?> property : properties) { | |||
Object converted = convertValue(property.value); | |||
if (property instanceof PaintPropertyValue) { | |||
nativeSetPaintProperty(property.name, converted); | |||
if(converted instanceof Expression) { |
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.
Could this be part of convertValue()
? (And space between if
and (
)
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.
wow, don't know how I could have missed that
98597e1
to
49af916
Compare
* | ||
* @param <T> | ||
*/ | ||
private static class ExpressionValue<T> extends Expression<T> { |
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.
ExpressionLiteral might be a better name for this class.
* a combination of the zoom level and individual feature properties. | ||
* </p> | ||
*/ | ||
public class Expression<T> { |
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.
Document <T>
*/ | ||
public class Expression<T> { | ||
|
||
private String operator; |
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.
Can both be final so that the object is immutable?
private String operator; | ||
private Expression[] arguments; | ||
|
||
Expression() { |
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.
Not used except by the subclass? If it initializes the members to null
, the object can be immutable
*/ | ||
private static class ExpressionValue<T> extends Expression<T> { | ||
|
||
private Object object; |
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.
Should this be <T>
instead of Object
?
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.
yes this should be enforced
* @param expression an expression to convert to a color | ||
* @return expression | ||
*/ | ||
public static Expression toRgba(Expression<Color> expression) { |
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.
Missing generic specifier (<Color>
) on return type?
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.
Correct about missing specifier, this case it should be <Array>
shown in style spec with ["to-rgba", color]: array<number, 4>)
.
* @param input boolean input | ||
* @return expression | ||
*/ | ||
public static Expression<Boolean> not(Boolean input) { |
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.
should this be boolean
instead? Otherwise, we should indicate nullability restrictions
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.
correct, all boolean input should primitive
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.
also went through the api and applied @NonNull
were needed
* @param expression an expression object or expression string | ||
* @return expression | ||
*/ | ||
public static Expression<Number> length(Expression expression) { |
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.
Is it preferable to use Expression<?>
over Expression
here?
* @param operator the expression operator | ||
* @param arguments expressions input | ||
*/ | ||
public Expression(@NonNull String operator, @Nullable Expression... arguments) { |
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.
Should we use @Size(min=1)
on varargs 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.
There are cases where the size may be 0, eg: ["pi"]: number
or ["properties"]: object
. I wasn't aware of this annotation, will try using it in other varargs occurrences in the class.
f57fde0
to
f408c00
Compare
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.
Some commented code can be removed. Otherwise 👍
) | ||
)); | ||
); |
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.
To be removed right?
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.
done
} else if (item.getItemId() == R.id.menu_action_filter) { | ||
SymbolLayer layer = mapboxMap.getLayerAs(LAYER_ID); | ||
layer.setFilter(Filter.eq(FEATURE_RANK, 1)); | ||
//layer.setFilter(eq(get(FEATURE_RANK), 1)); |
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.
To be removed?
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.
done
f408c00
to
862eaa0
Compare
This PR adds binding integration for expressions from #9439
Symbol layer example:
Todo:
Closes #9803
cc @mapbox/android @anandthakker