-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add projection expression syntax #888
Changes from 105 commits
9f0d5ee
596c048
56a04f3
2611016
8c34a52
7bcf2e7
931fc9a
3b87d0b
88422ab
81b441a
3f1a371
a569723
949e72c
52343f0
dd5af6f
4c8b8d5
d3717bf
dc4e463
208afe2
728469d
f7c458f
88dda3a
ce97699
f901a50
efcee2c
6341baf
d2d755d
b80a150
53b098e
8a95673
9ef606f
c799991
a74a812
695aa90
743282e
483c8e0
fcbf835
7548e99
87ec0ec
387f092
765c1a9
8e4eb9c
eed2fc1
69e89b7
ba4a001
eaa3f76
fda7d78
408fdc0
1c9e17a
6781b91
8e6f991
edae354
87af425
15ec25d
6da6683
7151547
6598bad
3e89e84
8d46eb1
6432a67
e11e196
fc5b33c
b68e386
9beb898
969891c
fe8e4c7
553a260
e18f8fa
439a9d2
feee50f
6ad8f4f
d1ce5fb
745ec3d
d2e39ad
9a40ded
9b4d843
dda0295
005975e
ceb0719
277b82f
38d9bc9
197c39d
31f91ee
ee5fb2f
51c1ae9
70a7f6d
d28b9b4
5897a8f
74337e6
d60f2cc
b4a73ef
0d0d787
af6cd97
8f3797b
b7c3057
f86e2de
c7dfd0a
deb0a79
3dbf359
0a7773a
1ac110f
77d042b
0c47edd
e51272b
6bbb342
6c987db
58150bd
a4fd843
dda14b5
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import UnitBezier from '@mapbox/unitbezier'; | ||
|
||
import interpolate from '../../util/interpolate'; | ||
import {array, ArrayType, ColorType, ColorTypeT, NumberType, NumberTypeT, PaddingType, PaddingTypeT, VariableAnchorOffsetCollectionType, VariableAnchorOffsetCollectionTypeT, toString, verifyType} from '../types'; | ||
import {array, ArrayType, ColorType, ProjectionTypeT, ColorTypeT, NumberType, NumberTypeT, PaddingType, PaddingTypeT, VariableAnchorOffsetCollectionType, VariableAnchorOffsetCollectionTypeT, toString, verifyType, ProjectionType} from '../types'; | ||
import {findStopLessThanOrEqualTo} from '../stops'; | ||
|
||
import type {Stops} from '../stops'; | ||
|
@@ -19,18 +19,18 @@ export type InterpolationType = { | |
name: 'cubic-bezier'; | ||
controlPoints: [number, number, number, number]; | ||
}; | ||
type InterpolatedValueType = NumberTypeT | ColorTypeT | PaddingTypeT | VariableAnchorOffsetCollectionTypeT | ArrayType<NumberTypeT>; | ||
|
||
type InterpolatedValueType = NumberTypeT | ColorTypeT | ProjectionTypeT | PaddingTypeT | VariableAnchorOffsetCollectionTypeT | ArrayType<NumberTypeT>; | ||
type InterpolationOperator = 'interpolate' | 'interpolate-hcl' | 'interpolate-lab' | 'interpolate-projection'; | ||
class Interpolate implements Expression { | ||
type: InterpolatedValueType; | ||
|
||
operator: 'interpolate' | 'interpolate-hcl' | 'interpolate-lab'; | ||
operator: InterpolationOperator ; | ||
interpolation: InterpolationType; | ||
input: Expression; | ||
labels: Array<number>; | ||
outputs: Array<Expression>; | ||
|
||
constructor(type: InterpolatedValueType, operator: 'interpolate' | 'interpolate-hcl' | 'interpolate-lab', interpolation: InterpolationType, input: Expression, stops: Stops) { | ||
constructor(type: InterpolatedValueType, operator: InterpolationOperator, interpolation: InterpolationType, input: Expression, stops: Stops) { | ||
this.type = type; | ||
this.operator = operator; | ||
this.interpolation = interpolation; | ||
|
@@ -108,6 +108,8 @@ class Interpolate implements Expression { | |
let outputType: Type = null; | ||
if (operator === 'interpolate-hcl' || operator === 'interpolate-lab') { | ||
outputType = ColorType; | ||
} else if (operator === 'interpolate-projection') { | ||
outputType = ProjectionType; | ||
} else if (context.expectedType && context.expectedType.kind !== 'value') { | ||
outputType = context.expectedType; | ||
} | ||
|
@@ -135,6 +137,7 @@ class Interpolate implements Expression { | |
|
||
if (!verifyType(outputType, NumberType) && | ||
!verifyType(outputType, ColorType) && | ||
!verifyType(outputType, ProjectionType) && | ||
!verifyType(outputType, PaddingType) && | ||
!verifyType(outputType, VariableAnchorOffsetCollectionType) && | ||
!verifyType(outputType, array(NumberType)) | ||
|
@@ -170,6 +173,10 @@ class Interpolate implements Expression { | |
|
||
const outputLower = outputs[index].evaluate(ctx); | ||
const outputUpper = outputs[index + 1].evaluate(ctx); | ||
|
||
if (this.type.kind == 'projection') { | ||
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. I think this can be added to the below switch-case? 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 type guard on switch (this.operator) {
case 'interpolate':
if (this.type.kind !== 'projection') {
return interpolate[this.type.kind](outputLower, outputUpper, t);
}
case 'interpolate-hcl':
return interpolate.color(outputLower, outputUpper, t, 'hcl');
case 'interpolate-lab':
return interpolate.color(outputLower, outputUpper, t, 'lab');
case 'interpolate-projection': {
return interpolate.projection(outputLower, outputUpper, t);
}
}
``` 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. 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. 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. case 'interpolate':
return interpolate[this.type.kind.toString()](outputLower, outputUpper, t);
case 'interpolate-hcl':
return interpolate.color(outputLower, outputUpper, t, 'hcl'); A 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. I think this removes the type guard from the 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 is an option too, that doesn't ignore any types switch (this.operator) {
case 'interpolate':
switch (this.type.kind) {
case 'number':
return interpolate.number(outputLower, outputUpper, t);
case 'color':
return interpolate.color(outputLower, outputUpper, t, 'rgb');
case 'array':
return interpolate.array(outputLower, outputUpper, t);
case 'padding':
return interpolate.padding(outputLower, outputUpper, t);
case 'variableAnchorOffsetCollection':
return interpolate.variableAnchorOffsetCollection(outputLower, outputUpper, t);
}
case 'interpolate-hcl':
return interpolate.color(outputLower, outputUpper, t, 'hcl');
case 'interpolate-lab':
return interpolate.color(outputLower, outputUpper, t, 'lab');
case 'interpolate-projection': {
return interpolate.projection(outputLower, outputUpper, t);
}
} 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. I like this one better to be honest. 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. By the way, if this is possible for other types, why do we need an extra case for interpolate-projection then? |
||
return interpolate.projection(outputLower, outputUpper, t); | ||
} | ||
|
||
switch (this.operator) { | ||
case 'interpolate': | ||
|
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 this really needed here?
This is used for the docs to allow link to an object type related to the expressions I think, and I'm not sure projectionConfig can be a return type of an expression, 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.
This is an overwrite I made so that the url of the main Projection page doesn't get a /projectionConfig url, which I thought was undesirable, compared to staying with /projection. I can let it generate the /projectionConfig if preferred.
This is the warning I got on mkdocs-build, when it makes the root pages from the v8, before I added it:
WARNING - Doc file 'root.md' contains a link 'projectionConfig.md', but the target is not found among documentation files.
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.
Ah, I see...
I'm trying to think if there's a way to solve this elegantly, but I can't think of a good idea at the moment.
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'm not sure this is a good idea, but in proj4js they use the term
ProjectionDefinition
for the values related to the projection:https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/proj4/index.d.ts
I'm not sure what I think about it though - this is for the "internal" type, the one used in the expressions, not the root projection type.