Miso.Dataset
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.
new Miso.Dataset( options )
Returns:
Miso.Dataset
Returns a new dataset. See the creating datasets guide for detailed information.
You can edit the code in this block and rerun it.
Parameters
Instance Methods
ds.fetch( options )
Returns:
Deferred
Fetches the data and populates the dataset. Even when importing local objects from a var
this needs to be called before data can be accessed. Fetch returns a
deferred
which makes it simple to chain operations off async data requests.
You can edit the code in this block and rerun it.
Parameters
-
options
Object
optional
optional arguments
-
success
Function
optional
Success callback to be called when data is fetched. Context is the dataset.
-
error
Function
optional
Error callback to be called when data fetching fails. Context is the dataset.
ds.addColumn( column )
Returns:
Miso.Dataset.Column
Creates a new column and adds it to the dataset.
You can edit the code in this block and rerun it.
Parameters
-
column
Object
required
Column options
-
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
Optional. An array of column data. By default, set to an empty array.
ds.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.
Parameters
-
name
String
required
Name of the column to be added. Must not already exist.
-
type
String
required
The type of the column to be added. Must match one of the Miso.Dataset.types.
-
func
function
required
The way that the new column is derived. It takes a row as a parameter.
ds.add( row, options )
Returns:
ds
Adds a row to the dataset. This will fire add and change
events on a syncable dataset.
You can edit the code in this block and rerun it.
Parameters
ds.remove( filter, options )
Returns:
ds
Removes rows matching the passed filter from the dataset. This will fire remove
and change events on a syncable dataset.
You can edit the code in this block and rerun it.
Parameters
ds.update( rowsOrFunction, options )
Returns:
ds
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
-
filter
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.
-
newProperties
Object
required
An object representing the values that are changing.
-
options
Object
optional
Options object
ds.reset()
Returns:
undefined
Updates one or more rows in a dataset. This will fire update and change events on a syncable dataset.
You can edit the code in this block and rerun it.
Miso.Dataset.DataView
A Miso.DataView is an immutable version of dataset. It is the result of selecting a subset of the data using the ds.where call. If the dataset is syncing, this view will be updated when changes take place in the original dataset.
A Miso.Dataset also extends from Miso.DataView. All the methods available on a dataview will also be available on the dataset.
Instance Methods
ds.columnNames()
Returns:
Array
Returns an array containing the names of all columns
You can edit the code in this block and rerun it.
ds.column( name )
Returns:
Array
Returns a reference to a column object
You can edit the code in this block and rerun it.
Parameters
ds.columns( nameArray )
Returns:
Miso.Dataset.DataView
Shorthand for ds.where({ columns : nameArray });
You can edit the code in this block and rerun it.
Parameters
ds.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
ds.eachColumn( iterator, context )
Returns:
Iterate over all columns. Direct column references, not arrays so modifying
data may cause internal inconsistencies.
You can edit the code in this block and rerun it.
Parameters
-
iterator
Function
required
A function with the following signature: function(columnName, columnObject, index)'
-
context
Object
optional
The context to be bound to the iterator.
ds.each( iterator, context )
Returns:
Iterate over all rows. 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
-
iterator
Function
required
A function with the following signature: function(row, rowIndex)'
-
context
Object
optional
The context to be bound to the iterator.
ds.reverseEach( iterator, context )
Returns:
Iterate over all rows in reverse. 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
-
iterator
Function
required
A function with the following signature: function(row, rowIndex)'
-
context
Object
optional
The context to be bound to the iterator.
ds.rowByPosition( position )
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
ds.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
Integer
required
id of row to be returned
ds.rows( rowFilter )
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
-
rowFilter
Array || Function
optional
An array of rowIds or a filter function that takes in a row and returns true if that row should return, false otherwise.
ds.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.
You can edit the code in this block and rerun it.
Parameters
ds.where( filters, options)
Returns:
Miso.Dataset.DataView
Where is 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
ds.groupBy(byColumn, columns, options)
Returns:
Miso.Dataset.Derived
Groups rows by the values in a given column
You can edit the code in this block and rerun it.
Parameters
ds.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
ds.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
ds.min( column )
Returns:
Number || Miso.Dataset.Product
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
ds.max( column )
Returns:
Number || Miso.Dataset.Product
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
ds.sum( column )
Returns:
Number || Miso.Dataset.Product
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
ds.mean( column )
Returns:
Number || Miso.Dataset.Product
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
Miso.Dataset.Derived
A Miso.Dataset.Derived is what you will be returned from derivative operations such as
groupBy or movingAverage, it is essetially a Miso.Dataset
but with a syncronisation link back to its parent dataset.
Miso.Dataset.Product
A Miso.Dataset.Product is what you will be returned if you run a method such as
max on a dataset that has sync set to true. The product object
allows you to bind events to it, meaning you can automatically update anything using the
product when the underlying dataset changes in a way which affects the current value of
the product.
Miso.Dataset.Product.define(func)
Returns:
Function
Use this method to define a new product. For example:
You can edit the code in this block and rerun it.
Parameters
Instance Methods
product.val()
Returns:
Any
Returns the current value of the product.
You can edit the code in this block and rerun it.
Miso.Events
Miso.Events is a simple set of pub/sub methods that can be added to any object. Miso Events
support not just simple subscriptions but also make identifiying individual subscriptions
easier through a token system and support callback priority.
object.publish( eventName )
Returns:
this
Publish an event on the object the events have been mixed in to.
Parameters
object.subscribe( eventName, callback, options )
Returns:
token
Subscribe to an event by passing in a name and a callback function.
The token option allows you to supply the token that you can use to
uniquely identify the subscription. The priority subscription allows you
to specify the running order of event subscriptions with higher numbers
being run earlier.
Parameters
-
name
String
required
Name of the event to subscribe to
-
callback
Function
required
Callback function to be run
-
options
Object
optional
Optional configuration parameters
-
token
String
optional
String token to uniquely identify the subscription, will be generated if not passed in
-
priority
Number
optional
Priority number, a higher number will mean the callback will be run earlier
object.subscribeOnce( eventName, callback )
Returns:
token
Create a subscription that will only be run once.
Parameters
-
name
String
required
Name of the event to subscribe to
-
callback
Function
required
Callback function to be run
object.unsubscribe( eventName, identifier )
Returns:
this
Destroy a subscription. If no identifier is provided all subscriptions to the
event will be destroyed.
Parameters
-
name
String
required
Name of the event to subscribe to
-
identifier
String || Function
optional
Either a subscription token or a callback function.
Miso.Dataset.Event
Miso.Dataset.Events are objects that will be passed to event callbacks bound to
dataset objects that contain information about the event and what has changed.
See the
Events tutorial
for more information.
event.isRemove(delta)
Returns:
Boolean
Returns whether or not a given delta is for a remove event
You can edit the code in this block and rerun it.
Parameters
event.isAdd(delta)
Returns:
Boolean
Returns whether or not a given delta is for an add event
You can edit the code in this block and rerun it.
Parameters
event.isUpdate(delta)
Returns:
Boolean
Returns whether or not a given delta is for an update event
You can edit the code in this block and rerun it.
Parameters
Instance Methods
event.affectedColumns()
Returns:
Array
Returns an array of columns affected by the event
You can edit the code in this block and rerun it.
Miso.Dataset.Importers
To specify a custom importer during dataset instantiation, just set the importer property to the class name of the importer you want. Some importers require custom properties. This section will document the properties you can set that will either cause this importer to be selected or will be required by it to continue.
Built in Importers include:
Miso.Dataset.Importers.Local
Miso.Dataset.Importers.Remote
Miso.Dataset.Importers.Polling
Miso.Dataset.Importers.GoogleSpreadsheet
An importer must implement the following interface:
Miso.Dataset.Importers.Local
Import local data already in the environment
You can edit the code in this block and rerun it.
new Miso.Dataset.Importers.Local( options )
Returns:
Miso.Dataset.Importers
Parameters
-
options
Object
optional
Options object
Miso.Dataset.Importers.Remote
Import data from remote files via an AJAX request
You can edit the code in this block and rerun it.
new Miso.Dataset.Importers.Remote( options )
Returns:
Miso.Dataset.Importers
Parameters
-
options
Object
optional
Options object
Miso.Dataset.Importers.Polling
Pull data from a remote source on a regular interval
You can edit the code in this block and rerun it.
new Miso.Dataset.Importers.Polling( options )
Returns:
Miso.Dataset.Importers
Parameters
-
options
Object
optional
Options object
Miso.Dataset.Importers.GoogleSpreadsheet
Import directly from google spreadsheets, see
the Google Spreadsheets guide.
new Miso.Dataset.Importers.GoogleSpreadsheet( options )
Returns:
Miso.Dataset.Importers
Parameters
-
options
Object
optional
Options object
-
key
string
required
The google spreadsheet key
-
worksheet
String
optional
An optional worksheet id. Default is always first worksheet.
-
fast
boolean
optional
An optional flag to enable faster parsing. See the Google Spreadsheets guide for more information about this flag.
-
sheetName
String
optional
If enabling faster parsing with fast flag, instead of using worksheet to designate the sheet index, you can use sheetName to access spreadsheet by name. Default is "Sheet1".
Miso.Dataset.Parsers
To specify a custom parser, during dataset instantiation set the parser property
to the class name of the parser you want. Some parsers require some custom properties.
This section will document the properties you can set that will either cause this parser
to be selected or will be required by it to continue.
Built in Parsers include:
Miso.Dataset.Parsers.Strict
Miso.Dataset.Parsers.Object
Miso.Dataset.Parsers.Delimited
Miso.Dataset.Parsers.GoogleSpreadsheet
The base Miso.Parser structure is:
Miso.Dataset.Parsers.Strict
-
strict - Set this to true when initializing a dataset to indicate
the default internal format should be used.
Miso.Dataset.Parsers.Object
The object parser expects an array of objects where each key is the column name.
data - The local var containing the data to be parsed.
Miso.Dataset.Parsers.Delimited
delimiter - The string that is delimiting the column values.
Note:
The delimited parser will assign custom column names in case the header row exists, but has
missing values. They will be of the form XN where N starts at 0.
Miso.Dataset.Column
Miso.Dataset.Column objects make up the columns contained in a dataset and are returned by some methods such as .column on Miso.Dataset and Miso.Dataset.DataView
new Miso.Dataset.Column( options )
Returns:
Miso.Dataset.Column
Returns a new column.
You can edit the code in this block and rerun it.
Parameters
-
options
Object
required
Options object
-
name
String
required
Column name
-
type
String
optional
Column type
-
before
Function
optional
A function to pre-process a column's value before it is coerced. Signature is function(value)
-
format
String
optional
Optional. Only set if time type. The moment.js format describing the input dates.
-
id
Integer
optional
Sets a custom column _id. We assign one by default.
-
data
Object
optional
A set of data. By default, set to an empty array.
Instance Methods
col.numericAt( index )
Returns:
Number
Internal function used to return the numeric value of a given input in a column. Index is used
as this is currently the return value for numeric coercion of string values.
You can edit the code in this block and rerun it.
Parameters
col.coerce()
Returns:
undefined
Coerces all the data in the column's data array to the appropriate type.
You can edit the code in this block and rerun it.
Miso.Dataset.types
Miso types are used to set and manage the data types on columns. These sets of
functions handle testing what type data is and coercing it into the correct format
for a given type. The type system is completely extensible, making it easy to create
rich custom types for your data when it would be helpful to do so. All types
must have the following interface.
Miso.Dataset.typeOf( value, options )
Returns:
String
Typeof tests the type of a given input against the registered Miso types and
returns the closest match.
You can edit the code in this block and rerun it.
Parameters
-
value
Any
optional
The value to test
-
options
Object
optional
Options object
Miso.Dataset.types.mixed
Miso types are used to set and manage the data types on columns. These sets of
functions handle testing what type data is and coercing it into the correct format
for a given type. The type system is completely extensible, making it easy to create
rich custom types for your data when it would be helpful to do so.
Miso.Dataset.types.mixed.name()
Returns:
string
Returns the name of the mixed type, ie 'mixed'. Used internally.
Miso.Dataset.types.mixed.coerce( value )
Returns:
Any
Coerces the value, given the is the mixed type it's a passthrough.
Parameters
-
value
Any
optional
Value to be coerced
Miso.Dataset.types.mixed.test( value )
Returns:
true
Tests whether the value is of the given type. Given this is the mixed type it will always be true
Parameters
-
value
Any
optional
Value to be tested
Miso.Dataset.types.mixed.compare( value1, value2 )
Returns:
Integer
Compares two mixed type values
Parameters
Miso.Dataset.types.mixed.numeric( value )
Returns:
Integer
Returns the numeric representation of a mixed value. If it's an integer, then it coerces it. Otherwise it returns 0.
Parameters
Miso.Dataset.types.string
The string type is used for columns of strings (shocking, I know).
Miso.Dataset.types.string.name()
Returns:
string
Returns the name of the string type, ie 'string'. Used internally.
Miso.Dataset.types.string.coerce( value )
Returns:
Any
Coerces the value to a string.
Parameters
-
value
Any
optional
Value to be coerced
Miso.Dataset.types.string.test( value )
Returns:
true
Tests whether the value is a string.
Parameters
-
value
Any
optional
Value to be tested
Miso.Dataset.types.string.compare( value1, value2 )
Returns:
Integer
Compares two string type values
Parameters
Miso.Dataset.types.string.numeric( value, indexPosition )
Returns:
Integer
Returns the numeric representation of a string value - returns the indexPosition HACKHACKHACK.
Parameters
-
value
Any
optional
Value to be coerced to numeric
-
indexPosition
Integer
optional
Column position of string value, is the value that will be returned.
Miso.Dataset.types.number
The number type is used for columns of numbers.
Miso.Dataset.types.number.name()
Returns:
number
Returns the name of the number type, ie 'number'. Used internally.
Miso.Dataset.types.number.coerce( value )
Returns:
Any
Coerces the value to a number, a passthrough.
Parameters
-
value
Any
optional
Value to be coerced
Miso.Dataset.types.number.test( value )
Returns:
true
Tests whether the value is a number.
Parameters
-
value
Any
optional
Value to be tested
Miso.Dataset.types.number.compare( value1, value2 )
Returns:
Integer
Compares two number type values
Parameters
Miso.Dataset.types.number.numeric( value, indexPosition )
Returns:
Integer
Returns the numeric representation of a number which will be..the number.
Parameters
Miso.Dataset.types.boolean
The boolean type is used for columns of true/false booleans.
Miso.Dataset.types.boolean.name()
Returns:
boolean
Returns the name of the boolean type, ie 'boolean'. Used internally.
Miso.Dataset.types.boolean.coerce( value )
Returns:
Any
Coerces the value to a boolean, uses javascript truthy/falsy.
Parameters
-
value
Any
optional
Value to be coerced
Miso.Dataset.types.boolean.test( value )
Returns:
true
Tests whether the value is a boolean.
Parameters
-
value
Any
optional
Value to be tested
Miso.Dataset.types.boolean.compare( value1, value2 )
Returns:
Integer
Compares two boolean type values
Parameters
Miso.Dataset.types.boolean.numeric( value, indexPosition )
Returns:
Integer
Returns the numeric representation of a boolean value - false is 0, true 1.
Parameters
-
value
Any
optional
Value to be coerced to numeric
-
indexPosition
Integer
optional
Column position of boolean value, is the value that will be returned.
Miso.Dataset.types.time
The time type is used for columns of dates & timestamps, this uses %a{ :href => 'http://momentjs.com/'} moment.js internally and returns moment objects.
Miso.Dataset.types.time.name()
Returns:
time
Returns the name of the time type, ie 'time'. Used internally.
Miso.Dataset.types.time.coerce( value, options )
Returns:
Any
Coerces the value to a time.
Parameters
-
value
Any
optional
Value to be coerced
-
options
Object
optional
Options object
Miso.Dataset.types.time.test( value )
Returns:
Boolean
Tests whether the value is a time.
Parameters
-
value
Any
optional
Value to be tested
Miso.Dataset.types.time.compare( value1, value2 )
Returns:
Integer
Compares two time type values
Parameters
Miso.Dataset.types.time.numeric( value, indexPosition )
Returns:
Integer
Returns the numeric representation of a time which will be an
epoch time.
Parameters