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

Added support for multiple expressions with passing tests #5232

Merged
merged 10 commits into from
May 23, 2017

Conversation

Jane-Of-Art
Copy link
Contributor

@lilleyse @Dylan-Brown

Keys inside the expressions object and the key "expression" are now all used in parsing conditions.

Had a bit of trouble with having to learn and fix the new RegEx parsing, but it all works now!

@Jane-Of-Art
Copy link
Contributor Author

This is for Ticket #5153.

For now, the support is for ${key}, where the keys are case sensitive.

I haven't really thought about reserved expression names, especially since I don't know which ones are reserved. Since it looks like all reserved expressions are in full uppercase, one idea would be to standardize all keys in this spec to be .toLowerCase(). I would love your input on this issue!

@Jane-Of-Art
Copy link
Contributor Author

RE: New comments under original issue

I did indeed implement this as string replacement. Therefore, I guess this isn't really a performance improvement, but I think this feature still has value as a development tool / convenience tool, as it'll be much more convenient for developers to write conditions with multiple expressions .

* conditions : [
* ['${expression} === "1"', 'color("#FF0000")'],
* ['${expression} === "2"', 'color("#00FF00")'],
* ["(${id} !== 1) && (${Area} > 0)", "color('#0000FF')"],
* ['true', 'color("#FFFFFF")']
* ]
Copy link
Contributor

Choose a reason for hiding this comment

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

For clarity, remove the new line and use ${id} in the first condition and ${Area} in the second.

@@ -32,9 +30,14 @@ define([
* @example
* var expression = new Cesium.Expression({
* expression : 'regExp("^1(\\d)").exec(${id})',
* expressions : {
* id : "RegEx('^1(\\d)$').exec(${id})",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is technically valid if ${id} is a built-in tile property, but as an example it is confusing to see id reference ${id}. Maybe use ${name} instead.

(yeah... this was my example in #5153)

// Insert expression to expressions if it exists
// Then evaluate using expressions throughout class
// this._expression has to stay in prototype for specs to keep passing, but it can be removed in the future.
this._expression = conditionsExpression.expression;
Copy link
Contributor

Choose a reason for hiding this comment

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

As part of this PR can you remove any uses of _expression and also any styles that reference a single expression. We should only support the multiple-expression syntax.

// Then evaluate using expressions throughout class
// this._expression has to stay in prototype for specs to keep passing, but it can be removed in the future.
this._expression = conditionsExpression.expression;
this._expressions = conditionsExpression.expressions || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

We try to avoid this type of syntax, and also the allocation. Instead use defaultValue(conditionsExpression.expressions, defaultValue.EMPTY_OBJECT)

cond = cond.replace(expressionPlaceholder, 'undefined');
condExpression = condExpression.replace(expressionPlaceholder, 'undefined');

//Loop over all expressions for replacement instead of only replacing one
Copy link
Contributor

Choose a reason for hiding this comment

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

Shorten the description, just Loop over all expressions for replacement is fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also style note, change to // Loop


//Loop over all expressions for replacement instead of only replacing one
for (var key in expressions) {
if (expressions.hasOwnProperty((key))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unneeded parentheses.

for (var key in expressions) {
if (expressions.hasOwnProperty((key))) {
var expressionPlaceholder = new RegExp('\\$\\{' + key + '\\}', 'g');
if (defined(expressions[key])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Factor expressions[key] out into a variable.

@lilleyse
Copy link
Contributor

For now, the support is for ${key}, where the keys are case sensitive.

I haven't really thought about reserved expression names, especially since I don't know which ones are reserved. Since it looks like all reserved expressions are in full uppercase, one idea would be to standardize all keys in this spec to be .toLowerCase(). I would love your input on this issue!

This is probably the right approach. If a batch table property or built-in property (like POSITION) and expression happen to use the same name, precedence goes towards the expression.

@lilleyse
Copy link
Contributor

Looks great overall!

As just one extra thing can you edit one of the examples in 3D Tiles Point Cloud Styling or make a new example to use multiple expressions? Visual testing is always nice.

@pjcozzi
Copy link
Contributor

pjcozzi commented May 10, 2017

@Jane-Of-Art @lilleyse what is the plan here? Do we want to get this into 3d-tiles soon so we get that branch in shape for master?

@lilleyse lilleyse mentioned this pull request May 10, 2017
23 tasks
@pjcozzi
Copy link
Contributor

pjcozzi commented May 22, 2017

@lilleyse do you plan to finish this up?

@lilleyse
Copy link
Contributor

This was pretty close already, so I'm fine with finishing it up.

…me name. Build regex for expression keys rather than generic variable regex.
@lilleyse
Copy link
Contributor

@pjcozzi this is ready now.

@lilleyse
Copy link
Contributor

Spec issue: CesiumGS/3d-tiles#226

This is a breaking change for any styles that use the ${expression} inside a conditions list.

@pjcozzi
Copy link
Contributor

pjcozzi commented May 23, 2017

@pmconne heads up for this small breaking changing in the styling language: #5232 (comment)

Thanks again @Jane-Of-Art @lilleyse!

@pjcozzi pjcozzi merged commit 6761474 into CesiumGS:3d-tiles May 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants