Skip to content

Commit

Permalink
[update] info about new maths operations added
Browse files Browse the repository at this point in the history
  • Loading branch information
tbshag2 committed Jun 4, 2024
1 parent 25b3d8d commit afe3dce
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 40 deletions.
43 changes: 31 additions & 12 deletions docs/api/config/methods-property.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ description: You can learn about the methods config in the documentation of the
label?:string,
handler?: (values: number[]|string[]|Date[]) => any,
branchMode?: "raw"|"result",
branchMath?: string,
branchMath?: string
},
};
~~~
Expand All @@ -35,24 +35,43 @@ Each method is represented by a key-value pair, where the `method` is the name o
- `branchMode` - (optional) defines the mode for the calculation of total values for the tree table; the branchMode can be set to `raw` for calculation based on all raw data; `result` (default) is set for calculation based on already processed data in the tree mode
- `branchMath` - (optional) the name of a method to calculate total values in the tree mode; the same as the method name by default (for "max" method branchMath is also "max")

By default, the `methods` property is an empty object {}, which means that no custom methods are defined. There are 5 predefined methods: "sum", "min", "max", "count", "average". TBD ADD MORE!!! There is no limit to the number of sub-properties that can be defined in the methods object.
By default, the `methods` property is an empty object {}, which means that no custom methods are defined. There is no limit to the number of sub-properties that can be defined in the methods object.

Predefined methods:

~~~jsx
const defaultMethods = {
sum: { label: "sum" },
min: { type: ["number", "date"], label: "min" },
max: { type: ["number", "date"], label: "max" },
count: {
type: ["number", "date", "text"],
label: "count",
branchMath: "sum",
},
average: { type: "number", label: "average", branchMode: "raw" },
defaultMethods = {
sum: { type: "number", label: "sum" },
min: { type: ["number", "date"], label: "min" },
max: { type: ["number", "date"], label: "max" },
count: {
type: ["number", "date", "text"],
label: "count",
branchMath: "sum",
},
counta: {
type: ["number", "date", "text"],
label: "counta",
branchMath: "sum",
},
countunique: {
type: ["number", "text"],
label: "countunique",
branchMath: "sum",
},
average: { type: "number", label: "average", branchMode: "raw" },
median: { type: "number", label: "median", branchMode: "raw" },
product: { type: "number", label: "product" },
stdev: { type: "number", label: "stdev", branchMode: "raw" },
stdevp: { type: "number", label: "stdevp", branchMode: "raw" },
var: { type: "number", label: "var", branchMode: "raw" },
varp: { type: "number", label: "varp", branchMode: "raw" },
};
~~~

The definition of each method you can see here: [Applying methods](/guides/working-with-data#default-methods)


## Example

The example below shows how to calculate the exact count of unique values. The function takes an array of numbers (values) as an input and calculates the exact count of unique values using the **reduce** method. The **distinct_count** sub-property has a handler with a function that calculates the distinct count value from an array of numbers.
Expand Down
5 changes: 1 addition & 4 deletions docs/guides/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@ pivotWidget.api.on("render-table", (tableConfig) => {
});
~~~




### Switching to the tree mode

The widget allows presenting data in a hierarchical format with expandable rows. To switch to the tree mode, apply the `tree` parameter of the [`tableShape`](/api/config/tableshape-property) property by setting its value to **true** (default is **false**).
Expand Down Expand Up @@ -385,7 +382,7 @@ const widget = new pivot.Pivot("#pivot", {

To enable generating the rightmost column with total values, apply the [`tableShape`](/api/config/tableshape-property) property and set the value of the `totalColumn` parameter to **true**.

To enable generating the bottom row with total, apply the [`tableShape`](/api/config/tableshape-property)property and set the value of the `totalRow` parameter to **true**.
To enable generating the footer with total, apply the [`tableShape`](/api/config/tableshape-property)property and set the value of the `totalRow` parameter to **true**.

Example:

Expand Down
71 changes: 47 additions & 24 deletions docs/guides/working-with-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,25 +480,48 @@ const pivotWidget = new pivot.Pivot("#pivot", {

The widget provides the following default methods for data aggregation:

- Sum (for numeric values only) - sums all the values of the selected data property and displays the sum
- Min (for numeric and date values)- finds and displays the minimum value of the selected data property
- Max (for numeric and date values) - finds and displays the maximum value of the selected data property
- Count (for numeric, text, and date values) - looks for all occurrences of the selected data property and displays their number; this is the default operation assigned to each newly added field
- Average (for numeric values only) - calculates the average value of an array
- sum (for numeric values only) - sums all the values of the selected data property and displays the sum
- min (for numeric and date values)- finds and displays the minimum value of the selected data property
- max (for numeric and date values) - finds and displays the maximum value of the selected data property
- count (for numeric, text, and date values) - looks for all occurrences of the selected data property and displays their number; this is the default operation assigned to each newly added field
- average (for numeric values only) - calculates the average value of an array
- counta (for numeric, text, and date values) - counts the number of cells in a range that are not empty
- median (for numeric values only) - calculates the median of an expression (middle value in a sorted data set), which separates the higher half in a distribution from the lower half
- product (for numeric values only) - calculates the product of all numbers in a given range
- stdev (for numeric values only) - calculates the standard deviation of a sample, which measures the amount of variation or dispersion of a set of values; quantifies the amount of variation or dispersion of a set of values
- stdevp (for numeric values only) - similar to stdev, but this calculates the standard deviation of a population
- var (for numeric values only) - calculates the variance of a sample, which measures how much each number in the set differs from the mean (average) and then squares that value
- varp (for numeric values only) - similar to var, but this calculates the variance of a population

Predefined methods:

~~~jsx
const methods = {
sum: { label: "sum" },
min: { type: ["number", "date"], label: "min" },
max: { type: ["number", "date"], label: "max" },
count: {
type: ["number", "date", "text"],
label: "count",
branchMath: "sum",
},
average: { type: "number", label: "average", branchMode: "raw" },
defaultMethods = {
sum: { type: "number", label: "sum" },
min: { type: ["number", "date"], label: "min" },
max: { type: ["number", "date"], label: "max" },
count: {
type: ["number", "date", "text"],
label: "count",
branchMath: "sum",
},
counta: {
type: ["number", "date", "text"],
label: "counta",
branchMath: "sum",
},
countunique: {
type: ["number", "text"],
label: "countunique",
branchMath: "sum",
},
average: { type: "number", label: "average", branchMode: "raw" },
median: { type: "number", label: "median", branchMode: "raw" },
product: { type: "number", label: "product" },
stdev: { type: "number", label: "stdev", branchMode: "raw" },
stdevp: { type: "number", label: "stdevp", branchMode: "raw" },
var: { type: "number", label: "var", branchMode: "raw" },
varp: { type: "number", label: "varp", branchMode: "raw" },
};
~~~

Expand All @@ -516,7 +539,7 @@ const widget = new pivot.Pivot("#pivot", {
values: [
{
//field id
id: "title",
field: "title",
//method
method: "count",
},
Expand All @@ -533,14 +556,14 @@ const widget = new pivot.Pivot("#pivot", {

You can define `values`in either of the two equally valid ways:
- option one is a string representing a data field ID: `operation(fieldID)`
- option two is an object containing the field ID and the method for data aggregation: `{ id: string, method?: string }`
- option two is an object containing the field ID and the method for data aggregation: `{ field: string, method?: string }`

Example:

~~~jsx
values: [
"sum(sales)", // option one
{ id: "sales", method: "sum" }, // option two
{ field: "sales", method: "sum" }, // option two
],
~~~

Expand All @@ -559,11 +582,11 @@ const widget = new pivot.Pivot("#pivot", {
columns: [],
values: [
{
id: "title",
field: "title",
method: "count",
},
{
id: "score",
field: "score",
method: "max",
},
],
Expand Down Expand Up @@ -693,11 +716,11 @@ const widget = new pivot.Pivot("#pivot", {
config: {
rows: ["state"],
columns: [
{ id: "date", method: "year" },
{ id: "date", method: "monthYear" },
{ id: "profit", method: "balanceSign" },
{ field: "date", method: "year" },
{ field: "date", method: "monthYear" },
{ field: "profit", method: "balanceSign" },
],
values: [{ id: "sales", method: "sum" }],
values: [{ field: "sales", method: "sum" }],
},
});
~~~
Expand Down

0 comments on commit afe3dce

Please sign in to comment.