<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [view][1]
    -   [delete][2]
    -   [schema][3]
    -   [to_columns][4]
    -   [to_json][5]
    -   [to_csv][6]
    -   [num_rows][7]
    -   [num_columns][8]
    -   [get_row_expanded][9]
    -   [expand][10]
    -   [collapse][11]
    -   [expand_to_depth][12]
    -   [collapse_to_depth][13]
    -   [on_update][14]
    -   [on_delete][15]
-   [table][16]
    -   [delete][17]
    -   [on_delete][18]
    -   [size][19]
    -   [schema][20]
    -   [computed_schema][21]
    -   [view][22]
    -   [update][23]
    -   [remove][24]
    -   [add_computed][25]
    -   [columns][26]
    -   [column_metadata][27]
-   [table][28]

## view

A View object represents a specific transform (configuration or pivot,
filter, sort, etc) configuration on an underlying [table][16]. A View
receives all updates from the [table][16] 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][29] method is called.

<strong>Note</strong> This constructor is not public - Views are created
by invoking the [table#view][30] method.

**Examples**

```javascript
// Returns a new View, pivoted in the row space by the "name" column.
table.view({row_pivots: ["name"]});
```

### delete

Delete this [view][1] 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.

### schema

The schema of this [view][1].  A schema is an Object, the keys of which
are the columns of this [view][1], and the values are their string type names.
If this [view][1] is aggregated, theses will be the aggregated types;
otherwise these types will be the same as the columns in the underlying
[table][16]

Returns **[Promise][31]&lt;[Object][32]>** A Promise of this [view][1]'s schema.

### to_columns

Serializes this view to JSON data in a column-oriented format.

**Parameters**

-   `options` **[Object][32]?** An optional configuration object.
    -   `options.start_row` **[number][33]** The starting row index from which
        to serialize.
    -   `options.end_row` **[number][33]** The ending row index from which
        to serialize.
    -   `options.start_col` **[number][33]** The starting column index from which
        to serialize.
    -   `options.end_col` **[number][33]** The ending column index from which
        to serialize.

Returns **[Promise][31]&lt;[Array][34]>** A Promise resolving to An array of Objects
representing the rows of this [view][1].  If this [view][1] 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][1] had a "column_pivots" config
parameter supplied, the keys of this object will be comma-prepended with
their comma-separated column paths.

### to_json

Serializes this view to JSON data in a row-oriented format.

**Parameters**

-   `options` **[Object][32]?** An optional configuration object.
    -   `options.start_row` **[number][33]** The starting row index from which
        to serialize.
    -   `options.end_row` **[number][33]** The ending row index from which
        to serialize.
    -   `options.start_col` **[number][33]** The starting column index from which
        to serialize.
    -   `options.end_col` **[number][33]** The ending column index from which
        to serialize.

Returns **[Promise][31]&lt;[Array][34]>** A Promise resolving to An array of Objects
representing the rows of this [view][1].  If this [view][1] 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][1] had a "column_pivots" config
parameter supplied, the keys of this object will be comma-prepended with
their comma-separated column paths.

### to_csv

Serializes this view to CSV data in a standard format.

**Parameters**

-   `options` **[Object][32]?** An optional configuration object.
    -   `options.start_row` **[number][33]** The starting row index from which
        to serialize.
    -   `options.end_row` **[number][33]** The ending row index from which
        to serialize.
    -   `options.start_col` **[number][33]** The starting column index from which
        to serialize.
    -   `options.end_col` **[number][33]** The ending column index from which
        to serialize.
    -   `options.config` **[Object][32]** A config object for the Papaparse [https://www.papaparse.com/docs#json-to-csv][35]
        config object.

Returns **[Promise][31]&lt;[string][36]>** A Promise resolving to a string in CSV format
representing the rows of this [view][1].  If this [view][1] 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][1] had a "column_pivots" config
parameter supplied, the keys of this object will be comma-prepended with
their comma-separated column paths.

### num_rows

The number of aggregated rows in this [view][1].  This is affected by
the "row_pivots" configuration parameter supplied to this [view][1]'s
contructor.

Returns **[Promise][31]&lt;[number][33]>** The number of aggregated rows.

### num_columns

The number of aggregated columns in this [view][1].  This is affected by
the "column_pivots" configuration parameter supplied to this [view][1]'s
contructor.

Returns **[Promise][31]&lt;[number][33]>** The number of aggregated columns.

### get_row_expanded

Whether this row at index `idx` is in an expanded or collapsed state.

**Parameters**

-   `idx`  

Returns **[Promise][31]&lt;bool>** Whether this row is expanded.

### expand

Expands the row at index `idx`.

**Parameters**

-   `idx`  

Returns **[Promise][31]&lt;void>** 

### collapse

Collapses the row at index `idx`.

**Parameters**

-   `idx`  

Returns **[Promise][31]&lt;void>** 

### expand_to_depth

Expand the tree down to `depth`.

**Parameters**

-   `depth`  

### collapse_to_depth

Collapse the tree down to `depth`.

**Parameters**

-   `depth`  

### on_update

Register a callback with this [view][1].  Whenever the [view][1]'s
underlying table emits an update, this callback will be invoked with the
aggregated row deltas.

**Parameters**

-   `callback` **[function][37]** A callback function invoked on update.  The
    parameter to this callback shares a structure with the return type of
    [view#to_json][38].

### on_delete

Register a callback with this [view][1].  Whenever the [view][1]
is deleted, this callback will be invoked.

**Parameters**

-   `callback` **[function][37]** A callback function invoked on update.  The
        parameter to this callback shares a structure with the return type of
        [view#to_json][38].

## table

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.

<strong>Note</strong> This constructor is not public - Tables are created
by invoking the [table][16] factory method, either on the perspective
module object, or an a [worker][39] instance.

### delete

Delete this [table][16] 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.

### on_delete

Register a callback with this [table][16].  Whenever the [view][1]
is deleted, this callback will be invoked.

**Parameters**

-   `callback` **[function][37]** A callback function invoked on update.  The
        parameter to this callback shares a structure with the return type of
        [table#to_json][40].

### size

The number of accumulated rows in this [table][16].  This is affected by
the "index" configuration parameter supplied to this [view][1]'s
contructor - as rows will be overwritten when they share an idnex column.

Returns **[Promise][31]&lt;[number][33]>** The number of accumulated rows.

### schema

The schema of this [table][16].  A schema is an Object whose keys are the
columns of this [table][16], and whose values are their string type names.

Returns **[Promise][31]&lt;[Object][32]>** A Promise of this [table][16]'s schema.

### computed_schema

The computed schema of this [table][16]. 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][31]&lt;[Object][32]>** A Promise of this [table][16]'s computed schema.

### view

Create a new [view][1] from this table with a specified
configuration.

**Parameters**

-   `config` **[Object][32]?** The configuration object for this [view][1].
    -   `config.row_pivot` **[Array][34]&lt;[string][36]>?** An array of column names
        to use as [Row Pivots][41].
    -   `config.column_pivot` **[Array][34]&lt;[string][36]>?** An array of column names
        to use as [Column Pivots][42].
    -   `config.aggregate` **[Array][34]&lt;[Object][32]>?** 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 defaults
    -   `config.filter` **[Array][34]&lt;[Array][34]&lt;[string][36]>>?** 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][34]&lt;[string][36]>?** An Array of column names by which to sort.

**Examples**

```javascript
var view = table.view({
     row_pivot: ['region'],
     aggregate: [{op: 'dominant', column:'region'}],
     filter: [['client', 'contains', 'fred']],
     sort: ['value']
});
```

Returns **[view][43]** A new [view][1] object for the supplied configuration,
bound to this table

### update

-   **See: [table][16]**

Updates the rows of a [table][16].  Updated rows are pushed down to any
derived [view][1] objects.

**Parameters**

-   `data` **([Object][32]&lt;[string][36], [Array][34]> | [Array][34]&lt;[Object][32]> | [string][36])** The input data
    for this table.  The supported input types mirror the constructor options, minus
    the ability to pass a schema (Object&lt;string, string>) as this table has.
    already been constructed, thus its types are set in stone.

### remove

-   **See: [table][16]**

Removes the rows of a [table][16].  Removed rows are pushed down to any
derived [view][1] objects.

**Parameters**

-   `data` **[Array][34]&lt;[Object][32]>** An array of primary keys to remove.

### add_computed

Create a new table with the addition of new computed columns (defined as javascript functions)

**Parameters**

-   `computed`  

### columns

The column names of this table.

Returns **[Array][34]&lt;[string][36]>** An array of column names for this table.

### column_metadata

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` is `undefined`.

Returns **[Array][34]&lt;[object][32]>** An array of Objects containing metadata for each column.

## table

A factory method for constructing [table][16]s.

**Parameters**

-   `data` **([Object][32]&lt;[string][36], [Array][34]> | [Object][32]&lt;[string][36], [string][36]> | [Array][34]&lt;[Object][32]> | [string][36])** 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][32]?** An optional options dictionary.
    -   `options.index` **[string][36]** 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
            to `limit`
    -   `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 to
            `index`.

**Examples**

```javascript
// Creating a table directly from node
var table = perspective.table([{x: 1}, {x: 2}]);
```

```javascript
// Creating a table from a Web Worker (instantiated via the worker() method).
var table = worker.table([{x: 1}, {x: 2}]);
```

Returns **[table][44]** A new [table][16] object.

[1]: #view

[2]: #delete

[3]: #schema

[4]: #to_columns

[5]: #to_json

[6]: #to_csv

[7]: #num_rows

[8]: #num_columns

[9]: #get_row_expanded

[10]: #expand

[11]: #collapse

[12]: #expand_to_depth

[13]: #collapse_to_depth

[14]: #on_update

[15]: #on_delete

[16]: #table

[17]: #delete-1

[18]: #on_delete-1

[19]: #size

[20]: #schema-1

[21]: #computed_schema

[22]: #view-1

[23]: #update

[24]: #remove

[25]: #add_computed

[26]: #columns

[27]: #column_metadata

[28]: #table-1

[29]: #viewdelete

[30]: #tableview

[31]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise

[32]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[33]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

[34]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[35]: https://www.papaparse.com/docs#json-to-csv

[36]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[37]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function

[38]: #viewto_json

[39]: https://developer.mozilla.org/docs/Web/JavaScript

[40]: table#to_json

[41]: https://en.wikipedia.org/wiki/Pivot_table#Row_labels

[42]: https://en.wikipedia.org/wiki/Pivot_table#Column_labels

[43]: #view

[44]: #table
