Show:

A View provides encapsulation for a subtree of the render tree. You can build complicated visual components and add them to a render tree as you would a Surface.

Custom Views are created by calling extend on the View constructor.

In addition to what a Controller provides, a View provides:

 Render Tree method: .add
 Size methods: setSize, setProportions
 Layout methods: setOpacity, setOrigin

Constructor

Core.View

()

Example:

 var MyView = View.extend({
             defaults : {
                 defaultOption1 : '',
                 defaultOption2 : 42
             },
             initialize : function(options){
                 // this method called on instantiation
                 // options are passed in after being patched by the specified defaults
        
                 var surface = new Surface({
                     content : options.defaultOption1,
                     size : [options.defaultOption2,100],
                     properties : {background : 'red'}
                 });
        
                 this.add(surface);
             }
         });
        
         var myView = new myView({defaultOption1 : 'hello'});
        
         var context = Context();
         context.add(myView);
        
         context.mount(document.body);

Methods

"on"

(
  • type
  • handler
)

Inherited from Core.OptionsManager:

Adds a handler to the type channel which will be executed on emit.

Parameters:

add

(
  • object
)
RenderTreeNode

Extends the render tree subtree with a new node.

Parameters:

  • object SizeNode | LayoutNode | Surface

    Node

Returns:

RenderTreeNode:

compose

(
  • spec
  • parentSpec
  • size
)
Object private

Inherited from Core.LayoutNode but overwritten in

Defines the rules for composing layout specs: transform, align, origin and opacity. Transform is multiplied by the parent's transform (matrix multiplication). Align is a proportional offset relative to the parent size. Origin is a proportional offset relative to the current size. Opacity is multiplied by the parent's opacity.

Parameters:

  • spec Object

    Object layout spec

  • parentSpec Object

    Parent layout spec

  • size Array

    Object size

Returns:

Object:

The composed layout spec

get

(
  • key
)
Object

Inherited from Core.OptionsManager:

Look up options value by key or get the full options hash.

Parameters:

Returns:

Object: Associated object or full options hash

getOptions

(
  • key
)
Object

Inherited from Core.OptionsManager but overwritten in

Options getter.

Parameters:

Returns:

Object:

object Options value for the key

getSize

() Number[]

Getter for size.

Returns:

Number[]:

size

key

(
  • key
)
OptionsManager

Inherited from Core.OptionsManager:

Return OptionsManager based on sub-object retrieved by key.

Parameters:

Returns:

OptionsManager: Value

off

(
  • type
  • handler
)

Inherited from Core.OptionsManager:

Removes the handler from the type channel. This undoes the work of on.

Parameters:

OptionsManager.patch

(
  • options
  • patch
)
Object

Inherited from Core.OptionsManager:

Constructor method. Create OptionsManager from source dictionary with arguments overridden by patch dictionary.

Parameters:

  • options Object
    Options to be patched
  • patch ...Object
    Options to override

Returns:

Object: source

OptionsManager.setOptions

(
  • instance
  • options
  • defaults
)
Object

Inherited from Core.OptionsManager:

Constructor method. Convenience method to set options with defaults on an object instance.

Parameters:

Returns:

Object: Patched options

patch

(
  • options
)
OptionsManager

Inherited from Core.OptionsManager:

Patch options with provided patches. Triggers change event on the object.

Parameters:

  • options Object
    Patch options

Returns:

OptionsManager: this

remove

()

Remove the View from the RenderTree. All Surfaces added to the View will also be removed. The View can be added back at a later time and all of its data and Surfaces will be restored.

set

(
  • key
  • value
)
OptionsManager

Inherited from Core.OptionsManager:

Set key to value. Outputs change event if a value is overwritten.

Parameters:

Returns:

OptionsManager: Updated OptionsManager

setAspectRatio

(
  • aspectRatio
)
deprecated

Deprecated: Use size functions instead

Setter for aspect ratio.

Parameters:

  • aspectRatio Number | Stream

    Aspect ratio, or a stream.

setMargins

(
  • margins
)

Setter for margins.

Parameters:

  • margins Number[] | Stream

    Margins as [x,y], or a stream.

setOpacity

(
  • opacity
)

Setter for opacity.

Parameters:

  • opacity Number | Stream

    Opacity

setOptions

(
  • options
)

Inherited from Core.OptionsManager but overwritten in

Options setter.

Parameters:

setOrigin

(
  • origin
)

Setter for origin.

Parameters:

  • origin Number[] | Stream

    Origin as [x,y], or a stream.

setProportions

(
  • proportions
)

Setter for proportions.

Parameters:

  • proportions Number[] | Stream

    Proportions as [x,y], or a stream.

setSize

(
  • size
)

Setter for size.

Parameters:

  • size Number[] | Stream

    Size as [width, height] in pixels, or a stream.

Attributes

DEFAULT_OPTIONS

readonly

Overwrite the DEFAULT_OPTIONS dictionary on the constructor of the class you wish to extend with the Controller to patch any options that are not prescribed on instantiation.

EVENTS

readonly

Overwrite the EVENTS dictionary on the constructor of the class you wish to extend with the Controller to include events in {key : value} pairs where the keys are event channel names and the values are functions to be executed.