A normalized data structure for working with tabular data
| Myna. DataSet | A normalized data structure for working with tabular data |
| Functions | |
| DataSet | Creates a new DataSet Object |
| contains | returns true if any row in the DataSet has a column value that matches compare |
| findFirst | returns the first row in the DataSet whose column value matches compare, or null if no matches |
| findAll | returns a new DataSet of all the rows in this DataSet whose column value matches compare |
| getDs | returns a java DataSource object that can be used as the “ds” option in queries |
| query | queries this DataSet as a table named “data”, and returns a Myna.Query object |
| valueArray | returns an array of the values of a column. |
| map | Creates a new DataSet with the results of calling a provided function on every element in this array. |
| filter | Performs Array.filter, but returns a new DataSet with the same columns as this one |
| concat | Performs Array.concat, but returns a new DataSet with the same columns as this one |
| slice | Performs Array.slice, but returns a new DataSet with the same columns as this one |
| minByCol | returns the “smallest” value of a column. |
| maxByCol | returns the “largest” value of a column. |
| sumByCol | returns a sum of the values of a column. |
| sortByCol | sorts the DataSet by the supplied column and compare function. |
| avgByCol | returns an average of the column. |
Myna.DataSet =function ( options )
Creates a new DataSet Object
| options | Either an array to be converted to a DataSet, or and object containing detailed options. If an array, the array must contain at least one record, and the record should have all the non-function properties expected in the DataSet so that <DataSet.columns> can be inferred. If this is an object it should conform to the Options Object defined below. |
| data | Optional default [] This is an array of initial data. May be empty. |
| columns | Optional default [] Either a comma separated list, an array of column names, or an object whose non-function properties represent the column names. These define the known properties of the objects in a DataSet array. If columns is not provided, but data contains at least one row, columns will be calculated as all the non-function properties of the first row. |
| loader | Optional default null If provided, this will be the implementation of <DataSet.load> |
DataSet is an array of objects. This is treated much like the result set of a query, but does not need to come from a query. DataSet’s provide a normalized way to represent any tabular data
Myna.DataSet.prototype.contains = function( column, compare )
returns true if any row in the DataSet has a column value that matches compare
| column | name of the column to search. |
| compare | RegExp, string regular expresion, or function to compare. if compare is a function, it will be called with the “Compare Function Arguments” below. The supplied compare function should return true if the current row should be output |
| columnValue | Value of column in the current row, |
| data | An object that represents all the columns in this row |
| index | The index of the current row |
| dataset | A reference to this dataset |
Myna.DataSet.prototype.findFirst = function DataSet_findFirst( column, compare )
returns the first row in the DataSet whose column value matches compare, or null if no matches
| column | name of the column to search. |
| compare | RegExp, string regular expresion, or function to compare. if compare is a function, it will be called with the “Compare Function Arguments” below. The supplied compare function should return true if the current row should be output |
| columnValue | Value of column in the current row, |
| data | An object that represents all the columns in this row |
| index | The index of the current row |
| dataset | A reference to this dataset |
Myna.DataSet.prototype.findAll = function DataSet_findAll( column, compare )
returns a new DataSet of all the rows in this DataSet whose column value matches compare
| column | name of the column to search. |
| compare | RegExp, string regular expression, or function to compare. if compare is a function, it will be called with the “Compare Function Arguments” below. The supplied compare function should return true if the current row should be output |
| columnValue | Value of column in the current row, |
| data | An object that represents all the columns in this row |
| index | The index of the current row |
| dataset | A reference to this DataSet |
Myna.DataSet.prototype.getDs =function()
returns a java DataSource object that can be used as the “ds” option in queries
This will create an in-memory H2 database containing a single table “data” which contains the contents of this DataSet. The return value will be a DataSource that can be used to query this table
Myna.DataSet.prototype.query =function( options )
queries this DataSet as a table named “data”, and returns a Myna.Query object
This will create an in-memory H2 database containing a single table “data” which contains the contents of this DataSet. This function takes the same options as Myna.Query, except that the ds/dataSource parameter is ignored
Myna.DataSet.prototype.valueArray=function( columnName )
returns an array of the values of a column.
| columnName | String Column name to return |
Myna.DataSet.prototype.map = function( func )
Creates a new DataSet with the results of calling a provided function on every element in this array.
Myna.DataSet.prototype.filter = function()
Performs Array.filter, but returns a new DataSet with the same columns as this one
Myna.DataSet.prototype.concat = function( otherArray )
Performs Array.concat, but returns a new DataSet with the same columns as this one
<Array.concat>
Myna.DataSet.prototype.slice = function()
Performs Array.slice, but returns a new DataSet with the same columns as this one
<Array.slice>
Myna.DataSet.prototype.minByCol = function( column, compare )
returns the “smallest” value of a column.
| column | column to compare |
| compare | Optiional, default: function(a,b){return a < b} A compare function like sort() uses to determine the minimum value |
Myna.DataSet.prototype.maxByCol = function( column, compare )
returns the “largest” value of a column.
| column | column to compare |
| compare | Optiional, default: function(a,b){return a > b} A compare function like sort() uses to determaxe the maximum value |
Myna.DataSet.prototype.sumByCol = function( column, accessor )
returns a sum of the values of a column.
| column | column to sum |
| accessor | Optional, default: function(element){return element} A function that takes an element of the column and returns a value to be summed. This is useful to force integer math or to sum a property of the objects in the column rather than the objects themselves. |
Myna.DataSet.prototype.sortByCol = function( column, compare )
sorts the DataSet by the supplied column and compare function.
| column | column to sort |
| compare | Optiional, default: String.compareAlpha A compare function that takes 2 elements and returns either 1, 0, or -1 |
var files = new Myna.File("/").listFiles()
files.sortByCol("fileName",String.compareNatural)
Myna.DataSet.prototype.avgByCol = function( column, accessor )
returns an average of the column.
| column | column to average |
| accessor | Optional, default: function(element){return element} A function that takes an element of the column and returns a value to be averaged. This is useful to force integer math or to average a property of the objects in the column rather than the objects themselves. |
null values are ignored. If you want to count nulls as 0, use this accessor
function(element){
return element===null?0:element;
}Creates a new DataSet Object
Myna.DataSet =function ( options )
returns true if any row in the DataSet has a column value that matches compare
Myna.DataSet.prototype.contains = function( column, compare )
returns the first row in the DataSet whose column value matches compare, or null if no matches
Myna.DataSet.prototype.findFirst = function DataSet_findFirst( column, compare )
returns a new DataSet of all the rows in this DataSet whose column value matches compare
Myna.DataSet.prototype.findAll = function DataSet_findAll( column, compare )
returns a java DataSource object that can be used as the “ds” option in queries
Myna.DataSet.prototype.getDs =function()
queries this DataSet as a table named “data”, and returns a Myna.Query object
Myna.DataSet.prototype.query =function( options )
returns an array of the values of a column.
Myna.DataSet.prototype.valueArray=function( columnName )
Creates a new DataSet with the results of calling a provided function on every element in this array.
Myna.DataSet.prototype.map = function( func )
Performs Array.filter, but returns a new DataSet with the same columns as this one
Myna.DataSet.prototype.filter = function()
Performs Array.concat, but returns a new DataSet with the same columns as this one
Myna.DataSet.prototype.concat = function( otherArray )
Performs Array.slice, but returns a new DataSet with the same columns as this one
Myna.DataSet.prototype.slice = function()
returns the “smallest” value of a column.
Myna.DataSet.prototype.minByCol = function( column, compare )
returns the “largest” value of a column.
Myna.DataSet.prototype.maxByCol = function( column, compare )
returns a sum of the values of a column.
Myna.DataSet.prototype.sumByCol = function( column, accessor )
sorts the DataSet by the supplied column and compare function.
Myna.DataSet.prototype.sortByCol = function( column, compare )
returns an average of the column.
Myna.DataSet.prototype.avgByCol = function( column, accessor )
Creates a new array with the results of calling a provided function on every element in this array.
Array.prototype.map = function( fun /*, thisp*/ )
Creates a new array with all elements that pass the test implemented by the provided function.
Array.prototype.filter = function( fun /*, thisp*/ )