Skip to content

Commit

Permalink
feat: add new functions
Browse files Browse the repository at this point in the history
FtoString, FtoNumber, FtoBoolean, Fstep
  • Loading branch information
KaiVolland committed Jun 18, 2024
1 parent a0b5002 commit b15e97f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 6 deletions.
24 changes: 22 additions & 2 deletions examples/sample.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Style } from '../index';
import { Fstep, Style } from '../index';

const sampleStyle: Style = {
name: 'Sample Point Style',
Expand Down Expand Up @@ -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'
Expand Down
72 changes: 68 additions & 4 deletions functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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 |
Expand All @@ -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 |
Expand All @@ -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
Expand Down Expand Up @@ -482,9 +494,30 @@ export interface Fsqrt extends FunctionCall<number> {
];
};

type FStepParameter = {
boundary: Expression<number>;
value: Expression<PropertyType>;
};

/**
* 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<unknown> {
name: 'step';
args: [
Expression<number>, Expression<PropertyType>,
...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<string> {
name: 'strAbbreviate';
Expand Down Expand Up @@ -707,6 +740,17 @@ 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 All @@ -717,6 +761,16 @@ export interface FtoDegrees extends FunctionCall<number> {
];
};

/**
* Converts an unknown value into a number
*/
export interface FtoNumber extends FunctionCall<number> {
name: 'toNumber';
args: [
Expression<unknown>
];
};

/**
* Converts an angle expressed in radians into degrees
*/
Expand All @@ -726,3 +780,13 @@ export interface FtoRadians extends FunctionCall<number> {
Expression<number>
];
};

/**
* Converts an unknown value into a string
*/
export interface FtoString extends FunctionCall<string> {
name: 'strToString';
args: [
Expression<unknown>
];
};

0 comments on commit b15e97f

Please sign in to comment.