A View object represents a specific transform (configuration or pivot, filter, sort, etc) configuration on an underlying table. A View receives all updates from the table from which it is derived, and can be serialized to JSON or trigger a callback when it is updated. View objects are immutable, and will remain in memory and actively process updates until its view#delete method is called.
Note This constructor is not public - Views are created by invoking the table#view method.
Examples
// Returns a new View, pivoted in the row space by the "name" column.
table.view({row_pivots: ["name"]});
Delete this view and clean up all resources associated with it. View objects do not stop consuming resources or processing updates when they are garbage collected - you must call this method to reclaim these.
The schema of this view. A schema is an Object, the keys of which are the columns of this view, and the values are their string type names. If this view is aggregated, theses will be the aggregated types; otherwise these types will be the same as the columns in the underlying table
Returns Promise<Object> A Promise of this view's schema.
Serializes this view to JSON data in a column-oriented format.
Parameters
options
Object? An optional configuration object.
Returns Promise<Array> A Promise resolving to An array of Objects representing the rows of this view. If this view had a "row_pivots" config parameter supplied when constructed, each row Object will have a "ROW_PATH" key, whose value specifies this row's aggregated path. If this view had a "column_pivots" config parameter supplied, the keys of this object will be comma-prepended with their comma-separated column paths.
Serializes this view to JSON data in a row-oriented format.
Parameters
options
Object? An optional configuration object.
Returns Promise<Array> A Promise resolving to An array of Objects representing the rows of this view. If this view had a "row_pivots" config parameter supplied when constructed, each row Object will have a "ROW_PATH" key, whose value specifies this row's aggregated path. If this view had a "column_pivots" config parameter supplied, the keys of this object will be comma-prepended with their comma-separated column paths.
Serializes this view to CSV data in a standard format.
Parameters
options
Object? An optional configuration object.options.start_row
number The starting row index from which to serialize.options.end_row
number The ending row index from which to serialize.options.start_col
number The starting column index from which to serialize.options.end_col
number The ending column index from which to serialize.options.config
Object A config object for the Papaparse https://www.papaparse.com/docs#json-to-csv config object.
Returns Promise<string> A Promise resolving to a string in CSV format representing the rows of this view. If this view had a "row_pivots" config parameter supplied when constructed, each row will have prepended those values specified by this row's aggregated path. If this view had a "column_pivots" config parameter supplied, the keys of this object will be comma-prepended with their comma-separated column paths.
Serializes a view column into a TypedArray.
Parameters
col_name
column_name
string The name of the column to serialize.
Returns Promise<TypedArray> A promise resolving to a TypedArray representing the data of the column as retrieved from the view - all pivots, aggregates, sorts, and filters have been applied onto the values inside the TypedArray. The TypedArray will be constructed based on data type - integers will resolve to Int8Array, Int16Array, or Int32Array. Floats resolve to Float32Array or Float64Array. If the column cannot be found, or is not of an integer/float type, the Promise returns undefined.
The number of aggregated rows in this view. This is affected by the "row_pivots" configuration parameter supplied to this view's contructor.
Returns Promise<number> The number of aggregated rows.
The number of aggregated columns in this view. This is affected by the "column_pivots" configuration parameter supplied to this view's contructor.
Returns Promise<number> The number of aggregated columns.
Whether this row at index idx
is in an expanded or collapsed state.
Parameters
idx
Returns Promise<bool> Whether this row is expanded.
Expands the row at index idx
.
Parameters
idx
Returns Promise<void>
Collapses the row at index idx
.
Parameters
idx
Returns Promise<void>
Set expansion depth
pf the pivot tree.
Parameters
depth
Register a callback with this view. Whenever the view's underlying table emits an update, this callback will be invoked with the aggregated row deltas.
Parameters
callback
function A callback function invoked on update. The parameter to this callback shares a structure with the return type of view#to_json.
Register a callback with this view. Whenever the view is deleted, this callback will be invoked.
Parameters
callback
function A callback function invoked on update. The parameter to this callback shares a structure with the return type of view#to_json.
A Table object is the basic data container in Perspective. Tables are typed - they have an immutable set of column names, and a known type for each.
Note This constructor is not public - Tables are created by invoking the table factory method, either on the perspective module object, or an a worker instance.
Delete this table and clean up all resources associated with it. Table objects do not stop consuming resources or processing updates when they are garbage collected - you must call this method to reclaim these.
Register a callback with this table. Whenever the view is deleted, this callback will be invoked.
Parameters
callback
function A callback function invoked on update. The parameter to this callback shares a structure with the return type of table#to_json.
The number of accumulated rows in this table. This is affected by the "index" configuration parameter supplied to this view's contructor - as rows will be overwritten when they share an idnex column.
Returns Promise<number> The number of accumulated rows.
The schema of this table. A schema is an Object whose keys are the columns of this table, and whose values are their string type names.
Returns Promise<Object> A Promise of this table's schema.
The computed schema of this table. Returns a schema of only computed columns added by the user, the keys of which are computed columns and the values an Object containing the associated column_name, column_type, and computation.
Returns Promise<Object> A Promise of this table's computed schema.
Create a new view from this table with a specified configuration.
Parameters
config
Object? The configuration object for this view.config.row_pivot
Array<string>? An array of column names to use as Row Pivots.config.column_pivot
Array<string>? An array of column names to use as Column Pivots.config.aggregate
Array<Object>? An Array of Aggregate configuration objects, each of which should provide an "name" and "op" property, repsresnting the string aggregation type and associated column name, respectively. Aggregates not provided will use their type defaultsconfig.filter
Array<Array<string>>? An Array of Filter configurations to apply. A filter configuration is an array of 3 elements: A column name, a supported filter comparison string (e.g. '===', '>'), and a value to compare.config.sort
Array<string>? An Array of column names by which to sort.
Examples
var view = table.view({
row_pivot: ['region'],
aggregate: [{op: 'dominant', column:'region'}],
filter: [['client', 'contains', 'fred']],
sort: ['value']
});
Returns view A new view object for the supplied configuration, bound to this table
- See: table
Updates the rows of a table. Updated rows are pushed down to any derived view objects.
Parameters
data
(Object<string, Array> | Array<Object> | string) The input data for this table. The supported input types mirror the constructor options, minus the ability to pass a schema (Object<string, string>) as this table has. already been constructed, thus its types are set in stone.
- See: table
Removes the rows of a table. Removed rows are pushed down to any derived view objects.
Parameters
Create a new table with the addition of new computed columns (defined as javascript functions)
Parameters
computed
The column names of this table.
Returns Array<string> An array of column names for this table.
Column metadata for this table.
If the column is computed, the computed
property is an Object containing:
-
Array
input_columns
-
String
input_type
-
Object
computation
.Otherwise,
computed
isundefined
.
Returns Array<object> An array of Objects containing metadata for each column.
A factory method for constructing tables.
Parameters
data
(Object<string, Array> | Object<string, string> | Array<Object> | string) The input data for this table. When supplied an Object with string values, an empty table is returned using this Object as a schema. When an Object with Array values is supplied, a table is returned using this object's key/value pairs as name/columns respectively. When an Array is supplied, a table is constructed using this Array's objects as rows. When a string is supplied, the parameter as parsed as a CSV.options
Object? An optional options dictionary.options.index
string The name of the column in the resulting table to treat as an index. When updating this table, rows sharing an index of a new row will be overwritten.index
is mutually exclusive tolimit
options.limit
integer The maximum number of rows that can be added to this table. When exceeded, old rows will be overwritten in the order they were inserted.limit
is mutually exclusive toindex
.
Examples
// Creating a table directly from node
var table = perspective.table([{x: 1}, {x: 2}]);
// Creating a table from a Web Worker (instantiated via the worker() method).
var table = worker.table([{x: 1}, {x: 2}]);