new TableStructure(nameopt, optionsopt)
- Source:
TableStructure provides an abstraction of a data table, ie. a structure with rows and columns. Its primary responsibility is to load and parse the data, from csvs or other. It stores each column as a TableColumn, and saves the rows too if conversion to rows is requested. Columns are also sorted by type for easier access.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name |
String |
<optional> |
Name to use in the NowViewing tab, defaults to 'Display Variable'. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
options |
Object |
<optional> |
Options: Properties
|
Extends
Members
(static) defaultDisplayVariableTypes :Array
- Source:
Expose the default display variable types.
Type:
- Array
_activeTimeColumnNameIdOrIndex :String|Number|Array.<String>|Array.<Number>|undefined
- Source:
Gets or sets the active time column name, id or index. If you pass an array of two such, eg. [0, 1], treats these as the start and end date column identifiers.
Type:
- String | Number | Array.<String> | Array.<Number> | undefined
activeTimeColumn :TableColumn
- Source:
Gets the active time column for this structure. If two were provided (for the start and end times), return only the start date column.
Type:
allowMultiple :Boolean
- Source:
- Inherited From:
Gets or sets a flag for whether more than one checkbox can be selected at a time. Default false.
Type:
- Boolean
color :String
- Source:
- Inherited From:
String describing the color of this node, if applicable. This property is observable.
Type:
- String
columns :Array.<TableColumn>
- Source:
Gets or sets the columns for this structure.
Type:
- Array.<TableColumn>
exclusiveChildIds :Array.<String>
- Source:
- Inherited From:
Gets or sets a list of child ids which cannot be selected at the same time as any other child. Defaults to []. Only relevant with allowMultiple = true. Eg. Suppose the child concepts have ids "10" for 10 year olds, etc, plus "ALL" for all ages, "U21" and "21PLUS" for under and over 21 year olds. Then by specifying ["ALL", "U21", "21PLUS"], when the user selects one of these values, any other values will be unselected. And when the user selects any other value (eg. "10"), if any of these values were selected, they will be unselected.
Type:
- Array.<String>
finishJulianDates :Array.<JulianDate>
- Source:
Returns an array of the finish Julian dates for each row. Only defined if there is an active time column.
Type:
- Array.<JulianDate>
getColorCallback :function
- Source:
- Inherited From:
Gets or sets a function with no arguments that returns a color for the VariableConcept. If undefined, no color is set (the default).
Type:
- function
id :String
- Source:
- Inherited From:
Gets or sets the id of the concept item. By default this is the same as the name. It is allowed to be different eg. for csv files with tersely-named columns.
Type:
- String
isActive :Boolean
- Source:
- Inherited From:
Gets or sets a value indicating whether this variable is currently active. This property is observable.
Type:
- Boolean
isOpen :Boolean
- Source:
- Inherited From:
Gets or sets a value indicating whether this concept item is currently open. When an item is open, its child items (if any) are visible. Default true.
Type:
- Boolean
isSelectable :Boolean
- Source:
- Inherited From:
Gets or sets a flag indicating whether this node is selectable.
Type:
- Boolean
isVisible :Boolean
- Source:
- Inherited From:
Gets or sets a value indicating whether this concept is visible. Defaults to true.
Type:
- Boolean
items :Array.<Concept>
- Source:
- Inherited From:
Gets or sets the array of concepts contained in this group.
If options.items is present, each item's parent property is overridden with this
.
Type:
- Array.<Concept>
name :String
- Source:
- Inherited From:
Gets or sets the name of the concept item. This property is observable.
Type:
- String
parent :Array.<VariableConcept>
- Source:
- Inherited From:
Gets or sets the parent for a node. This property is observable.
Type:
- Array.<VariableConcept>
requireSomeActive :Boolean
- Source:
- Inherited From:
Gets or sets a flag for whether at least one checkbox must be selected at all times. Default false.
Type:
- Boolean
timeIntervals :Array.<TimeIntervalCollection>
- Source:
Returns an array describing when each row is visible. Only defined if there is an active time column.
Type:
- Array.<TimeIntervalCollection>
toggleActiveCallback :function
- Source:
- Inherited From:
Gets or sets a function which is called whenever a child item is successfully toggled. Its sole argument is the toggled child item.
Type:
- function
Methods
(static) fromCsv(csvString, resultopt)
- Source:
Create a TableStructure from a string in csv format. Understands \r\n, \r and \n as newlines.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
csvString |
String | String in csv format. |
|
result |
TableStructure |
<optional> |
A pre-existing TableStructure object; if not present, creates a new one. |
(static) fromJson(json, resultopt)
- Source:
Create a TableStructure from a JSON object, eg. [['x', 'y'], [1, 5], [3, 8], [4, -3]].
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
json |
Object | Table data as an object (in json format). |
|
result |
TableStructure |
<optional> |
A pre-existing TableStructure object; if not present, creates a new one. |
addColumn(name, values)
- Source:
Add column to tableStructure.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Name of column (column header). |
values |
Array.<Number> | Values of column to add to table. |
append(table2, rowNumbersopt)
- Source:
Appends table2 to this table. If rowNumbers are provided, only takes those row numbers from table2. Changes all the columns in one go, to avoid partial updates from tracked values.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
table2 |
TableStructure | The table to add to this one. |
|
rowNumbers |
Array.<Integer> |
<optional> |
The row numbers from table2 to add (defaults to all). |
destroy()
- Source:
Destroy the object and release resources. Is this necessary?
getActiveColumns() → {Array.<TableColumn>}
- Source:
Returns an array of active columns.
Returns:
An array of active columns.
- Type
- Array.<TableColumn>
getChartDetailsForRowNumbers(rowNumbersopt) → {Object}
- Source:
Given an optional array of row numbers of the table which you would like to make into a chart, returns the key information for that chart, ie. the data (in csv string format), units, and x and y labels.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
rowNumbers |
Array.<Number> |
<optional> |
The row numbers. |
Returns:
An object with xName, yName, csvData (Strings) and units (String[]) properties.
- Type
- Object
getColumnAliases() → {Array.<Object>}
- Source:
Provide an array which maps ids to names, if they differ.
Returns:
An array of objects with 'id' and 'name' properties; only where the id and name differ.
- Type
- Array.<Object>
getColumnIndex(id) → {Number}
- Source:
Given an id, find the index of the column and return that. Will return undefined if column with matching id cannot be found in tableStructure.
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | Id of column to find index of. |
Returns:
index of column.
- Type
- Number
getColumnNames() → {Array.<String>}
- Source:
Get the column names.
Returns:
Array of column names.
- Type
- Array.<String>
getColumnsWithFeatureRowsAtStartAndEndDates(timeColumnNameIdOrIndex, valueColumnNameIdOrIndex)
- Source:
Returns new columns for this table structure that include rows for all features at the full table's start and end dates, if they do not already exist. The data for all columns is copied from the feature's start and end date row, except for the provided valueColumn, which is set to null. Pass the time column explicitly if desired, to override this.activeTimeColumn. (Useful if you want to call this before setting it.) It is recommended if you use this, to also set the table's finalEndJulianDate beforehand, so the new feature rows don't blow out the end dates.
Parameters:
Name | Type | Description |
---|---|---|
timeColumnNameIdOrIndex |
String | Integer | Name, id or index of the time column. |
valueColumnNameIdOrIndex |
String | Integer | Name, id or index of the column which should be set to null at the table's start and end dates. |
getColumnWithName(name, columnsopt) → {TableColumn}
- Source:
Returns the first column with the given name, or undefined if none match.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String | The column name. |
|
columns |
Array.<TableColumn> |
<optional> |
If provided, test on these columns instead of this.columns. |
Returns:
The matching column.
- Type
- TableColumn
getColumnWithNameIdOrIndex(nameIdOrIndex) → {TableColumn}
- Source:
Returns the first column with the given name, id or index, or undefined if none match (or null is passed in).
Parameters:
Name | Type | Description |
---|---|---|
nameIdOrIndex |
String | Integer | null | The column name, id or index. |
Returns:
The matching column.
- Type
- TableColumn
getColumnWithNameOrId(nameOrId) → {TableColumn}
- Source:
Returns the first column with the given name or id, or undefined if none match.
Parameters:
Name | Type | Description |
---|---|---|
nameOrId |
String | The column name or id. |
Returns:
The matching column.
- Type
- TableColumn
getIdMapping(idColumnNamesopt) → {Object}
- Source:
Returns a mapping from the idColumnNames to all the rows in the table with that id. If no columnIdNames are defined, returns undefined.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
idColumnNames |
Array |
<optional> |
Provide if you wish to override this table's own idColumnNames. This is supplied to getColumnWithNameIdOrIndex, so the "names" could be ids or indexes too. |
Returns:
An object with keys equal to idStrings (use tableStructure.getIdStringForRowNumber(i) to get this) and values equal to an array of rowNumbers.
- Type
- Object
getIdStringForRowNumber(rowNumber, idColumnNamesopt) → {Object}
- Source:
Returns an id string for the given row, based on idColumns (defaulting to idColumnNames). Use this to index into the result of this.getIdMapping().
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
rowNumber |
Integer | The row number. |
|
idColumnNames |
Array |
<optional> |
An array of id column names (or indexes or ids). |
Returns:
An id string for that row based on joining the id column values for that row such as "Newtown^^NSW".
- Type
- Object
getNodes(condition) → {Array.<Concept>}
- Source:
- Inherited From:
Gets a flat array of all of this concept's descendants, including itself, which meet a given condition.
Parameters:
Name | Type | Description |
---|---|---|
condition |
function | A function of a concept, which returns a boolean. |
Returns:
- Type
- Array.<Concept>
getUpdatedColumns(updatedColumnValuesArrays)
- Source:
Updates this table's columns with new ones, using the existing columns' metadata, and replacing the column values. If a time column is present, reset it, which can involve sorting the columns.
Parameters:
Name | Type | Description |
---|---|---|
updatedColumnValuesArrays |
Array.<Array> | Array of values arrays. |
loadFromCsv(csvString)
- Source:
Load a string in csv format into an existing TableStructure.
Parameters:
Name | Type | Description |
---|---|---|
csvString |
String | String in csv format. |
loadFromJson(json)
- Source:
Load a JSON object into an existing TableStructure.
Parameters:
Name | Type | Description |
---|---|---|
json |
Object | Table data as an object (in json format). |
merge(table2)
- Source:
Merges the rows of table2 into the rows of this table. Uses this.idColumnNames (and this.activeTimeColumn, if present) to identify matching rows. The columns must be in the same order in the two tables. Changes all the columns in one go, to avoid partial updates from tracked values.
Parameters:
Name | Type | Description |
---|---|---|
table2 |
TableStructure | The table to merge into this one. |
replaceRows(table2, replacementMap)
- Source:
Replace specific rows in this table with rows in table2. Changes all the columns in one go, to avoid partial updates from tracked values.
Parameters:
Name | Type | Description |
---|---|---|
table2 |
TableStructure | The table whose rows should replace this table's rows. |
replacementMap |
Object | An object whose properties are {table 1 row number: table 2 row number}. |
setActiveTimeColumn(nameIdOrIndex)
- Source:
Sets the relevant active time column on the table structure, defaulting to the first time column present unless the tableStyle has a 'timeColumn' property. A null timeColumn should explicitly not have a time column, even if one is present.
Parameters:
Name | Type | Description |
---|---|---|
nameIdOrIndex |
String | Number | undefined | A way to identify the column, eg. from tableStyle.timeColumn. |
sortBy(sortColumn, compareFunctionopt)
- Source:
Sorts the rows of the TableStructure by the provided column's values. If the sortColumn is a date/time column, uses its julianDates to sort; otherwise, the values. The tableStructure is given new TableColumns.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
sortColumn |
TableColumn | Column whose values should be sorted. |
|
compareFunction |
function |
<optional> |
The compare function passed to Array.prototype.sort(). |
toArrayOfColumns() → {Object}
- Source:
Return data as an array of columns, eg. [ ['x', 1, 2, 3], ['y', 10, 20, 5] ].
Returns:
An array of column arrays, each beginning with the column name.
- Type
- Object
toArrayOfRows(dateFormatStringopt, rowNumbersopt, formatScalarsopt, quoteStringsIfNeededopt) → {Object}
- Source:
Return data as an array of rows of formatted data, eg. [ ['x', 'y'], ['1', '12,345'], ['2.1', '20'] ].
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dateFormatString |
String |
<optional> |
If present, override the standard date format with a string (see https://www.npmjs.com/package/dateformat) Eg. "isoDateTime" or "dd mmm yyyy HH:MM:ss". "source" is a special override which uses the original source date format. |
rowNumbers |
Array.<Integer> |
<optional> |
An array of row numbers to return. Defaults to all rows. |
formatScalars |
Boolean |
<optional> |
True by default; if false, leave numbers as they are. |
quoteStringsIfNeeded |
Boolean |
<optional> |
False by default; if true, any strings which contain commas will be quoted (including column names). |
Returns:
An array of rows of formatted data, the first of which is the column names. If they contain commas, they are quoted.
- Type
- Object
toCsvString(dateFormatStringopt, rowNumbersopt, formatScalarsopt) → {String}
- Source:
Return data as a csv string with formatted values, eg. 'x,y\n1,"12,345"\n2.1,20'.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dateFormatString |
String |
<optional> |
If present, override the standard date format with a string (see https://www.npmjs.com/package/dateformat) Eg. "isoDateTime" or "dd mmm yyyy HH:MM:ss". "source" is a special override which uses the original source date format. |
rowNumbers |
Array.<Integer> |
<optional> |
An array of row numbers to return. Defaults to all rows. |
formatScalars |
Boolean |
<optional> |
True by default; if false, leave numbers as they are. |
Returns:
Returns the data as a csv string, including the header row.
- Type
- String
toggleActive()
- Source:
- Inherited From:
Toggles the VariableConcept#isActive
property, by using the parent's toggleActiveItem (if defined), or else manually.
toggleActiveItem(concept)
- Source:
- Inherited From:
If appropriate, based on this.allowMultiple, this.requireSomeActive and this.exclusiveChildIds,
sets the VariableConcept#isActive
property on all children, so that only the provided concept is activated.
This is called by the VariableConcept's toggleActive function.
If not appropriate, simply toggles the concept without changing any others.
(For backwards compatibility, VariableConcept does not call this function if there's no possibility it's needed.)
Parameters:
Name | Type | Description |
---|---|---|
concept |
VariableConcept | The concept to make active/inactive. |
toggleOpen()
- Source:
- Inherited From:
Toggles the Concept#isOpen
property. If this item's list of children is open,
calling this method will close it. If the list is closed, calling this method will open it.
toPointArrays(xColumnopt, yColumnsopt) → {Array.<Array>}
- Source:
Returns the active columns as an array of arrays of objects with x and y properties, using js dates for x values if available. Useful for plotting the data. Eg. "a,b,c\n1,2,3\n4,5,6" => [[{x: 1, y: 2}, {x: 4, y: 5}], [{x: 1, y: 3}, {x: 4, y: 6}]].
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
xColumn |
TableColumn |
<optional> |
Which column to use for the x values. Defaults to the first column. |
yColumns |
Array.<TableColumn> |
<optional> |
Which columns to use for the y values. Defaults to all columns excluding xColumn. |
Returns:
The data as arrays of objects.
- Type
- Array.<Array>
toRowDescriptions(featureInfoFieldsopt) → {Array.<String>}
- Source:
Returns data as an array of html for each row.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
featureInfoFields |
Array | Object |
<optional> |
Either an array of keys from the row objects, or an object that maps keys to names of keys. If not provided, defaults to using all keys unaltered. |
Returns:
Array of html for each row.
- Type
- Array.<String>
toRowObjects() → {Array.<Object>}
- Source:
Return data as an array of rows of objects, eg. [{'x': 1, 'y': 10}, {'x': 2, 'y': 20}, ...]. Note this won't work if a column name is a javascript reserved word. Has the same arguments as TableStructure.prototype.toArrayOfRows.
Returns:
Array of objects containing a property for each column of the row. If the table has no data, returns [].
- Type
- Array.<Object>
toStringAndNumberRowObjects(dateFormatStringopt) → {Array.<Object>}
- Source:
Return data as an array of rows of objects with string and number values, eg. [{'string': {'x': '12,345', 'y': '10'}, 'number': {'x': 12345, 'y': 10}}, {'string': {'x':...}, ...}].
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dateFormatString |
String |
<optional> |
If present, override the standard date format with a string (see https://www.npmjs.com/package/dateformat) Eg. "isoDateTime" or "dd mmm yyyy HH:MM:ss". "source" is a special override which uses the original source date format. |
Returns:
Array of objects with "string" and "number" properties, whose properties are the column names.
- Type
- Array.<Object>