Skip to content

Commit

Permalink
[update] methods, predicates sections updated
Browse files Browse the repository at this point in the history
  • Loading branch information
tbshag2 committed May 23, 2024
1 parent 24dd4b4 commit e8c8869
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/api/config/config-property.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The `config` parameters are used to define which fields will be applied as rows
- for numeric values: min, max, sum, count
- for text values: count
- for date value: min, max, count
Sum - sums all the values of the selected data property and displays the sum
Sum - sums all the values of the selected data property and displays the sum
Min - finds and displays the minimum value of the selected data property
Max - finds and displays the maximum value of the selected data property
Count - looks for all occurrences of the selected data property and displays their number; set by default for each newly added field
Expand Down
15 changes: 15 additions & 0 deletions docs/api/config/methods-property.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ Each method is represented by a key-value pair, where the `method` is the name o

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". There is no limit to the number of sub-properties that can be defined in the methods object.

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",
},
};
~~~

## 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
18 changes: 9 additions & 9 deletions docs/api/config/predicates-property.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ The following default predicates are applied in case no predicate is specified v

~~~jsx
const predicates = {
date: [
{ id: "$empty", label: "(date)" },
{ id: "year", label: "year" },
{ id: "month", label: "month" },
{ id: "day", label: "day" },
{ id: "hour", label: "hour" },
{ id: "minute", label: "minute" },
],
$empty: {
label: (v: any, type: any) => `raw ${type}`,
type: ["number", "date", "text"],
},
year: { label: "year", type: "date" },
month: { label: "month", type: "date" },
day: { label: "day", type: "date" },
hour: { label: "hour", type: "date" },
minute: { label: "minute", type: "date" },
};
~~~

Expand Down Expand Up @@ -90,7 +91,6 @@ const predicates = {
const widget = new pivot.Pivot("#pivot", {
fields,
data: dataset,
tableShape: { dateFormat: "%d %M %Y %H:%i" },
predicates: { ...pivot.defaultPredicates, ...predicates },
config: {
rows: ["state"],
Expand Down
18 changes: 15 additions & 3 deletions docs/guides/working-with-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,21 @@ The widget provides the following default methods for data aggregation:
- 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

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",
},
};
~~~

You can apply default methods using the `values` parameter of the [`config`](/api/config/config-property) property. See [Options for defining values](#options-for-defining-values) below.

Example:
Expand Down Expand Up @@ -715,7 +730,6 @@ const predicates = {
const widget = new pivot.Pivot("#pivot", {
fields,
data: dataset,
tableShape: { dateFormat: "%d %M %Y %H:%i" },
predicates: { ...pivot.defaultPredicates, ...predicates },
config: {
rows: ["state"],
Expand All @@ -730,8 +744,6 @@ const widget = new pivot.Pivot("#pivot", {
~~~




## Example

In this snippet you can see how to use Pivot API for working with data:
Expand Down

0 comments on commit e8c8869

Please sign in to comment.