Miso. Dataset

new Dataset ( options )

Miso.Dataset is the main object you will instantiate to create a new dataset. A Miso.Dataset also extends from Miso.Dataset.DataView. All the methods available on a Miso.Dataset.DataView will also be available on the dataset.

See the creating datasets guide for detailed information.

You can edit the code in this block and rerun it.

Parameters

  • options Object optional

    optional parameters.

    Properties
    • data Object required

      an actual javascript object that already contains the data

    • url String | function required

      The url of a remote file or a function returning a string for a url containing your data, used for remote importers

    • sync Boolean required

      Set to true to be able to bind to dataset changes. False by default. See the Syncronization & Events guide for detailed information

    • callback String required

      By default, If making a jsonp request, you can use this parameter to specify an alternate callback function name than the one that would be auto generated for you.

    • jsonp Boolean required

      Whether a remote request should use jsonp to enable cross-domain requests.

    • delimiter String required

      When using the Delimeted parser this is used to set a custom field delimiter such as delimiter: '||' for CSV files such as value1||value2

    • strict Boolean required

      Whether to expect the json in our format or whether to interpret as raw array of objects; shorthand for using the Strict parser; default false

    • extract function required

      function used to pre-process raw data, see the creating a dataset guide for more information.

    • ready function required

      the callback function to act on once the data is fetched. Isn't reuired for local imports but is required for remote url fetching.

    • columns Array required

      A way to manually override column type detection. Expects an array of objects of the following structure: { name : 'columnname', type: 'columntype', ... (additional params required for type here.) }

    • comparator function required

      A function to sort the data by. It will be sorted on fetch and on any successive addition. See the sort function for more information.

    • deferred function required

      by default we use underscore.deferred, but if you want to pass your own (like jquery's) just pass it here.

    • importer String required

      The classname of any importer (passes through auto detection based on parameters). For example: Miso.Importers.Polling. See the Creating a dataset guide for more information.

    • parser String required

      The classname of any parser (passes through auto detection based on parameters). For example: Miso.Parsers.Delimited. See the Creating a dataset guide for more information.

    • resetOnFetch Boolean required

      set to true if any subsequent fetches after first one should overwrite the current data.

    • uniqueAgainst String required

      Set to a column name to check for duplication on subsequent fetches.

    • interval Number required

      Polling interval. Set to any value in milliseconds to enable polling on a url.

    • idAttribute String required

      By default all ids are stored in a column called '_id'. If there is an alternate column in the dataset that already includes a unique identifier, specify its name here. Note that the row objects will no longer have an _id property.

Source

Extends

Classes

Column
DataView
Derived
Event
Importers
Parsers
Product

Namespaces

Builder
types

Members

<static> typeOf

Tests the type of a given input against the registered Miso types and returns the closest match.

Source

Methods

add ( rows, options )

Returns: Miso.Dataset

Add a row to the dataset. Triggers add and change events on a syncable dataset.

You can edit the code in this block and rerun it.

Parameters

  • rows Object required

    an object representing a row

  • options Object optional
    Properties
    • silent Boolean required

      do not trigger an add (and thus view updates) event

Returns

Type: Miso.Dataset
Source

addColumn ( column )

Returns: Miso.Dataset.Column

Creates a new column and adds it to the dataset.

Parameters

  • column Object required

    a set of properties describing a Miso.Dataset.Column

    Properties
    • name String required

      Column name

    • type String required

      String name of column type

    • format String optional

      Only used for columns of the type time. The moment.js format describing the input dates.

    • _id String optional

      Sets a custom column _id. We assign one by default.

    • data Array optional

      Column data. By default, set to an empty array.

Returns

Type: Miso.Dataset.Column
Source

addColumns ( )

Adds columns to the dataset.

Source

addComputedColumn ( name, type, func )

Returns: Miso.Dataset.Column

Creates a new column that is computationally derived from the rest of the row. See the Computed columns tutorial for more information.

You can edit the code in this block and rerun it.

Parameters

  • name String required

    name of new column

  • type String required

    The type of the column based on existing

  • func function required

    The way that the column is derived. It takes a row as a parameter.

Returns

Type: Miso.Dataset.Column
Source

column ( name )

Returns: Miso.Dataset.Column
You can edit the code in this block and rerun it.

Parameters

  • name String required

    name of the column to be selected

Returns

View of the given column name

Type: Miso.Dataset.Column
Inherited From
Source

columnNames ( )

Returns: Array.<String>
You can edit the code in this block and rerun it.

Returns

the names of all columns, not including id column

Type: Array.<String>
Inherited From
Source

columns ( columnsArray )

Returns: Miso.Dataset.DataView
You can edit the code in this block and rerun it.

Parameters

  • columnsArray Array.<String> required

    an array of column names

Returns

dataset view of the given columns

Type: Miso.Dataset.DataView
Inherited From
Source

countBy ( byColumn, options )

Returns: Miso.Dataset.Derived

Returns a new derived dataset that contains the original byColumn and a count column that returns the number of occurances each unique value in the byColumn contained.

You can edit the code in this block and rerun it.

Parameters

  • byColumn String required

    The column to count instances again.

  • options Object optional

Returns

Type: Miso.Dataset.Derived
Inherited From
Source

each ( iterator, context )

Iterates over all rows in the dataset. Each row is not a direct reference to the data and thus should not be altered in any way.

You can edit the code in this block and rerun it.

Parameters

Inherited From
Source

eachColumn ( iterator, context )

Iterates over each column. Direct column references, not arrays so modifying data may cause internal inconsistencies.

You can edit the code in this block and rerun it.

Parameters

Inherited From
Source

fetch ( options )

Returns: Deferred

Responsible for actually fetching the data based on the initialized dataset. Note that this needs to be called for either local or remote data.

There are three different ways to use this method:

ds.fetch();

will just fetch the data based on the importer. Note that for async fetching this isn't blocking so don't put your next set of instructions expecting the data to be there.

ds.fetch({
  success: function() {
    // do stuff
    // this is the dataset.
  },
  error : function(e) {
    // do stuff
  }
});

Allows you to pass success and error callbacks that will be called once data is property fetched.

_.when(ds.fetch(), function() {
  // do stuff
  // note 'this' is NOT the dataset.
});

Allows you to use deferred behavior to potentially chain multiple datasets.

You can edit the code in this block and rerun it.

Parameters

  • options Object optional
    Properties
    • success function required

      Success callback to be called when data is fetched. Context is the dataset.

    • failure function required

      Error callback to be called when data fetching fails. Context is the dataset.

Returns

Type: Deferred
Source

groupBy ( byColumn, columns, options )

Returns: Miso.Dataset.Derived

Group rows by values in a given column

You can edit the code in this block and rerun it.

Parameters

  • byColumn String required

    The column by which rows will be grouped

  • columns Array.<String> required

    The columns to be included

  • options Object optional
    Properties
    • method function required

      Function that specifies the way in which the columns are aggregated. The default is sum. The function signature is function(arr). It should return a single result.

    • preprocess function required

      specify a normalization function for the byColumn values if you need to group by some kind of derivation of those values that are not just equality based.

Returns

Type: Miso.Dataset.Derived
Inherited From
Source

hasColumn ( name )

Returns: Boolean

Checks for the existance of a column and returns true/false

You can edit the code in this block and rerun it.

Parameters

  • name String required

    Name of column to check for

Returns

true if a column exists, false otherwise.

Type: Boolean
Inherited From
Source

max ( columns )

Returns: Miso.Dataset.Product|Number

If the dataset has sync enabled this will return a Miso.Dataset.Product that can be used to bind events to and access the current value. Otherwise it will return the current value - the highest numeric value in that column.

You can edit the code in this block and rerun it.

Parameters

  • columns String | Array.<String> required

    column name(s) on which the value is calculated

Returns

Type: Miso.Dataset.Product | Number
Inherited From
Source

mean ( columns )

Returns: Miso.Dataset.Product|Number

If the dataset has sync enabled this will return a Miso.Dataset.Product that can be used to bind events to and access the current value. Otherwise it will return the current value - the mean or average of the numeric form of the values in the column.

You can edit the code in this block and rerun it.

Parameters

  • columns Array.<String> required

    array of column names on which the value is calculated

Returns

Type: Miso.Dataset.Product | Number
Inherited From
Source

min ( columns )

Returns: Miso.Dataset.Product|Number

If the dataset has sync enabled this will return a Miso.Dataset.Product that can be used to bind events to and access the current value. Otherwise it will return the current value - the lowest numeric value in that column.

You can edit the code in this block and rerun it.

Parameters

  • columns Array.<String> required

    array of column names on which the value is calculated

Returns

Type: Miso.Dataset.Product | Number
Inherited From
Source

movingAverage ( columns, size, options )

Returns: Miso.Dataset.Derived

Returns a derived dataset in which the specified columns have a moving average computed over them of a specified size.

Parameters

  • columns Dataset.Column required

    The column on which to calculate the average

  • size Number required

    The window size to utilize for the moving average (the number of rows to average per row.)

  • options Object optional
    Properties
    • method function required

      the method to apply to all values in a window. Mean by default.

Returns

Type: Miso.Dataset.Derived
Inherited From
Source

remove ( filter, options )

Returns: Miso.Dataset

Remove all rows that match the filter. Fires remove and change events on a syncable dataset.

You can edit the code in this block and rerun it.

Parameters

  • filter Number | function required

    can be one of two things: A row id, or a filter function that takes a row and returns true if that row should be removed or false otherwise.

  • options Object optional
    Properties
    • silent Boolean required

      do not trigger an add (and thus view updates) event

Returns

Type: Miso.Dataset
Source

reset ( options )

Clears all the rows. Fires a reset event.

You can edit the code in this block and rerun it.

Parameters

  • options Object optional
    Properties
    • silent Boolean required
Source

reverseEach ( iterator, context )

Iterates over all rows in the dataset in reverse order. Each row is not a direct reference to the data and thus should not be altered in any way.

You can edit the code in this block and rerun it.

Parameters

Inherited From
Source

rowById ( id )

Returns: Object

Fetches a row object with a specific _id. Note that the returned row object is NOT a direct reference to the data and thus any changes to it will not alter the original data.

You can edit the code in this block and rerun it.

Parameters

  • id Number required

    unique id

Returns

a single row based on its id (NOT Position.)

Type: Object
Inherited From
Source

rowByPosition ( i )

Returns: Object

Fetches a row object at a specified position. Note that the returned row object is NOT a direct reference to the data and thus any changes to it will not alter the original data.

You can edit the code in this block and rerun it.

Parameters

  • i Number required

    position index

Returns

a single row based on its position (NOT ID.)

Type: Object
Inherited From
Source

rows ( filter )

Returns: Miso.Dataset.DataView

Shorthand for ds.where({ rows : rowFilter );} If run with no filter will return all rows.

You can edit the code in this block and rerun it.

Parameters

Returns

a dataset view of filtered rows

Type: Miso.Dataset.DataView
Inherited From
Source

sort ( args )

Returns: Miso.Dataset.DataView

Sorts the dataset according to the comparator. A comparator can either be passed in as part of the options object or have been defined on the dataset already, for example as part of the initialization block.

roughly taken from here: http://jxlib.googlecode.com/svn-history/r977/trunk/src/Source/Data/heapsort.js License: Copyright (c) 2009, Jon Bomgardner. This file is licensed under an MIT style license

You can edit the code in this block and rerun it.

Parameters

  • args Object | function optional

    Comparator Function OR Options object

    Properties
    • comparator function required

      Function used to sort the dataset, uses the same return structure as a standard JavaScript sort

    • silent Boolean required

      Default false, set true to supress the firing of a sort event.

Returns

Type: Miso.Dataset.DataView
Inherited From
Source

sum ( columns )

Returns: Miso.Dataset.Product|Number

If the dataset has sync enabled this will return a Miso.Dataset.Product that can be used to bind events to and access the current value. Otherwise it will return the current value - the sum of the numeric form of the values in the column.

You can edit the code in this block and rerun it.

Parameters

  • columns String | Array.<String> required

    column name(s) on which the value is calculated

Returns

Type: Miso.Dataset.Product | Number
Inherited From
Source

toJSON ( )

Returns: Array

Exports a version of the dataset in json format.

Returns

Array of rows.

Type: Array
Inherited From
Source

update ( rowsOrFunction, options )

Returns: Miso.Dataset

Updates one or more rows in a dataset. You can pass either a row object that contains an the identifying id property and altered property, an array of objects of the same form or a function that will be first applied to all rows. The function should take a row object for each row in the dataset. If a row shouldn't be modified, the function can return false for that row. This will fire update and change events on a syncable dataset.

You can edit the code in this block and rerun it.

Parameters

  • rowsOrFunction function | String required

    Can be one of two things: A row id, or a filter function that takes a row and returns true if that row should be removed or false otherwise.

  • options Object optional
    Properties
    • silent Boolean required

      Set to true to disable event firing

Returns

Type: Miso.Dataset
Source

where ( filter, options )

Returns: Miso.Dataset.DataView

Used to create Dataviews, subsets of data based on a set of filters. Filtration can be applied to both rows & columns and for syncing datasets changes in the parent dataset from which the dataview was created will be reflected in the dataview.

You can edit the code in this block and rerun it.

Parameters

  • filter function | Object optional

    a function that takes in a row or an options object that can contain the following parameters.

    Properties
    • columns String | Array.<String> optional

      A filter for columns. A single or multiple column names.

    • filter String | function optional

      A filter for rows. A rowId or a filter function that takes in a row and returns true if it passes the criteria.

  • options Object optional

Returns

Type: Miso.Dataset.DataView
Inherited From
Source