fields
Fields
1. name
Syntax: field.name()
Returns: String
, name of the field
2. type
Syntax: field.type()
Returns: String
, type of the field
3. schema
Syntax: field.schema()
Returns: JSON
, schema of the field
4. displayName
Syntax: field.displayName()
Returns: String
, display name of the field
5. subtype
Syntax: field.subtype()
Returns: String
, subtype of the field
6. domain
Syntax: field.domain()
Returns: String | number
, domain of the field in case of continuous
and temporal
data and unique strings in case of categorical
data
7. data
Syntax: field.data()
Returns: Array<String | number | Invalid>
, data of the field
8. formattedData
Syntax: field.formattedData(format)
parameters:
- format:
required: true
type: Function | string
description: to generate a formatted data that does not have the same
formatter as the one loaded in the schema during the initialization
Returns: Array
, formatted data of the field
9. getRowsCount
Syntax: field.getRowsCount()
Returns: Number
, returns the minimum difference between two consecutive dates milliseconds.
10. minimumConsecutiveDifference
Syntax: field.minimumConsecutiveDifference()
Returns: Number
, returns the minimum difference between two consecutive dates
milliseconds.
const Datamodel = muze.DataModel;
const data = [
{
Acc: 11,
Year: "1971-01-01",
Origin: "USA",
},
{
Acc: 12,
Year: "1975-01-01",
Origin: "Japan",
},
{
Acc: 10.5,
Year: "1971-01-01",
Origin: "USA",
},
{
Acc: 10,
Year: "1974-01-01",
Origin: "Europe",
},
];
const schema = [
{
name: "Acc",
type: "measure",
defAggFn: "avg",
format: (val) => `${val} m/s^2`,
},
{
name: "Origin",
type: "dimension",
displayName: "Region",
},
{
name: "Year",
type: "dimension",
subtype: "temporal",
format: "%Y-%m-%d",
},
];
const formattedData = await Datamodel.loadData(data, schema);
const dm = new Datamodel(formattedData);
const continuousField = dm.getField("Acc");
const categoricalField = dm.getField("Origin");
const temporalField = dm.getField("Year");
let val = [];
val.push(["Name of Temporal Field", temporalField.name()]);
val.push(["Display Name of Categorical Field", categoricalField.displayName()]);
val.push(["Type of Temporal Field", temporalField.type()]);
val.push(["Subtype of Continuous Field", continuousField.subtype()]);
val.push(["Row Count of Categorical Field", categoricalField.name()]);
val.push([
"Minimum Consecutive Difference of Temporal Field",
temporalField.minimumConsecutiveDifference(),
]);
val.push(["Data of Categorical Field:", categoricalField.data()]);
val.push([
"Formatted Data of Continuous Field:",
continuousField.formattedData(),
]);
val.push(["Name of Temporal Field", temporalField.domain()]);
val.push(["Name of Continuous Field", continuousField.domain()]);
val.push(["Name of Categorical Field", categoricalField.domain()]);
printTable(val, ["Purpose", "Value"]);
*Note**: printTable
is a utility function used for demostration purpose.
The output of above looks like this:
Purpose | Value |
---|---|
Name of Temporal Field | Year |
Display Name of Categorical Field | Region |
Type of Temporal Field | dimension |
Subtype of Continuous Field | continuous |
Row Count of Categorical Field | Origin |
Minimum Consecutive Difference of Temporal Field | 94694400000 |
Data of Categorical Field: | USA, Japan, USA, Europe |
Formatted Data of Continuous Field: | 11 m/s^2, 12 m/s^2, 10.5 m/s^2, 10 m/s^2 |
Name of Temporal Field | 31516200000, 157746600000 |
Name of Continuous Field | 10, 12 |
Name of Categorical Field | USA, Japan, Europe |