new Table(data, config) → {Spyral.Table}
Create a new Table
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Object | Array | String | Number | An array of data or a string with CSV or TSV. |
config |
Spyral.Table~TableConfig | an Object for configuring the table initialization |
Returns:
Spyral.TableMethods
-
addColumn(config, ind) → {Spyral.Table}
-
Add a column (at the specified index)
Parameters:
Name Type Description configObject | String indnumber | string Returns:
Spyral.Table -
addRow(data) → {Spyral.Table}
-
Add a row to the Table
Parameters:
Name Type Description dataArray | Object Returns:
Spyral.Table -
addRows(data) → {Spyral.Table}
-
Add rows to the Table
Parameters:
Name Type Description dataArray Returns:
Spyral.Table -
cell(rowInd, colInd) → {number}
-
Get the value of a cell
Parameters:
Name Type Description rowIndnumber | string The row index
colIndnumber | string The column index
Returns:
number -
chart(targetopt, configopt) → {Highcharts.Chart}
-
Show a chart representing the Table
Parameters:
Name Type Attributes Description targetString | HTMLElement <optional>
configHighchartsConfig <optional>
Returns:
Highcharts.Chart -
column(ind, asObjopt) → {Object|Number|String}
-
Get the specified column
Parameters:
Name Type Attributes Description indnumber | string asObjboolean <optional>
Returns:
Object | Number | String -
columnCounts(ind) → {number}
-
Get the count of each unique value in the specified column
Parameters:
Name Type Description indnumber | string Returns:
number -
columnMax(ind) → {number}
-
Get the maximum value in the specified column
Parameters:
Name Type Description indnumber | string Returns:
number -
columnMean(ind) → {number}
-
Get the mean of the values in the specified column
Parameters:
Name Type Description indnumber | string Returns:
number -
columnMin(ind) → {number}
-
Get the minimum value in the specified column
Parameters:
Name Type Description indnumber | string Returns:
number -
columnRollingMean(ind, neighbors, overwrite) → {Array}
-
Get the rolling mean for the specified column
Parameters:
Name Type Description indnumber | string neighborsnumber overwriteboolean Returns:
Array -
columnSort() → {Spyral.Table}
-
TODO Sort the specified columns
Returns:
Spyral.Table -
columnStandardDeviation(ind) → {number}
-
Get the standard deviation for the specified column
Parameters:
Name Type Description indnumber | string Returns:
number -
columnSum(ind) → {number}
-
Get the sum of the values in the specified column
Parameters:
Name Type Description indnumber | string Returns:
number -
columnVariance(ind) → {number}
-
Get the variance for the specified column
Parameters:
Name Type Description indnumber | string Returns:
number -
columnZScores(ind) → {Array}
-
Get the z scores for the specified column
Parameters:
Name Type Description indnumber | string Returns:
Array -
columns(indsopt, configopt) → {Number|Array}
-
This function returns different values depending on the arguments provided. When there are no arguments, it returns the number of columns in this table. When the first argument is the boolean value
trueall columns are returned. When the first argument is a number a slice of the columns is returned and if the second argument is a number it is treated as the length of the slice to return (note that it isn't theendindex like with Array.slice()).Parameters:
Name Type Attributes Description indsBoolean | Array | Number | String <optional>
configObject | Number | String <optional>
Returns:
Number | Array -
forEach(fn)
-
Runs the specified function on each row. The function is passed the row and the row index.
Parameters:
Name Type Description fnfunction -
getColumnIndex(ind, create) → {number}
-
Get (and create) the column index
Parameters:
Name Type Description indnumber | string The index
createboolean Returns:
number -
getRowIndex(ind, create) → {number}
-
Get (and create) the row index
Parameters:
Name Type Description indnumber | string The index
createboolean Returns:
number -
hasColumn(ind) → {number|string}
-
Does the specified column exist
Parameters:
Name Type Description indnumber | string Returns:
number | string -
header(ind) → {number|string}
-
Get the specified header
Parameters:
Name Type Description indnumber | string Returns:
number | string -
headers(inds) → {Number|Array}
-
This function returns different values depending on the arguments provided. When there are no arguments, it returns the number of headers in this table. When the first argument is the boolean value
trueall headers are returned. When the first argument is a number a slice of the headers is returned. When the first argument is an array the slices specified in the array are returned.Parameters:
Name Type Description indsBoolean | Array | Number | String Returns:
Number | Array -
html(target, configopt) → {Spyral.Table}
-
Set the target's contents to an HTML representation of the Table
Parameters:
Name Type Attributes Description targetfunction | String | Object configObject <optional>
Returns:
Spyral.Table -
row(ind, asObjopt) → {Object|Number|String}
-
Get the specified row
Parameters:
Name Type Attributes Description indnumber | string asObjboolean <optional>
Returns:
Object | Number | String -
rowCounts(ind) → {number}
-
Get the count of each unique value in the specified row
Parameters:
Name Type Description indnumber | string Returns:
number -
rowMax(ind) → {number}
-
Get the maximum value in the specified row
Parameters:
Name Type Description indnumber | string Returns:
number -
rowMean(ind) → {number}
-
Get the mean of the values in the specified row
Parameters:
Name Type Description indnumber | string Returns:
number -
rowMin(ind) → {number}
-
Get the minimum value in the specified row
Parameters:
Name Type Description indnumber | string Returns:
number -
rowRollingMean(ind, neighbors, overwrite) → {Array}
-
Get the rolling mean for the specified row
Parameters:
Name Type Description indnumber | string neighborsnumber overwriteboolean Returns:
Array -
rowSort() → {Spyral.Table}
-
TODO Sort the specified rows
Returns:
Spyral.Table -
rowStandardDeviation(ind) → {number}
-
Get the standard deviation for the specified row
Parameters:
Name Type Description indnumber | string Returns:
number -
rowSum(ind) → {number}
-
Get the sum of the values in the specified row
Parameters:
Name Type Description indnumber | string Returns:
number -
rowVariance(ind) → {number}
-
Get the variance for the specified row
Parameters:
Name Type Description indnumber | string Returns:
number -
rowZScores(ind) → {Array}
-
Get the z scores for the specified row
Parameters:
Name Type Description indnumber | string Returns:
Array -
rows(indsopt, configopt) → {Number|Array}
-
This function returns different values depending on the arguments provided. When there are no arguments, it returns the number of rows in this table. When the first argument is the boolean value
trueall rows are returned. When the first argument is a an array then the rows corresponding to the row indices or names are returned. When all arguments except are numbers or strings then each of those is returned.Parameters:
Name Type Attributes Description indsBoolean | Array | Number | String <optional>
configObject | Number | String <optional>
Returns:
Number | Array -
setCell(row, column, value) → {Spyral.Table}
-
Set the value of a cell
Parameters:
Name Type Description rownumber | string The row index
columnnumber | string The column index
valuenumber The value to set
Returns:
Spyral.Table -
setColumn(ind, data, create) → {Spyral.Table}
-
Set a column
Parameters:
Name Type Description indnumber | string The column index
dataObject | Array createboolean Returns:
Spyral.Table -
setHeaders(data) → {Spyral.Table}
-
Set the headers for the Table
Parameters:
Name Type Description dataObject | Array Returns:
Spyral.Table -
setRow(ind, data, create) → {Spyral.Table}
-
Set a row
Parameters:
Name Type Description indnumber | string The row index
dataObject | Array createboolean Returns:
Spyral.Table -
toArray(rowsAsObjectsopt) → {Array}
-
Get an array of the rows of the Table.
Parameters:
Name Type Attributes Default Description rowsAsObjectsBoolean <optional>
false If true, each row will be returned as an object with the headers as keys
Returns:
Array -
toCsv(configopt) → {string}
-
Get a CSV representation of the Table
Parameters:
Name Type Attributes Description configObject <optional>
Returns:
string -
toDataTable(targetopt, config) → {DataTable}
-
Displays an interactive table using DataTables
Parameters:
Name Type Attributes Description targetHTMLElement <optional>
configObject Returns:
DataTable -
toHtml()
-
Same as toString.
-
toString(configopt) → {string}
-
Get an HTML representation of the Table
Parameters:
Name Type Attributes Description configObject <optional>
Returns:
string -
toTsv(configopt) → {string}
-
Get a TSV representation of the Table
Parameters:
Name Type Attributes Description configObject <optional>
Returns:
string -
updateCell(row, column, value, overwrite)
-
Add to or set a cell value
Parameters:
Name Type Description rownumber | string The row index
columnnumber | string The column index
valuenumber The value to set/add
overwriteboolean True to set, false to add to current value
-
static cmp(a, b) → {number}
-
Compare two values
Parameters:
Name Type Description anumber | string bnumber | string Returns:
number -
static counts(data) → {Object}
-
Get the count of each unique value in the data
Parameters:
Name Type Description dataArray Returns:
Object -
static create(data, config) → {Spyral.Table}
-
Create a new Table
Parameters:
Name Type Description dataObject | Array | String | Number configSpyral.Table~TableConfig Returns:
Spyral.Table -
static fetch(input, api, config) → {Promise}
-
Fetch a Table from a source
Parameters:
Name Type Description inputString | Request apiObject configObject Returns:
Promise -
static mean(data) → {number}
-
Get the mean of the provided values
Parameters:
Name Type Description dataArray Returns:
number -
static rollingMean(data, neighbors) → {Array}
-
Get rolling mean for the provided values
Parameters:
Name Type Description dataArray neighborsnumber Returns:
Array -
static standardDeviation(data) → {number}
-
Get the standard deviation for the provided values
Parameters:
Name Type Description dataArray Returns:
number -
static sum(data) → {number}
-
Get the sum of the provided values
Parameters:
Name Type Description dataArray Returns:
number -
static variance(data) → {number}
-
Get the variance for the provided values
Parameters:
Name Type Description dataArray Returns:
number -
static zScores(data) → {Array}
-
Get the z scores for the provided values
Parameters:
Name Type Description dataArray Returns:
Array -
static zip(…data) → {Array}
-
Perform a zip operation of the provided arrays. Learn more about zip on Wikipedia.
Parameters:
Name Type Attributes Description dataArray <repeatable>
Returns:
Array
Type Definitions
-
TableConfig
-
The Table config object
Properties:
Name Type Description formatstring The format of the provided data, either "tsv" or "csv"
headersObject | Array The table headers
hasHeadersboolean True if the headers are the first item in the data
countstring Specify "vertical" or "horizontal" to create a table of unique item counts in the provided data