Home Manual Reference Source Repository
import BaseBehavior from 'waves-ui/src/behaviors/base-behavior.js'
public class | source

BaseBehavior

Is an abstract class or interface to be overriden in order to define the way a given shape should behave when selected or edited by a user. Instances of BaseBehavior are internally used by Layer instances to modify the data according to a user interaction and a given shape. A single instance of Behavior is created in one given shape.

By default, the only method to override to define a new behavior for a shape is the edit method. However, if needed in special cases, all the selection handling can be overriden too.

The flow is the following: Event - (forwarded to) -> Layer - (command) -> Behavior - (modify) -> data - (upates) -> Shape

The behavior responsability is then to modify the data according to the user interactions, while shapes are always a view of the current state of the data.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public set

The class to add to the shapes when selected.

public get

The class to add to the shapes when selected.

public get

An array containing all the selected items of the layer.

Method Summary

Public Methods
public

Destroy the references to the selected items.

public

edit(renderingContext: Object, shape: BaseShape, datum: Object | Array, dx: Number, dy: Number, $target: Element)

Interface method to override in order to define its particular behavior when interacted with.

public

initialize(layer: *)

public

select($item: Element, datum: Object)

public

toggleSelection($item: Element, datum: Object)

public

unselect($item: Element, datum: Object)

Public Constructors

public constructor source

Public Members

public set selectedClass: String source

The class to add to the shapes when selected.

public get selectedClass: String source

The class to add to the shapes when selected.

public get selectedItems: Array source

An array containing all the selected items of the layer.

Public Methods

public destroy(): String source

Destroy the references to the selected items.

TODO:

  • - rename to `clearSelection` (removing the class) ?

public edit(renderingContext: Object, shape: BaseShape, datum: Object | Array, dx: Number, dy: Number, $target: Element) source

Interface method to override in order to define its particular behavior when interacted with.

Params:

NameTypeAttributeDescription
renderingContext Object

The layer rendering context.

shape BaseShape

The shape object to be edited.

datum Object | Array

The related datum to modify.

dx Number

The value of the interaction in the x axis (in pixels).

dy Number

The value of the interaction in the y axis (in pixels).

$target Element

The target DOM element of the interaction.

public initialize(layer: *) source

Params:

NameTypeAttributeDescription
layer *

public select($item: Element, datum: Object) source

Params:

NameTypeAttributeDescription
$item Element

The item to select.

datum Object

Not used in this implementation. Could be used to mark the data as selected.

TODO:

  • - Pass the shape object to get the accessors ?

public toggleSelection($item: Element, datum: Object) source

Params:

NameTypeAttributeDescription
$item Element

The item to toggle selection.

datum Object

Not used in this implementation. Could be used to mark the data as selected.

TODO:

  • - Pass the shape object to get the accessors ?

public unselect($item: Element, datum: Object) source

Params:

NameTypeAttributeDescription
$item Element

The item to unselect.

datum Object

Not used in this implementation. Could be used to mark the data as selected.

TODO:

  • - Pass the shape object to get the accessors ?