Skip to content

Commit

Permalink
Merge pull request #632 from jansule/interpolate
Browse files Browse the repository at this point in the history
feat: add interpolate function
  • Loading branch information
jansule authored Jun 21, 2024
2 parents 646db55 + ac4a927 commit cecc3dc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
46 changes: 33 additions & 13 deletions functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Fcos |
Fdiv |
Fexp |
Ffloor |
Finterpolate |
Flog |
Fmax |
Fmin |
Expand Down Expand Up @@ -84,8 +85,7 @@ FparseBoolean |
FstrEndsWith |
FstrEqualsIgnoreCase |
FstrMatches |
FstrStartsWith |
FtoBoolean;
FstrStartsWith;

export type GeoStylerUnknownFunction = Fcase | Fstep | Fproperty;

Expand Down Expand Up @@ -740,17 +740,6 @@ export interface Ftan extends FunctionCall<number> {
];
};

/**
* Converts an unknown value to boolean
*/
export interface FtoBoolean extends FunctionCall<boolean> {
name: 'toBoolean';
args: [
Expression<unknown>
];
};


/**
* Converts an angle expressed in radians into degrees
*/
Expand Down Expand Up @@ -790,3 +779,34 @@ export interface FtoString extends FunctionCall<string> {
Expression<unknown>
];
};

export type FInterpolateTypeLinear = {
name: 'linear';
};

export type FInterpolateType = FInterpolateTypeLinear;

export type FInterpolateParameter = {
stop: Expression<number>;
value: Expression<PropertyType>;
};

/**
* Textual representation of a interpolate function.
* argument[0] is the interpolation type.
* argument[1] is the input value.
* argument[2] - argument[args.length] are objects with 'stop' and 'value'.
*
* Will produce continuous results by interpolating between pairs
* of FInterpolateParamters.
*/
export interface Finterpolate extends FunctionCall<number> {
name: 'interpolate';
args: [
FInterpolateType,
Expression<number>,
FInterpolateParameter,
FInterpolateParameter,
...FInterpolateParameter[]
];
};
4 changes: 4 additions & 0 deletions typeguards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export const isGeoStylerNumberFunction = (got: any): got is GeoStylerNumberFunct
'div',
'exp',
'floor',
'interpolate',
'log',
'max',
'min',
Expand All @@ -221,6 +222,7 @@ export const isGeoStylerNumberFunction = (got: any): got is GeoStylerNumberFunct
'sub',
'tan',
'toDegrees',
'toNumber',
'toRadians'
];
return functionNames.includes(got?.name);
Expand All @@ -238,6 +240,7 @@ export const isGeoStylerStringFunction = (got: any): got is GeoStylerStringFunct
'strSubstring',
'strSubstringStart',
'strToLowerCase',
'strToString',
'strToUpperCase',
'strTrim'
];
Expand Down Expand Up @@ -271,6 +274,7 @@ export const isGeoStylerUnknownFunction = (got: any): got is GeoStylerUnknownFun
const functionNames: GeoStylerUnknownFunction['name'][] = [
'case',
'property',
'step'
];
return functionNames.includes(got?.name);
};
Expand Down

0 comments on commit cecc3dc

Please sign in to comment.