new module:BaseLayer(data, axes, config, dependencies)
Creates a layer using a configuration and data.
Parameters:
Name | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
DataModel | Instance of DataModel to be used. This DataModel instance serves as the data for a layer. | ||||||||||||||||||
axes |
Object | Axes instances to be used for rendering the layer. Axes are used for mapping data from
value to px.
Properties
|
||||||||||||||||||
config |
LayerConfig | Configuration of the layer | ||||||||||||||||||
dependencies |
Object | Dependencies of the layer
Properties
|
Methods
(static) create() → {BaseLayer}
Creates a layer instance
Returns:
Instance of a layer
- Type
- BaseLayer
(static) defaultConfig() → {Object}
Default configuration of the layer. This configuration gets merged to the user passed configuration using a
plolicy. Base layer only returns part of configuraion, any layer overridding base layer should return its own
configuration.
Returns:
Default configuration
- Type
- Object
(static) defaultPolicy(conf, userConf) → {LayerConfig}
Policy defines how user config gets merged to default config. The default policy here does a deep copy
operation.
Any policy which does more than deep copying should define the policy as a static member.
Parameters:
Name | Type | Description |
---|---|---|
conf |
LayerConfig | Configuration with which the user config will be merged |
userConf |
LayerConfig | Configuration given by the user |
Returns:
Merged layer configuration
- Type
- LayerConfig
(static) formalName() → {string}
Determines a name for a layer. This name of the layer is used in the input data to refer to this layer.
```
.layer([
mark: 'bar',
encoding: { ... }
])
```
Returns:
name of layer
- Type
- string
alias(alias) → {BaseLayer|string}
Provides a alias for a layer. Like it's possible to have same layer (like bar) multiple times, but among multiple
layers of same type if one layer has to be referred, alias is used. If no alias is given then `formalName` is set
as the alias name.
If used as setter
Parameters:
Name | Type | Description |
---|---|---|
alias |
string | Name of the alias |
Returns:
-
Instance of current base layer If used as getter
- Type
- BaseLayer
-
Alias of the current layer
- Type
- string
cachePoint(key, data) → {BarLayer}
Stores point in an object with key as the categorical value or temporal value
Parameters:
Name | Type | Description |
---|---|---|
key |
string | categorical value or temporal value |
data |
Object | Information of the data point |
Returns:
Instance of bar layer
- Type
- BarLayer
calculateDomainFromData(data, fieldsConfig) → {Array}
Calculates the domain from the data.
It checks the type of field and calculates the domain based on that. For example, if it
is a quantitative or temporal field, then it calculates the min and max from the data or
if it is a categorical field then it gets all the values from the data of that field.
Parameters:
Name | Type | Description |
---|---|---|
data |
Array | DataArray |
fieldsConfig |
Object | Configuration of fields |
Returns:
Domain values array.
- Type
- Array
getDataDomain(encodingType) → {Object}
Returns the domain for the axis.
Parameters:
Name | Type | Description |
---|---|---|
encodingType |
string | type of encoding x, y, etc. |
Returns:
Axis domains
- Type
- Object
getNearestPoint(x, y) → {Object}
Gets the nearest point closest to the given x and y coordinate. If no nearest point is found, then it returns
null.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | X Coordinate. |
y |
number | Y Coordinate. |
Returns:
Information of the nearest point.
```
{
// id property contains the field names and their corresponding values in a 2d array. This is the data
// associated with the nearest point.
id: // Example data: [['Origin'], ['USA']],
dimensions: // Physical dimensions of the point.
layerId: // Id of the layer instance.
}
```
- Type
- Object
getNormalizedData(encodingType) → {Object}
Normalizes the transformed data and returns it.
Parameters:
Name | Type | Description |
---|---|---|
encodingType |
string | type of encoding x, y, etc. |
Returns:
Axis domains
- Type
- Object
getPlotElementsFromSet(set) → {Selection}
Returns the dom elements associated with the supplied set of row ids.
Each element in the layer is mapped with a row of the datamodel. When given an array of row ids, it returns all
the elements which is mapped with those row ids.
Parameters:
Name | Type | Description |
---|---|---|
set |
Array | Array of row ids |
Returns:
D3 Selection of dom elements.
- Type
- Selection
getPointsFromIdentifiers(identifiers, config) → {Array}
Returns the information of the marks corresponding to the supplied identifiers. Identifiers are a set of field
names and their corresponding values in an array. It can also be an instance of datamodel.
For example,
```
const identifiers = [
['Origin', 'Cylinders'],
['USA', '8']
];
const points = barLayer.getPointsFromIdentifiers(identifiers);
```
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
identifiers |
Array | DataModel | Identifiers of the marks. | |||||||||
config |
Object | Optional configuration which describes how to get the information.
Properties
|
Returns:
Array of points contains
- Type
- Array
getTransformedData(dataModel, config) → {Array.<Array>}
Returns the transformed data based on given transform type.
It first gets the transform method from transform factory based on type of transform. It then calls the
transform method with the data and passes the configuration parameters of transform such as
groupBy, value field, etc.
Parameters:
Name | Type | Description |
---|---|---|
dataModel |
DataModel | Instance of DataModel |
config |
Object | Configuration for transforming data |
Returns:
Transformed data.
- Type
- Array.<Array>
id() → {string}
Returns the unique identifier of this layer. Id is auto generated during the creation proceess of a schema.
Returns:
id of the layer
- Type
- string
remove() → {BaseLayer}
Disposes the entire layer.
Returns:
Instance of layer.
- Type
- BaseLayer
render() → {BaseLayer}
Renders the layer
Returns:
Instance of the layer.
- Type
- BaseLayer
serialize() → {LayerConfig}
Serialize the schema. Merge config is used for serialization.
Returns:
Serialized schema
- Type
- LayerConfig