Layer
Extends:
The layer class is the main visualization class. It is mainly defines by its
related LayerTimeContext
which determines its position in the overall
timeline (through the start
, duration
, offset
and stretchRatio
attributes) and by it's registered Shape which defines how to display the
data associated to the layer. Each created layer must be inserted into a
Track
instance in order to be displayed.
Note: in the context of the layer, an item is the SVG element
returned by a Shape
instance and associated with a particular datum.
Layer DOM structure
<g class="layer" transform="translate(${start}, 0)">
<svg class="bounding-box" width="${duration}">
<g class="offset" transform="translate(${offset, 0})">
<!-- background -->
<rect class="background"></rect>
<!-- shapes and common shapes are inserted here -->
</g>
<g class="interactions"><!-- for feedback --></g>
</svg>
</g>
Static Method Summary
Static Public Methods | ||
public static |
Allows to override default the |
Constructor Summary
Public Constructor | ||
public |
constructor(dataType: String, data: Array | Object, options: Object) |
Member Summary
Public Members | ||
public |
|
|
public |
|
|
public |
|
|
public |
|
|
public |
|
|
public |
A Segment instanciated to interact with the Layer itself. |
|
public get |
Returns the data associated to the layer. |
|
public set |
Sets the data associated with the layer. |
|
public |
Defines how the layer should look at the data ( |
|
public set |
Sets |
|
public get |
Returns |
|
public get |
Returns an array containing all the displayed items. |
|
public set |
Sets |
|
public get |
Returns |
|
public get |
Returns the opacity of the whole layer. |
|
public set |
Sets the opacity of the whole layer. |
|
public |
Parameters of the layers, |
|
public get |
Returns the items marked as selected. |
|
public set |
Sets |
|
public get |
Returns |
|
public set |
Sets |
|
public get |
Returns |
|
public |
|
|
public get |
Returns the transfert function used to display the data in the x axis. |
|
public get |
Returns the transfert function used to display the data in the y axis. |
|
public set |
Set the domain boundaries of the data for the y axis. |
|
public get |
Returns the domain boundaries of the data for the y axis. |
Method Summary
Public Methods | ||
public |
configureCommonShape(ctor: BaseShape, accessors: Object, options: Object) Optionnaly register a shape to be used accros the entire collection. |
|
public |
configureShape(ctor: BaseShape, accessors: Object, options: Object) Register a shape and its configuration to use in order to render the data. |
|
public |
destroy() Destroy the layer, clear all references. |
|
public |
Edit item(s) according to the |
|
public |
editContext(dx: Number, dy: Number, $target: Element) Edit the layer and thus its related |
|
public |
getDatumFromDOMElement($el: Element): Object | Array | null Returns the datum associated to a specific item from any DOM element composing the shape. |
|
public |
getDatumFromItem($item: Element): Object | Array | null Returns the datum associated to a specific item. |
|
public |
getItemFromDOMElement($el: Element): Element | null Returns an item from a DOM element related to the shape, null otherwise. |
|
public |
getItemsInArea(area: Object): Array Retrieve all the items in a given area as defined in the registered |
|
public |
hasElement($el: Element): bool Defines if a given element belongs to the layer. |
|
public |
Tests if the given DOM element is an item of the layer. |
|
public |
render() Create the DOM structure of the shapes according to the given data. |
|
public |
Mark item(s) as selected. |
|
public |
setBehavior(behavior: BaseBehavior) Register the behavior to use when interacting with a shape. |
|
public |
setContextEditable(bool: boolean) Defines if the |
|
public |
setTimeContext(timeContext: TimeContext) Sets the context of the layer, thus defining its |
|
public |
stretchContext(dx: Number, dy: Number, $target: Element) Stretch the layer and thus its related |
|
public |
toggleSelection($items: Element | Element[]) Toggle item(s) selection state according to their current state. |
|
public |
Removes item(s) from selected items. |
|
public |
update() Updates the container of the layer and the attributes of the existing shapes. |
|
public |
Updates the container of the layer. |
|
public |
Updates the attributes of all the |
Static Public Methods
Public Constructors
public constructor(dataType: String, data: Array | Object, options: Object) source
Params:
Name | Type | Attribute | Description |
dataType | String | Defines how the layer should look at the data. Can be 'entity' or 'collection'. |
|
data | Array | Object | The data associated to the layer. |
|
options | Object | Configures the layer. |
|
options.height | Number |
|
Defines the height of the layer. |
options.top | Number |
|
Defines the top position of the layer. |
options.opacity | Number |
|
Defines the opacity of the layer. |
options.yDomain | Number |
|
Defines boundaries of the data values in y axis (for exemple to display an audio buffer, this attribute should be set to [-1, 1]. |
options.className | String |
|
An optionnal class to add to each created shape. |
options.className | String |
|
The class to add to a shape when selected. |
options.contextHandlerWidth | Number |
|
The width of the handlers displayed to edit the layer. |
options.hittable | Number |
|
Defines if the layer can be interacted
with. Basically, the layer is not returned by |
Public Members
public dataType: String source
Defines how the layer should look at the data ('entity'
or 'collection'
).
public timeContext: LayerTimeContext source
public get timeToPixel: Number source
Returns the transfert function used to display the data in the x axis.
Public Methods
public configureCommonShape(ctor: BaseShape, accessors: Object, options: Object) source
Optionnaly register a shape to be used accros the entire collection.
public configureShape(ctor: BaseShape, accessors: Object, options: Object) source
Register a shape and its configuration to use in order to render the data.
public edit($items: Element | Element[], dx: Number, dy: Number, $target: Element) source
Edit item(s) according to the edit
defined in the registered Behavior
.
Params:
Name | Type | Attribute | Description |
$items | Element | Element[] | The item(s) to edit. |
|
dx | Number | The modification to apply in the x axis (in pixels). |
|
dy | Number | The modification to apply in the y axis (in pixels). |
|
$target | Element | The target of the interaction (for example, left handler DOM element in a segment). |
public editContext(dx: Number, dy: Number, $target: Element) source
Edit the layer and thus its related LayerTimeContext
attributes.
public getDatumFromDOMElement($el: Element): Object | Array | null source
Returns the datum associated to a specific item from any DOM element
composing the shape. Basically a shortcut for getItemFromDOMElement
and
getDatumFromItem
methods.
Params:
Name | Type | Attribute | Description |
$el | Element |
public getDatumFromItem($item: Element): Object | Array | null source
Returns the datum associated to a specific item.
Params:
Name | Type | Attribute | Description |
$item | Element |
public getItemFromDOMElement($el: Element): Element | null source
Returns an item from a DOM element related to the shape, null otherwise.
Params:
Name | Type | Attribute | Description |
$el | Element | the element to be tested |
public getItemsInArea(area: Object): Array source
Retrieve all the items in a given area as defined in the registered Shape~inArea
method.
public hasElement($el: Element): bool source
Defines if a given element belongs to the layer. Is more general than
hasItem
, can mostly used to check interactions elements.
Params:
Name | Type | Attribute | Description |
$el | Element | The DOM element to be tested. |
Return:
bool |
public hasItem($item: Element): Boolean source
Tests if the given DOM element is an item of the layer.
Params:
Name | Type | Attribute | Description |
$item | Element | The item to be tested. |
public render() source
Create the DOM structure of the shapes according to the given data. Inspired
from the enter
and exit
d3.js paradigm, this method should be called
each time a datum is added or removed from the data. While the DOM is
created the update
method must be called in order to update the shapes
attributes and thus place them where they should.
public setBehavior(behavior: BaseBehavior) source
Register the behavior to use when interacting with a shape.
Params:
Name | Type | Attribute | Description |
behavior | BaseBehavior |
public setContextEditable(bool: boolean) source
Defines if the Layer
, and thus the LayerTimeContext
is editable or not.
Params:
Name | Type | Attribute | Description |
bool | boolean |
|
public setTimeContext(timeContext: TimeContext) source
Sets the context of the layer, thus defining its start
, duration
,
offset
and stretchRatio
.
Params:
Name | Type | Attribute | Description |
timeContext | TimeContext | The timeContext in which the layer is displayed. |
public stretchContext(dx: Number, dy: Number, $target: Element) source
Stretch the layer and thus its related LayerTimeContext
attributes.
public toggleSelection($items: Element | Element[]) source
Toggle item(s) selection state according to their current state.
public update() source
Updates the container of the layer and the attributes of the existing shapes.
public updateShapes() source
Updates the attributes of all the Shape
instances rendered into the layer.
TODO:
- - allow to filter which shape(s) should be updated.