diff --git a/examples/sample.ts b/examples/sample.ts index 1e35fdcf4..a685579e4 100644 --- a/examples/sample.ts +++ b/examples/sample.ts @@ -1,4 +1,4 @@ -import { Style } from '../index'; +import { Fstep, Style } from '../index'; const sampleStyle: Style = { name: 'Sample Point Style', @@ -89,7 +89,27 @@ const sampleStyle: Style = { }, { kind: 'Mark', wellKnownName: 'ttf://Webdings#0x68', - radius: 12, + radius: { + name: 'step', + args: [ + { + name: 'property', + args: ['population'] + }, 5, + { + boundary: 1000, + value: 10 + }, + { + boundary: 10000, + value: 15 + }, + { + boundary: 100000, + value: 20 + } + ] + }, color: '#8a000e', strokeOpacity: 0.7, strokeColor: '#ffffff' diff --git a/functions.ts b/functions.ts index ccd7c34b0..bbfa8bc9c 100644 --- a/functions.ts +++ b/functions.ts @@ -10,6 +10,9 @@ export type GeoStylerFunction = GeoStylerNumberFunction | GeoStylerBooleanFunction | GeoStylerUnknownFunction; +/** + * An expression of a function that returns a number. + */ export type GeoStylerNumberFunction = GeoStylerUnknownFunction | Fabs | Facos | @@ -40,8 +43,12 @@ FstrLength | Fsub | Ftan | FtoDegrees | +FtoNumber | FtoRadians; +/** + * An expression of a function that returns a string. + */ export type GeoStylerStringFunction = GeoStylerUnknownFunction | FnumberFormat | FstrAbbreviate | @@ -54,8 +61,12 @@ FstrSubstring | FstrSubstringStart | FstrToLowerCase | FstrToUpperCase | -FstrTrim; +FstrTrim | +FtoString; +/** + * An expression of a function that returns a boolean. + */ export type GeoStylerBooleanFunction = GeoStylerUnknownFunction | Fall | Fany | @@ -73,9 +84,10 @@ FparseBoolean | FstrEndsWith | FstrEqualsIgnoreCase | FstrMatches | -FstrStartsWith; +FstrStartsWith | +FtoBoolean; -export type GeoStylerUnknownFunction = Fcase | Fproperty; +export type GeoStylerUnknownFunction = Fcase | Fstep | Fproperty; /** * The absolute value of the specified number value @@ -482,9 +494,30 @@ export interface Fsqrt extends FunctionCall { ]; }; +type FStepParameter = { + boundary: Expression; + value: Expression; +}; + +/** + * Returns an unknown value depending on the passed in value of argument[0]. In + * most cases this will be an {@link Fproperty}. + * The argument[1] is the initial value. + * All following arguments are an array of length 2 where the first element is + * a numeric value and the second element is the value to return if the value is + * larger than that boundry. + */ +export interface Fstep extends FunctionCall { + name: 'step'; + args: [ + Expression, Expression, + ...FStepParameter[] + ]; +}; + /** * Abbreviates the sentence (argument[0]) at first space beyond lower (argument[1]) - * or at upper (argument[2]) if no space.Appends append (argument[3]) if string is abbreviated. + * or at upper (argument[2]) if no space. Appends append (argument[3]) if string is abbreviated. */ export interface FstrAbbreviate extends FunctionCall { name: 'strAbbreviate'; @@ -707,6 +740,17 @@ export interface Ftan extends FunctionCall { ]; }; +/** + * Converts an unknown value to boolean + */ +export interface FtoBoolean extends FunctionCall { + name: 'toBoolean'; + args: [ + Expression + ]; +}; + + /** * Converts an angle expressed in radians into degrees */ @@ -717,6 +761,16 @@ export interface FtoDegrees extends FunctionCall { ]; }; +/** + * Converts an unknown value into a number + */ +export interface FtoNumber extends FunctionCall { + name: 'toNumber'; + args: [ + Expression + ]; +}; + /** * Converts an angle expressed in radians into degrees */ @@ -726,3 +780,13 @@ export interface FtoRadians extends FunctionCall { Expression ]; }; + +/** + * Converts an unknown value into a string + */ +export interface FtoString extends FunctionCall { + name: 'strToString'; + args: [ + Expression + ]; +};