Home Manual Reference Source Repository
public class | source

BaseShape

Is an abstract class or interface to be overriden in order to define new shapes. Shapes define the way a given datum should be rendered, they are the smallest unit of rendering into a timeline.

All the life cycle of Shape instances is handled into the Layer instance they are attach to. As a consequence, they should be mainly considered as private objects. The only place they should be interacted with is in Behavior definitions, to test which element of the shape is the target of the interaction and define the interaction according to that test.

Depending of its implementation a Shape can be used along with entity or collection data type. Some shapes are then created to use data considered as a single entity (Waveform, TracePath, Line), while others are defined to be used with data seen as a collection, each shape rendering a single entry of the collection. The shapes working with entity type data should therefore be used in an entity configured Layer. Note that if they are registered as "commonShape" in a collection type Layer, they will behave the exact same way. These kind of shapes are noted: "entity shape".

Available collection shapes:

  • Marker / Annotated Marker
  • Segment / Annotated Segment
  • Dot
  • TraceDots

Available entity shapes:

  • Line
  • Tick (for axis)
  • Waveform
  • TracePath
  • Matrix

Constructor Summary

Public Constructor
public

constructor(options: Object)

Member Summary

Public Members
public
public

[key]: *

public

[name]: *

public
public

Method Summary

Public Methods
public

describe(datum: *, x: *): *[]

Interface method that returns a value or description for salient features of the shape at the given x-coordinate (in time).

public

Destroy the shape and clean references.

public

encache(datum: Object | Array): Object

Interface method called by Layer~update, only for shapes with entity type.

public

Interface method to override when extending this base class.

public

inArea(renderingContext: Object, datum: Object | Array, x1: Number, y1: Number, x2: Number, y2: Number): Boolean

Interface method to override called by Layer~getItemsInArea.

public

install(accessors: Object<String, function>)

Interface method called by Layer when creating a shape.

public

render(renderingContext: Object): Element

Interface method called by Layer~render.

public

update(renderingContext: Object, datum: Object | Array)

Interface method called by Layer~update.

Protected Methods
protected

Returns an object where keys are the accessors methods names to create and values are the default values for each given accessor.

protected

Returns the defaults for global configuration of the shape.

Public Constructors

public constructor(options: Object) source

Params:

NameTypeAttributeDescription
options Object

override default configuration

Public Members

public $el: Element source

public [key]: * source

public [name]: * source

public ns: String source

public params: Object source

Public Methods

public describe(datum: *, x: *): *[] source

Interface method that returns a value or description for salient features of the shape at the given x-coordinate (in time).

The return value should be an array of objects each having properties "cy" (y-coord, i.e. underlying value of datum at or nearest to the given time), "cx" (x-coord in time of that datum) and optionally "unit" (unit of value as a string).

Params:

NameTypeAttributeDescription
datum *
x *

Return:

*[]

public destroy() source

Destroy the shape and clean references. Interface method called from the layer.

public encache(datum: Object | Array): Object source

Interface method called by Layer~update, only for shapes with entity type.

Called once for a given entity, to return any information derived from it that will be used subsequently when rendering. If this method returns a non-null object, then that object will be passed to the update method subsequently instead of the original entity datum. (If you want to retain access to the original entity, stash it in your cache object as well. Otherwise it may be GC'd if nobody else needs it.)

Params:

NameTypeAttributeDescription
datum Object | Array

Entity associated with this shape.

Return:

Object

Cache data (opaque to caller) to pass to update subsequently in place of the original entity datum.

public getClassName(): String source

Interface method to override when extending this base class. The method is called by the Layer~render method. Returns the name of the shape, used as a class in the element group (defaults to 'shape').

Return:

String

public inArea(renderingContext: Object, datum: Object | Array, x1: Number, y1: Number, x2: Number, y2: Number): Boolean source

Interface method to override called by Layer~getItemsInArea. Defines if the shape is considered to be the given area. Arguments are passed in pixel domain.

Params:

NameTypeAttributeDescription
renderingContext Object

the renderingContext of the layer which owns this shape.

datum Object | Array

The datum associated to the shape.

x1 Number

The x component of the top-left corner of the area to test.

y1 Number

The y component of the top-left corner of the area to test.

x2 Number

The x component of the bottom-right corner of the area to test.

y2 Number

The y component of the bottom-right corner of the area to test.

Return:

Boolean

Returns true if the is considered to be in the given area, false otherwise.

public install(accessors: Object<String, function>) source

Interface method called by Layer when creating a shape. Install the given accessors on the shape, overriding the default accessors.

Params:

NameTypeAttributeDescription
accessors Object<String, function>

public render(renderingContext: Object): Element source

Interface method called by Layer~render. Creates the DOM structure of the shape.

Params:

NameTypeAttributeDescription
renderingContext Object

the renderingContext of the layer which owns this shape.

Return:

Element

the DOM element to insert in the item's group.

public update(renderingContext: Object, datum: Object | Array) source

Interface method called by Layer~update. Updates the DOM structure of the shape.

Params:

NameTypeAttributeDescription
renderingContext Object

The renderingContext of the layer which owns this shape.

datum Object | Array

The datum or cache associated with the shape. If the shape has collection type, this will be the single item from the dataset that the shape is dedicated to displaying. If it has entity type, then this will be the object previously returned from the shape's encache method (if any), or else the entity object itself.

Protected Methods

protected _getAccessorList(): Object source

Returns an object where keys are the accessors methods names to create and values are the default values for each given accessor.

Return:

Object

TODO:

  • rename ?

protected _getDefaults(): Object source

Returns the defaults for global configuration of the shape.

Return:

Object