API Docs for:
Show:

Legend Class

Defined in: dynamic_chart.js:426
Module: DynamicChart

Legend for a chart;
Adds a div and an SVG element to the page to represent a chart's legend.

Methods

__init__

(
  • legend
  • width
  • height
  • left
  • top
)
Undefined private

[Private method, not visible from consumers]

Parameters:

  • legend Object

    [Mandatory] The legend object to be initialized;

  • width Number

    [Mandatory] The width of the legend object;

  • height Number

    [Mandatory] The height of the legend object;

  • left Number

    [Mandatory] Horizontal absolute position of the legend;

  • top Number

    [Mandatory] Vertical absolute position of the legend;

Returns:

Undefined:

__redrawLegend__

() Undefined protected

[Protected method, not visible outside this library]

Update the drawings of this legend object;

Returns:

Undefined:

addItem

(
  • labelText
  • labelColor
  • fillColor
)
Object chainable

Adds an item to the legend and then redraws it;

Parameters:

  • labelText String

    [Mandatory] The text of the label for this new item;

  • labelColor String

    [Mandatory] The color to be used to draw new item's label;

  • fillColor String

    [Mandatory] The color associated with this new item;

Returns:

Object: This legend object, to allow for method chaining;

destroy

() Null

Object's destructor: helps garbage collector freeing memory, and removes legend's DOM elements. Object's destructor: helps garbage collector freeing memory, and removes chart DOM elements.

WARNING: calling destroy on an object will force any further reference to its attributes / methods to throw exceptions.

NOTE: This function should be override by any class inheriting from this object.
In order to properly work, any overriding destroyer should:

  1. Free any array specific to the object on which is called;
  2. Remove any event listener on chart objects;
  3. Call super object's destroy method.

Returns:

Null: to state that the object has been destroyed.

LegendFactory

(
  • [width]
  • [height]
  • [left]
  • [top]
  • [parent=
)
Object

Creates, upon request, a new Legend object and returns it;

Parameters:

  • [width] Number optional

    [Mandatory] The desired width for the chart (can't be changed later) Can be any value that is or can be converted to a positive integer.

  • [height] Number optional

    [Mandatory] The desired height for the chart (can't be changed later) Can be any value that is or can be converted to a positive integer.

  • [left] Number optional

    [Optional] The horizontal position of the legend bounding box;

  • [top] Number optional

    [Optional] The vertical position of the legend bounding box;

  • [parent= Object

    page's body element] [Optional] The DOM element to which the diagram should be appended as a child

Returns:

Object: A new Legend object;

removeItem

(
  • index
)
Object chainable

Parameters:

  • index Number

    [Mandatory] The index of the item to update; Only positive Integers and values that can be converted to positive integers are accepted.

Returns:

Object: This legend object, to allow for method chaining;

setHeight

(
  • height
)
Object chainable

Sets the height of the legend bounding box.

Parameters:

  • height Number

    [Mandatory] The new height of the legend; Only positive Integers and values that can be converted to positive integers are accepted.

Returns:

Object: This legend object, to allow for method chaining.

setPosition

(
  • left
  • top
)
Object chainable

Sets the position of the legend in the page. Position is assumed to be absolute.

Parameters:

  • left Number

    [Mandatory] The horizontal position of the legend bounding box; Only Integers and values that can be converted to integers are accepted.

  • top Number

    [Mandatory] The vertical position of the legend bounding box; Only Integers and values that can be converted to integers are accepted.

Returns:

Object: This legend object, to allow for method chaining.

setWidth

(
  • width
)
Object chainable

Sets the width of the legend bounding box.

Parameters:

  • width Number

    [Mandatory] The new width of the legend; Only positive integers and values that can be converted to positive Integers are accepted.

Returns:

Object: This legend object, to allow for method chaining.

updateItem

(
  • index
  • [labelText]
  • [labelColor]
  • [fillColor]
)
Object chainable

Updates the attributes of an item of the legend and then redraws it;

Parameters:

  • index Number

    [Mandatory] The index of the item to update;

  • [labelText] String optional

    [Optional] The new text for the label of the index-th item; If omitted or undefined won't be changed;

  • [labelColor] String optional

    [Optional] The new color to be used to draw the index-th item's label; If omitted or undefined won't be changed;

  • [fillColor] String optional

    [Optional] The new color associated with the index-th item; If omitted or undefined won't be changed;

Returns:

Object: This legend object, to allow for method chaining;

Properties

__divElement__

Object protected

The div element that will be a container to the legend's svg element

__items__

Array protected

Array of the items contained in the legend

__svgElement__

Object protected

The svg element for this Legend