From e8c88690ae701aa619d82e43413003cfbf78338f Mon Sep 17 00:00:00 2001 From: tbshag2 Date: Thu, 23 May 2024 19:03:33 +0300 Subject: [PATCH] [update] methods, predicates sections updated --- docs/api/config/config-property.md | 2 +- docs/api/config/methods-property.md | 15 +++++++++++++++ docs/api/config/predicates-property.md | 18 +++++++++--------- docs/guides/working-with-data.md | 18 +++++++++++++++--- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/docs/api/config/config-property.md b/docs/api/config/config-property.md index 65c2117..fedb10b 100644 --- a/docs/api/config/config-property.md +++ b/docs/api/config/config-property.md @@ -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 diff --git a/docs/api/config/methods-property.md b/docs/api/config/methods-property.md index 5db6652..4f57b47 100644 --- a/docs/api/config/methods-property.md +++ b/docs/api/config/methods-property.md @@ -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. diff --git a/docs/api/config/predicates-property.md b/docs/api/config/predicates-property.md index 1864de5..9eb56f3 100644 --- a/docs/api/config/predicates-property.md +++ b/docs/api/config/predicates-property.md @@ -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" }, }; ~~~ @@ -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"], diff --git a/docs/guides/working-with-data.md b/docs/guides/working-with-data.md index 0319b3f..c016207 100644 --- a/docs/guides/working-with-data.md +++ b/docs/guides/working-with-data.md @@ -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: @@ -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"], @@ -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: