Members
(constant) calculateVariable
Creates a new variable calculated from existing variable. This method expects definition of the newly created
variable and a function which resolves value of the new variable from existing variables.
This operator is not compose supported.
Creates a new measure based on existing variables
- Source:
Examples
//@preamble_start
Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
const data = params[0];
const schema = params[1];
const DataModel = muze.DataModel;
const dm = new DataModel(data, schema);
//@preamble_end
// DataModel instance is created from https://www.charts.com/static/cars.json data,
// https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted from
// muze namespace and assigned to the DataModel variable.
const calculateVariable = DataModel.Operators.calculateVariable
const creatorFn = calculateVariable({
name: 'powerToWeight',
type: 'measure' // Schema of variable
}, ['Horsepower', 'Weight_in_lbs', (hp, weight) => hp / weight ]);
const outputDM = creatorFn(dm);
//@preamble_start
printDM(outputDM);
});
//@preamble_end
//@preamble_start
Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
const data = params[0];
const schema = params[1];
const DataModel = muze.DataModel;
const dm = new muze.DataModel(data, schema);
//@preamble_end
// DataModel instance is created from https://www.charts.com/static/cars.json data,
// https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted from
// muze namespace and assigned to the DataModel variable.
const calculateVariable = DataModel.Operators.calculateVariable;
const creatorFn = calculateVariable(
{
name: 'Efficiency',
type: 'dimension'
}, ['Horsepower', (hp) => {
if (hp < 80) { return 'low'; }
else if (hp < 120) { return 'moderate'; }
else { return 'high' }
}]);
const outputDM = creatorFn(dm);
//@preamble_start
printDM(outputDM);
});
//@preamble_end
(constant) DataFormat :string
DataFormat Enum defines the format of the input data.
Based on the format of the data the respective adapter is loaded.
Type:
- string
Properties:
Name | Type | Description |
---|---|---|
FLAT_JSON |
string | |
DSV_STR |
string | |
DSV_ARR |
string | |
AUTO |
string |
- Source:
(constant) DimensionSubtype :string
DimensionSubtype enum defines the sub types of the Dimensional Field.
Type:
- string
Properties:
Name | Type | Description |
---|---|---|
CATEGORICAL |
string | |
TEMPORAL |
string | |
GEO |
string |
- Source:
(constant) DM_DERIVATIVES
The enums for operation names performed on DataModel.
- Source:
(constant) FieldType :string
FieldType enum defines the high level field based on which visuals are controlled.
Measure in a high level is numeric field and Dimension in a high level is string field.
Type:
- string
Properties:
Name | Type | Description |
---|---|---|
MEASURE |
string | |
DIMENSION |
string |
- Source:
(constant) FilteringMode
FilteringMode determines if resultant DataModel should be created from selection set or rejection set.
The following modes are available
- `NORMAL`: Only entries from selection set are included in the resulatant DataModel instance
- `INVERSE`: Only entries from rejection set are included in the resulatant DataModel instance
- `ALL`: Both the entries from selection and rejection set are returned in two different DataModel instance
You can access this enums from `DataModel.FilteringMode`.
- Source:
(constant) getMinDiff
Gets the minimum difference between two consecutive numbers in an array.
- Source:
(constant) MeasureSubtype :string
MeasureSubtype enum defines the sub types of the Dimensional Field.
Type:
- string
Properties:
Name | Type | Description |
---|---|---|
DISCRETE |
string |
- Source:
(constant) project
This is functional version of projection operator. Projection is a column (field) filtering operation. It expects
list of fields name and either include those or exclude those based on
FilteringMode on the resultant dataModel. It returns a function which is
called with the DataModel instance on which the action needs to be performed.
Projection expects array of fields name based on which it creates the selection and rejection set. All the field
whose name is present in array goes in selection set and rest of the fields goes in rejection set.
FilteringMode operates on the selection and rejection set to determine
which one would reflect in the resulatant datamodel.
- Source:
Example
//@preamble_start
Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
const data = params[0];
const schema = params[1];
const DataModel = muze.DataModel;
const dm = new DataModel(data, schema);
//@preamble_end
// DataModel instance is created from https://www.charts.com/static/cars.json data,
// https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted from
// muze namespace and assigned to the DataModel variable.
const project = DataModel.Operators.project;
usaCarsFn = project(['Name'], { mode: DataModel.FilteringMode.INVERSE });
outputDM = usaCarsFn(dm);
//@preamble_start
printDM(outputDM);
});
//@preamble_end
(constant) PROPAGATION
The event name for data propagation.
- Source:
(constant) ROW_ID
The name of the unique row id column in DataModel.
- Source:
(constant) select
This is functional version of selection operator. Selection is a row filtering operation. It takes
predicate for filtering criteria and returns a function. The returned
function is called with the DataModel instance on which the action needs to be performed.
SelectionPredicate is a function which returns a boolean value. For
selection opearation the selection function is called for each row of DataModel instance with the current row passed
as argument.
After executing SelectionPredicate the rows are labeled as either an
entry of selection set or an entry of rejection set.
FilteringMode operates on the selection and rejection set to determine
which one would reflect in the resulatant datamodel.
- Source:
Example
//@preamble_start
Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
const data = params[0];
const schema = params[1];
const DataModel = muze.DataModel;
const dm = new DataModel(data, schema);
//@preamble_end
// DataModel instance is created from https://www.charts.com/static/cars.json data,
// https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted from
// muze namespace and assigned to the DataModel variable.
const select = DataModel.Operators.select;
usaCarsFn = select(fields => fields.Origin.value === 'USA');
outputDM = usaCarsFn(dm);
//@preamble_start
printDM(outputDM);
});
//@preamble_end
(constant) sort
Performs sorting according to the specified sorting details. Like every other operator it doesn't mutate the current
DataModel instance on which it was called, instead returns a new DataModel instance containing the sorted data.
This operator support multi level sorting by listing the variables using which sorting needs to be performed and
the type of sorting `ASC` or `DESC`.
In the following example, data is sorted by `Origin` field in `DESC` order in first level followed by another level
of sorting by `Acceleration` in `ASC` order.
- Source:
Examples
//@preamble_start
Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
const data = params[0];
const schema = params[1];
const DataModel = muze.DataModel;
const dm = new DataModel(data, schema);
//@preamble_end
// DataModel instance is created from https://www.charts.com/static/cars.json data,
// https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted from
// muze namespace and assigned to the DataModel variable.
const sort = DataModel.Operators.sort;
const preparatorFn = sort([
['Origin', 'DESC'],
['Acceleration'] // Default value is ASC
]);
const outputDM = preparatorFn(dm);
//@preamble_start
printDM(outputDM);
});
//@preamble_end
//@preamble_start
Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
const data = params[0];
const schema = params[1];
const DataModel = muze.DataModel;
const dm = new muze.DataModel(data, schema);
//@preamble_end
// DataModel instance is created from https://www.charts.com/static/cars.json data,
// https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted
// from muze namespace and assigned to DataModel variable.
const avg = DataModel.Stats.avg;
const sort = DataModel.Operators.sort;
const preparatorFn = sort([
['Origin', ['Acceleration', (a, b) => avg(a.Acceleration) - avg(b.Acceleration)]]
]);
const outputDM = preparatorFn(dm);
//@preamble_start
printDM(outputDM);
});
//@preamble_end
Methods
Auto(data, options) → {Array.<Object>}
Parses the input data and detect the format automatically.
Parameters:
Name | Type | Description |
---|---|---|
data |
string | Array | The input data. |
options |
Object | An optional config specific to data format. |
- Source:
Returns:
Returns an array of headers and column major data.
- Type
- Array.<Object>
avg(arr) → {number}
reducer function that takes care about the mean aggregation
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | array of values |
- Source:
Returns:
mean of the array
- Type
- number
calculatedVariableIterator(datamodel, callback)
Invokes a callback for every measure child of a DataModel.
Parameters:
Name | Type | Description |
---|---|---|
datamodel |
DataModel | The input DataModel instance. |
callback |
function | The callback to be invoked on each measure child. The parameters provided to the callback are the child DataModel instance and the child params. |
- Source:
childIterator(datamodel, callback, operation)
iterate the children and call the callback for each
Parameters:
Name | Type | Description |
---|---|---|
datamodel |
DataModel | |
callback |
function | |
operation |
DM_DERIVATIVES |
- Source:
convertToNativeDate(date) → {Date}
Creates a JS native date object from input
Parameters:
Name | Type | Description |
---|---|---|
date |
string | number | Date | Input using which date object to be created |
- Source:
Returns:
: JS native date object
- Type
- Date
count(arr) → {number}
reducer function that gives the count value
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | array of values |
- Source:
Returns:
count of the array
- Type
- number
createBinnedFieldData(data, config) → {Array}
Creates bin f from the data and the supplied config.
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
data |
Array | The input data. | |||||||||
config |
Object | The config object.
Properties
|
- Source:
Returns:
Returns an array of created bins.
- Type
- Array
createFields(dataColumn, schema, headers) → {Array.<Field>}
Creates the field instances with input data and schema.
Parameters:
Name | Type | Description |
---|---|---|
dataColumn |
Array | The data array for fields. |
schema |
Array | The schema array for fields. |
headers |
Array | The array of header names. |
- Source:
Returns:
Returns an array of newly created field instances.
- Type
- Array.<Field>
createSortingFnArg(groupedDatum, targetFields, targetFieldDetails) → {Object}
Creates the argument value used for sorting function when sort is done
with another fields.
Parameters:
Name | Type | Description |
---|---|---|
groupedDatum |
Array | The grouped datum for a single dimension field value. |
targetFields |
Array | An array of the sorting fields. |
targetFieldDetails |
Array | An array of the sorting field details in schema. |
- Source:
Returns:
Returns an object containing the value of sorting fields and the target field name.
- Type
- Object
createUnitField(data, schema) → {Field}
Creates a field instance according to the provided data and schema.
Parameters:
Name | Type | Description |
---|---|---|
data |
Array | The field data array. |
schema |
Object | The field schema object. |
- Source:
- To Do:
-
- Add logic for GEO dimension subtype.
Returns:
Returns the newly created field instance.
- Type
- Field
crossProduct(dataModel1, dataModel2, filterFn, replaceCommonSchemaopt) → {DataModel}
Implementation of cross product operation between two DataModel instances.
It internally creates the data and schema for the new DataModel.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dataModel1 |
DataModel | The left DataModel instance. | ||
dataModel2 |
DataModel | The right DataModel instance. | ||
filterFn |
function | The filter function which is used to filter the tuples. | ||
replaceCommonSchema |
boolean |
<optional> |
false | The flag if the common name schema should be there. |
- Source:
Returns:
Returns The newly created DataModel instance from the crossProduct operation.
- Type
- DataModel
dataBuilder(fieldStore, rowDiffset, colIdentifier, sortingDetails, options) → {Object}
Builds the actual data array.
Parameters:
Name | Type | Description |
---|---|---|
fieldStore |
Array | An array of field. |
rowDiffset |
string | A string consisting of which rows to be included eg. '0-2,4,6'; |
colIdentifier |
string | A string consisting of the details of which column to be included eg 'date,sales,profit'; |
sortingDetails |
Object | An object containing the sorting details of the DataModel instance. |
options |
Object | The options required to create the type of the data. |
- Source:
Returns:
Returns an object containing the multidimensional array and the relative schema.
- Type
- Object
defAggFn() → {function}
Getter for aggregation function of the field.
- Source:
Returns:
Returns aggregation function of the field.
- Type
- function
defaultFilterFn() → {boolean}
Default filter function for crossProduct.
- Source:
Returns:
Always returns true.
- Type
- boolean
defSortFn(a, b) → {number}
The default sort function.
Parameters:
Name | Type | Description |
---|---|---|
a |
* | The first value. |
b |
* | The second value. |
- Source:
Returns:
Returns the comparison result e.g. 1 or 0 or -1.
- Type
- number
difference(leftDM, rightDM) → {DataModel}
Difference operator is written as `(A - B)` where **A** and **B** are instances of
DataModel. The result of `difference` is an instance of
DataModel which includes tuples which are present in **A** and not in **B**.
For `difference` to work schema of both DataModel has to be same.
Parameters:
Name | Type | Description |
---|---|---|
leftDM |
DataModel | Instance of DataModel from which the difference will be calculated. For the notation `(A - B)`, **A** is the leftDM |
rightDM |
DataModel | Instance of DataModel which will be used to calculate the difference from the leftDM. For the notation `(A - B)`, **B** is the rightDM. |
- Source:
Returns:
New DataModel instance with the result of the operation.
- Type
- DataModel
Example
//@preamble_start
Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
const data = params[0];
const schema = params[1];
const DataModel = muze.DataModel;
const dm = new DataModel(data, schema);
//@preamble_end
// DataModel instance is created from https://www.charts.com/static/cars.json data,
// https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted from
// muze namespace and assigned to the variable DataModel.
// Creates a DataModel instance only including USA. Using chained version for conciseness.
const usaMakerDM = dm.select(fields => fields.Origin.value === 'USA');
const difference = DataModel.Operators.difference;
outputDM = difference(dm, usaMakerDM);
//@preamble_start
printDM(outputDM);
});
//@preamble_end
DSVArr(arr, options) → {Array}
Parses and converts data formatted in DSV array to a manageable internal format.
Parameters:
Name | Type | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
arr |
Array.<Array> | A 2D array containing of the DSV data. | ||||||||||
options |
Object | Option to control the behaviour of the parsing.
Properties
|
- Source:
Returns:
Returns an array of headers and column major data.
- Type
- Array
Example
// Sample input data:
const data = [
["a", "b", "c"],
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
DSVStr(str, options) → {Array}
Parses and converts data formatted in DSV string to a manageable internal format.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
str |
string | The input DSV string. | |||||||||||||||
options |
Object | Option to control the behaviour of the parsing.
Properties
|
- Source:
- To Do:
-
- Support to be given for https://tools.ietf.org/html/rfc4180.
- Sample implementation https://github.com/knrz/CSV.js/.
Returns:
Returns an array of headers and column major data.
- Type
- Array
Example
// Sample input data:
const data = `
a,b,c
1,2,3
4,5,6
7,8,9
`
first(arr) → {number}
reducer function that gives the first value
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | array of values |
- Source:
Returns:
first value of the array
- Type
- number
FlatJSON(arr) → {Array.<Object>}
Parses and converts data formatted in JSON to a manageable internal format.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array.<Object> | The input data formatted in JSON. |
- Source:
Returns:
Returns an array of headers and column major data.
- Type
- Array.<Object>
Example
// Sample input data:
const data = [
{
"a": 1,
"b": 2,
"c": 3
},
{
"a": 4,
"b": 5,
"c": 6
},
{
"a": 7,
"b": 8,
"c": 9
}
];
formatNumber(arr1, arr2) → {boolean}
Checks Whether two arrays have same content.
Parameters:
Name | Type | Description |
---|---|---|
arr1 |
Array | The first array. |
arr2 |
Array | The 2nd array. |
- Source:
Returns:
Returns whether two array have same content.
- Type
- boolean
fullOuterJoin(leftDm, rightDm, filterFn) → {DataModel}
Full outer join between two
DataModel instances is a kind of join that ensures that all the tuples from the
left DataModel and right DataModel are present
in the resulatant DataModel. This operator takes a predicate which gets
called for every combination of tuples (created by cartesian product). Based on the value of predicate the equality
is established between two DataModel.
Parameters:
Name | Type | Description |
---|---|---|
leftDm |
DataModel | Instance of DataModel |
rightDm |
DataModel | Instance of DataModel |
filterFn |
SelectionPredicate | The predicate function that will filter the result of the crossProduct. |
- Source:
Returns:
New DataModel instance created after the left outer join operation.
- Type
- DataModel
Example
//@preamble_start
Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
const data = params[0];
const schema = params[1];
const DataModel = muze.DataModel;
const dm = new DataModel(data, schema);
//@preamble_end
// DataModel instance is created from https://www.charts.com/static/cars.json data,
// https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted from
// muze namespace and assigned to the variable DataModel.
// Creates two small DataModel instance from the original DataModel instance, which will be joined using left outer
// join.
let makerDM = dm.groupBy(['Origin', 'Maker']).project(['Origin', 'Maker']);
let nameDM = dm.project(['Name','Miles_per_Gallon']);
const fullOuterJoin = DataModel.Operators.fullOuterJoin;
let outputDM = fullOuterJoin(makerDM, nameDM,
(makerDM, nameDM) => makerDM.Maker.value === nameDM.Name.value.split(/\s/)[0]);
//@preamble_start
printDM(outputDM);
});
//@preamble_end
getCommonSchema(fs1, fs2) → {Array}
The helper function that returns an array of common schema
from two fieldStore instances.
Parameters:
Name | Type | Description |
---|---|---|
fs1 |
FieldStore | The first FieldStore instance. |
fs2 |
FieldStore | The second FieldStore instance. |
- Source:
Returns:
An array containing the common schema.
- Type
- Array
getFieldArr(dataModel, fieldArr) → {Array}
This function sanitize the user given field and return a common Array structure field
list
Parameters:
Name | Type | Description |
---|---|---|
dataModel |
DataModel | the dataModel operating on |
fieldArr |
Array | user input of field Array |
- Source:
Returns:
arrays of field name
- Type
- Array
getReducerObj(dataModel, reducersopt) → {Object}
This sanitize the reducer provide by the user and create a common type of object.
user can give function Also
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dataModel |
DataModel | dataModel to worked on | ||
reducers |
Object | function |
<optional> |
{} | reducer provided by the users |
- Source:
Returns:
object containing reducer function for every measure
- Type
- Object
getSortFn(dataType, sortType, index) → {function}
Generates the sorting functions to sort the data of a DataModel instance
according to the input data type.
Parameters:
Name | Type | Description |
---|---|---|
dataType |
string | The data type e.g. 'measure', 'datetime' etc. |
sortType |
string | The sorting order i.e. 'asc' or 'desc'. |
index |
integer | The index of the data which will be sorted. |
- Source:
Returns:
Returns the the sorting function.
- Type
- function
groupBy(dataModel, fieldArr, reducers, existingDataModel) → {DataModel}
main function which perform the group-by operations which reduce the measures value is the
fields are common according to the reducer function provided
Parameters:
Name | Type | Description |
---|---|---|
dataModel |
DataModel | the dataModel to worked |
fieldArr |
Array | fields according to which the groupby should be worked |
reducers |
Object | function | reducers function |
existingDataModel |
DataModel | Existing datamodel instance |
- Source:
Returns:
new dataModel with the group by
- Type
- DataModel
groupByIterator(datamodel, callback)
Invokes a callback over the children created by a groupBy
operation on a DataModel.
Parameters:
Name | Type | Description |
---|---|---|
datamodel |
DataModel | The input DataModel instance. |
callback |
function | The callback to be invoked. The parameters provided to the callback are the child DataModel instance and the groupBy string used to create it. |
- Source:
groupData(data, fieldIndex) → {Array}
Groups the data according to the specified target field.
Parameters:
Name | Type | Description |
---|---|---|
data |
Array | The input data array. |
fieldIndex |
number | The target field index within schema array. |
- Source:
Returns:
Returns an array containing the grouped data.
- Type
- Array
isArray(val) → {boolean}
Checks whether the value is an array.
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to be checked. |
- Source:
Returns:
Returns true if the value is an array otherwise returns false.
- Type
- boolean
isArrEqual(arr1, arr2) → {boolean}
Checks Whether two arrays have same content.
Parameters:
Name | Type | Description |
---|---|---|
arr1 |
Array | The first array. |
arr2 |
Array | The 2nd array. |
- Source:
Returns:
Returns whether two array have same content.
- Type
- boolean
isCallable(val) → {boolean}
Checks whether the value is callable.
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to be checked. |
- Source:
Returns:
Returns true if the value is callable otherwise returns false.
- Type
- boolean
isObject(val) → {boolean}
Checks whether the value is an object.
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to be checked. |
- Source:
Returns:
Returns true if the value is an object otherwise returns false.
- Type
- boolean
isString(val) → {boolean}
Checks whether the value is a string value.
Parameters:
Name | Type | Description |
---|---|---|
val |
* | The value to be checked. |
- Source:
Returns:
Returns true if the value is a string value otherwise returns false.
- Type
- boolean
join(leftDM, rightDM, filterFn) → {DataModel}
Performs cross-product between two
DataModel instances with an optional predicate which determines which tuples
should be included and returns a new DataModel instance containing the results.
This operation is also called theta join.
Cross product takes two set and create one set where each value of one set is paired with each value of another
set.
This method takes an optional predicate which filters the generated result rows. The predicate is called for
every tuple. If the predicate returns true the combined row is included in the resulatant table.
Parameters:
Name | Type | Description |
---|---|---|
leftDM |
DataModel | Instance of DataModel |
rightDM |
DataModel | Instance of DataModel |
filterFn |
SelectionPredicate | The predicate function that will filter the result of the crossProduct. |
- Source:
Returns:
New DataModel instance created after joining.
- Type
- DataModel
Example
//@preamble_start
Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
const data = params[0];
const schema = params[1];
const DataModel = muze.DataModel;
const dm = new DataModel(data, schema);
//@preamble_end
// DataModel instance is created from https://www.charts.com/static/cars.json data,
// https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted from
// muze namespace and assigned to the variable DataModel.
// Creates two small DataModel instance from the original DataModel instance, which will be joined.
let makerDM = dm.groupBy(['Origin', 'Maker']).project(['Origin', 'Maker']);
let nameDM = dm.project(['Name','Miles_per_Gallon']);
const join = DataModel.Operators.join;
let outputDM = join(makerDM, nameDM,
(makerDM, nameDM) => makerDM.Maker.value === nameDM.Name.value.split(/\s/)[0]);
//@preamble_start
printDM(outputDM);
});
//@preamble_end
last(arr) → {number}
reducer function that gives the last value
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | array of values |
- Source:
Returns:
last value of the array
- Type
- number
leftOuterJoin(leftDm, rightDm, filterFn) → {DataModel}
Left outer join between two
DataModel instances is a kind of join that ensures that all the tuples from the
left DataModel are present in the resulatant
DataModel. This operator takes a predicate which gets called for every
combination of tuples (created by cartesian product). Based on the value of predicate the equality is established
between two DataModel.
Parameters:
Name | Type | Description |
---|---|---|
leftDm |
DataModel | Instance of DataModel |
rightDm |
DataModel | Instance of DataModel |
filterFn |
SelectionPredicate | The predicate function that will filter the result of the crossProduct. |
- Source:
Returns:
New DataModel instance created after the left outer join operation.
- Type
- DataModel
Example
//@preamble_start
Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
const data = params[0];
const schema = params[1];
const DataModel = muze.DataModel;
const dm = new DataModel(data, schema);
//@preamble_end
// DataModel instance is created from https://www.charts.com/static/cars.json data,
// https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted from
// muze namespace and assigned to the variable DataModel.
// Creates two small DataModel instance from the original DataModel instance, which will be joined using left outer
// join.
let makerDM = dm.groupBy(['Origin', 'Maker']).project(['Origin', 'Maker']);
let nameDM = dm.project(['Name','Miles_per_Gallon']);
const leftOuterJoin = DataModel.Operators.leftOuterJoin;
let outputDM = leftOuterJoin(makerDM, nameDM,
(makerDM, nameDM) => makerDM.Maker.value === nameDM.Name.value.split(/\s/)[0]);
//@preamble_start
printDM(outputDM);
});
//@preamble_end
max(arr) → {number}
reducer function that gives the max value
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | array of values |
- Source:
Returns:
max of the array
- Type
- number
merge(arr, lo, mid, hi, sortFn)
The helper function for merge sort which creates the sorted array
from the two halves of the input array.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | The target array which needs to be merged. |
lo |
number | The starting index of the first array half. |
mid |
number | The ending index of the first array half. |
hi |
number | The ending index of the second array half. |
sortFn |
function | The sort function. |
- Source:
mergeSort(arr, sortFnopt) → {Array}
The implementation of merge sort.
It is used in DataModel for stable sorting as it is not sure
what the sorting algorithm used by browsers is stable or not.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
arr |
Array | The target array which needs to be sorted. | ||
sortFn |
function |
<optional> |
defSortFn | The sort function. |
- Source:
Returns:
Returns the input array itself in sorted order.
- Type
- Array
min(arr) → {number}
reducer function that gives the min value
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | array of values |
- Source:
Returns:
min of the array
- Type
- number
naturalJoinFilter(dm1, dm2) → {function}
The filter function used in natural join.
It generates a function that will have the logic to join two
DataModel instances by the process of natural join.
Parameters:
Name | Type | Description |
---|---|---|
dm1 |
DataModel | The left DataModel instance. |
dm2 |
DataModel | The right DataModel instance. |
Returns:
Returns a function that is used in cross-product operation.
- Type
- function
pad(n) → {string}
Apply padding before a number if its less than 1o. This is used when constant digit's number to be returned
between 0 - 99
Parameters:
Name | Type | Description |
---|---|---|
n |
number | Input to be padded |
- Source:
Returns:
Padded number
- Type
- string
prepareSelectionData()
Prepares the selection data.
projectIterator(datamodel, callback)
Invokes a callback for every projected child of a DataModel.
Parameters:
Name | Type | Description |
---|---|---|
datamodel |
DataModel | The input DataModel instance. |
callback |
function | The callback to be invoked on each projected child. The parameters provided to the callback are the child DataModel instance and the projection string. |
- Source:
rightOuterJoin(leftDm, rightDm, filterFn) → {DataModel}
Right outer join between two
DataModel instances is a kind of join that ensures that all the tuples from the
right DataModel are present in the resulatant
DataModel. This operator takes a predicate which gets called for every
combination of tuples (created by cartesian product). Based on the value of predicate the equality is established
between two DataModel.
Parameters:
Name | Type | Description |
---|---|---|
leftDm |
DataModel | Instance of DataModel |
rightDm |
DataModel | Instance of DataModel |
filterFn |
SelectionPredicate | The predicate function that will filter the result of the crossProduct. |
- Source:
Returns:
New DataModel instance created after the left outer join operation.
- Type
- DataModel
Example
//@preamble_start
Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
const data = params[0];
const schema = params[1];
const DataModel = muze.DataModel;
const dm = new DataModel(data, schema);
//@preamble_end
// DataModel instance is created from https://www.charts.com/static/cars.json data,
// https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted from
// muze namespace and assigned to the variable DataModel.
// Creates two small DataModel instance from the original DataModel instance, which will be joined using left outer
// join.
let makerDM = dm.groupBy(['Origin', 'Maker']).project(['Origin', 'Maker']);
let nameDM = dm.project(['Name','Miles_per_Gallon']);
const rightOuterJoin = DataModel.Operators.rightOuterJoin;
let outputDM = rightOuterJoin(makerDM, nameDM,
(makerDM, nameDM) => makerDM.Maker.value === nameDM.Name.value.split(/\s/)[0]);
//@preamble_start
printDM(outputDM);
});
//@preamble_end
rowDiffsetIterator(rowDiffset, callback)
Iterates through the diffSet array and call the callback with the current
index.
Parameters:
Name | Type | Description |
---|---|---|
rowDiffset |
string | The row diffset string e.g. '0-4,6,10-13'. |
callback |
function | The callback function to be called with every index. |
- Source:
scale() → {string}
Getter for scale value of the field.
- Source:
Returns:
Returns scale of the field.
- Type
- string
selectIterator(datamodel, callback)
Invokes a callback for every child created by a selection operation on a DataModel.
Parameters:
Name | Type | Description |
---|---|---|
datamodel |
DataModel | The input DataModel instance. |
callback |
function | The callback to be invoked on each child. The parameters provided to the callback are the child DataModel instance and the selection function used to create it. |
- Source:
sort(arr, lo, hi, sortFn) → {Array}
The helper function for merge sort which would be called
recursively for sorting the array halves.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | The target array which needs to be sorted. |
lo |
number | The starting index of the array half. |
hi |
number | The ending index of the array half. |
sortFn |
function | The sort function. |
- Source:
Returns:
Returns the target array itself.
- Type
- Array
sortData(dataObj, sortingDetails)
Sorts the data before return in dataBuilder.
Parameters:
Name | Type | Description |
---|---|---|
dataObj |
Object | An object containing the data and schema. |
sortingDetails |
Array | An array containing the sorting configs. |
- Source:
std(arr) → {number}
Calculates the square root of the variance of the input array.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array.<number> | The input array. |
- Source:
Returns:
Returns the square root of the variance.
- Type
- number
sum(arr) → {number}
Reducer function that takes care about the sum aggregation
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | array of values |
- Source:
Returns:
sum of the array
- Type
- number
union(topDM, bottomDM) → {DataModel}
Union operation can be termed as vertical stacking of all rows from both the DataModel instances, provided that both
of the DataModel instances should have same column names.
Parameters:
Name | Type | Description |
---|---|---|
topDM |
DataModel | One of the two operands of union. Instance of DataModel. |
bottomDM |
DataModel | Another operands of union. Instance of DataModel. |
- Source:
Returns:
New DataModel instance with the result of the operation.
- Type
- DataModel
Example
//@preamble_start
Promise.all([loadData('/static/cars.json'), loadData('/static/cars-schema.json')]).then(function (params) {
const data = params[0];
const schema = params[1];
const DataModel = muze.DataModel;
const dm = new DataModel(data, schema);
//@preamble_end
// DataModel instance is created from https://www.charts.com/static/cars.json data,
// https://www.charts.com/static/cars-schema.json schema and assigned to variable dm. DataModel is extracted from
// muze namespace and assigned to the variable DataModel.
// Creates two small DataModel instance from the original DataModel instance, one only for european cars,
// another for cars from USA. Used the chain operation here for conciseness.
const usaMakerDM = dm.select(fields => fields.Origin.value === 'USA');
const euroMakerDM = dm.select(fields => fields.Origin.value === 'Europe');
const union = DataModel.Operators.union;
const outputDM = union(usaMakerDM, euroMakerDM);
//@preamble_start
printDM(outputDM);
});
//@preamble_end
uniqueValues(data) → {Array}
Returns the unique values from the input array.
Parameters:
Name | Type | Description |
---|---|---|
data |
Array | The input array. |
- Source:
Returns:
Returns a new array of unique values.
- Type
- Array
unit() → {string}
Getter for unit value of the field.
- Source:
Returns:
Returns unit of the field.
- Type
- string
variance(arr) → {number}
Calculates the variance of the input array.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array.<number> | The input array. |
- Source:
Returns:
Returns the variance of the input array.
- Type
- number