Miso.Dataset. Derived

new Derived ( options )

A Miso.Derived dataset is a regular dataset that has been derived through some computation from a parent dataset. It behaves just like a regular dataset except it also maintains a reference to its parent and the method that computed it.

Parameters

  • options Object optional
    Properties
    • parent Object required

      the parent dataset

    • method function required

      the method by which this derived dataset was computed

Returns

a derived dataset instance

Source

Extends

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
Inherited From
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
Inherited From
Source

addColumns ( )

Adds columns to the dataset.

Inherited From
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
Inherited From
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
Inherited From
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
Inherited From
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
Inherited From
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
Inherited From
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