Core
Package | Version | Downloads |
---|---|---|
@carto/react-core |
Set of common functions, to be used mostly by other packages. You won’t usually consume this package directly, but when using AggregationTypes
for widgets or when creating custom widgets.
Tip: The computations performed internally by widgets use these functions. They can be useful in the context of new custom widgets (for example using a different charting library)
Functions
aggregationFunctions
Contains a set of basic aggregation functions (count, min, max, sum, and average), used automatically for widgets and layers, see AggregationTypes. Functions are applicable to numbers and also objects using a numeric property.
Input:
Param | Type | Description |
---|---|---|
values |
| Array of numbers or objects with a numerical property |
[key] |
| (optional). When using objects, name of the property to use for calculations |
Returns:
Object
- An object with Aggregation functions, which keys are everyAggregationTypes
valuesExample:
groupValuesByColumn
Makes groups from features based in a column (keysColumn
) and applying an operation
to the numeric values in a predefined column (valuesColumn
).
Input:
Param | Type | Default | Description |
---|---|---|---|
data |
| Features for calculations (plain objects with properties) | |
valuesColumn |
| Quantitative column for grouping (the name of a numeric property in the object) | |
keysColumn |
| Qualitative column for grouping (the name of a string property in the object) | |
operation |
| Operation for groups calculations, see AggregationTypes |
Returns:
Array
- Grouped valuesExample:
histogram
Categorizes numeric values as a histogram from a set of features, having the option of just calculating the frequency (with COUNT operation) or an aggregated operation on the features inside the bin (e.g., SUM).
Input:
Param | Type | Description |
---|---|---|
features |
| Features for calculations (plain objects with properties) |
columnName |
| Quantitative column for calculations (the name of a number property in the object) |
ticks |
| Array of numbers to build intervals (eg 1, 5, 10 will defines 4 intervals: <1, 1 to 5, 5 to 10 and >10) |
operation |
| Operation for groups calculations, see AggregationTypes |
Returns:
Array
- Histogram data for each bin, derived from ticksExample:
scatterPlot
Receives an array of features and the properties that will be used for each axis, checks that properties are valid and returns a formatted array.
Input:
Param | Type | Description |
---|---|---|
features |
| Features |
xAxisColumn |
| Property containing values for the X axis. |
yAxisColumn |
| Property containing values for the Y axis. |
Returns:
Array
- Formatted array.Example:
Constants & enums
AggregationTypes
Enum for the different types of aggregations, available for widgets.
Options:
COUNT
SUM
AVG
MIN
MAX
Example:
Last updated