Grouping In Essential Chart
The grouping engine encapsulates the Essential Grouping architecture.
Users set an IList data source to impose multicolumn sorts, filters, grouping with summaries, and nested tables.
Essential Grouping uses balanced binary trees as a core data structure instead of arrays.
Binary trees have the advantage that parent branches can cache information about their children.
Inserting, removing, and moving records only takes O(log2n) operations instead of the O(n) operations with linear data structures.
Users can access the engine using their own code.
Essential Grouping has no UI dependencies. It may be used with any UI controls or no controls at all.
The following examples illustrate Essential Grouping in use with standard controls.
GridView Statistics Tied to Labels via Essential Grouping
The image above illustrates an ASP.NET GridView control and several labels on a page.
The labels display statistics based on the values in the grid view.
As users edit items or delete rows in the grid view, the labels automatically maintain the proper values through the grouping engine.
The program inserts random numbers into a data-table object that has been set as the data source of a grouping engine object.
This means that the engine is dynamically monitoring the numbers and maintaining the statistics as each new item is added to the collection.
Using Essential Grouping is straightforward.
You specify a data source or IList object with public properties to the Essential Grouping engine.
The following code sample shows the process.
Initialization Code for Using Essential Grouping
Once the engine is initialized, it is possible to sort, filter, group, and summarize data using straightforward code.
Once the tracking items are set up (provided the data source supports IBindingList), the engine will automatically maintain the information being tracked.
It can then be accessed through collections in the engine. The following image illustrates simple data that has been grouped by column C.
There are three lists, the raw data, the visible data before an ExpandAll call, and finally, the visible data after the ExpandAll call.
The middle section lists out the group captions, showing summary information on the group.
The bottom listing shows the captions plus the actual records in the expanded groups.
This is the type of raw (non-UI specific) information that Essential Grouping allows access to.
Grouped, Non-UI Specific Data
While the IBindingList data source is being edited, Essential Grouping will respond immediately to any changes. If the edit changes a record's sort position, filter state, or group state, the engine will handle repositioning the record appropriately.
Since binary trees have the advantage of parent branches caching information about their children, the position and summary information is cached in parent branches, allowing the editing changes to quickly reflect any sort or group criteria applied.
If a user changes an entry such that it changes its group location or summary information, the Grouping Engine updates these items automatically.
The following image illustrates a before and after listing of some sports statistics. In the external data table, the record for Maryland was changed to Boston College.
Notice that the grouping engine placed the record in its proper sort position.
Before and After Displays of Externally Changed Data Affecting Sort Position
The following is a before and after listing of a group of sports statistics. In the external data table, a new record was added for the school Miami. Notice that the Grouping Engine placed the record in its proper sort position.
Before and After Displays of Adding a New Item to a Sorted Collection
As items are deleted from an IBindingList data source, Essential Grouping will automatically remove them from any sorted, filtered, or grouped collections.
Essential Grouping's sorting support is flexible and not restricted to ADO.NET DataView sorting.
Users can sort any IList data source. The following image displays the code to sort a collection on two keys.
Code to Perform Multi-Key Sorting
Users may provide an IComparer object to customize the sort behavior.
With IComparer objects, it is possible to do things such as always position empty values at the bottom of sorted data.
The following image details the use of a custom IComparer object.
In the picture, column B has values such as b73, b31, etc. By default, this column would be sorted alphabetically.
But with a custom sort, a user may strip off the leading "b" and have the column appear numerically sorted, ignoring the "b".
The picture displays both the default and custom sort results.
Sort Results from Default and Custom Sort on Column B
If a collection has been grouped, subsequent sorts will respect the grouping, arranging the items within the groups.
Filtering allows users to specify data of interest.
Filtering is the process of constraining the display of records based on specific criteria.
Code to Apply a Filter
The following list includes the Filter-Compare-Operator operations currently supported by Essential Grouping.
Equals—Checks if the field value is equal to the compare value. NotEquals—Checks if the field value is not equal to the compare value. LessThan—Checks if the field value is less than the compare value. LessThanOrEqualTo—Checks if the field value is less than or equal to the compare value. GreaterThan—Checks if the field value is greater than the compare value. GreaterThanOrEqualTo—Checks if the field value is greater than or equal to the compare value. Like—Checks if the string field value begins similarly to the compare value. Match—Checks if the string field value is equal to the compare value. Custom—Allows users to add a delegate to define the filter.
Essential Grouping lets users add one or more summary items to each group. Each summary item automatically reflects changes made to data items.
Because of the highly optimized, balanced tree structures used in the grouping engine, the calculation of summary values is very fast with only O(log2 n) operations (where n, is the number of records in the table) .
The following image is a code sample illustrating the addition of a summary item.
Code to Add a Summary Item
The element collection in the grouping engine has additional items at the bottom of each group which you can see after adding a summary item.
The grouping engine has several built-in summaries:
Int32AggregateDouble Aggregate (Count, Min, Max, Sum)String Aggregate (MaxLength, Count)CountDistinct Count (Count, Values array)Vector (Values)Double Vector (statistical methods: Median, Min, Max, 25% Quartile, 75% Quartile)
Custom summaries can easily be added. You can effectively use all of these functionalities in Essential Grid.
Use an expression to add computed values to the information in your data.
For example, if your data contains a "Price" and a "Discount", then the expression can compute the discounted price.
To create an expression, users provide the following—a name to associate with the new item;
a "headertext" property that is a display name; and an algebraic expression involving other columns in the data source.
The following code sample illustrates this procedure.
Code to Add an Expression Field
Expression fields let users add new columns with formula expressions.
The grouping engine comes with its own extensible formula engine. Expression fields can be used in records just like a regular field.
Users may create summaries and group, sort, or create filters based on expression fields.
The following image shows the GridGrouping control with a "Gain" expression field.
It is calculated based on shares and price paid. A summary of totals is displayed at the end of the group.
Expression Field in a Grid (Gain Column)
The following screenshot depicts Essential Grid's GridGrouping control using Essential Grouping.
For flat data tables, users can employ the GridGrouping control to quickly provide custom views of the data.
Users can filter, group, sort, and summarize the data, and it is also easy to add custom formula columns to be used in groups and summaries.
The grouping architecture is flexible, and can be used with any IList object whose items have public properties.
GridGrouping Control—Non-Grouped (Flat) Data
Users may group and sort multiple columns.
If editing changes are made, any affected group, sort, or filter will be automatically adjusted.
GridGrouping Control—Grouped Data
The GridGrouping control also supports data with hierarchical relationships and nested tables.
Changes to any data element automatically update the grid and the position of the changed records appropriately. New rows may be added at any level.
GridGrouping Control—Hierarchical Data
With a GridGrouping control, each record in a hierarchical grid can have multiple nested relations.
Users can expand the record to display nested relations. Each nested table can be expanded individually by clicking the plus-minus button next to the caption text.
Record with Multiple Nested Tables
Essential Chart can use Essential Grouping to manipulate data, and to provide cumulative charts from instance data.
The following chart displays trading volume for issues on a given day. The data in this case is a ticker-type data set that has a time stamp,
a volume value, a symbol, and a price. To get the cumulative chart from this data, Essential Chart first groups the data by symbol, and then aggregates the data to get the total volume on a symbol-by-symbol basis.
Summary Values from Grouped Data
The following figure is another chart based on the same data as the previous the chart in the previous image. For this chart, Essential Grouping has been used to filter the data, and to only display the results of the afternoon trades.
Summary Values from Grouped Data Filtered for Afternoon Trades