Widget

live example

Explore the API in the live example.

api reference

Widget(type, name, parent, elem)
Component implementing a generic widget. A widget is the most abstract element of the library and most of the charts or control elements are inherited from this component.

Parameters

NameTypeDescription
typestringType of the widget.
namestringWidget name. This is the unique identifier of the widget.
parentstring, HTMLElement, SelectionParent to insert widget into. May be a string representing the query selector of the parent, an HTMLElement or a d3 selection.
elemstringElement type (svg, div, etc).
Widget.getElem(selection, duration)
Returns a selection with different behavior based on whether the widget has been initialized yet. If the widget is already initialized, it returns the transitioned form of the selection, otherwise it returns the selection and initializes the widget.

Parameters

NameTypeDescription
selectionObjectSelection to retrieve.
durationnumberDuration of the

Returns

Object
The selection or transition of the selection.
Widget.getStyle()
Widget.height([value])
Sets the height of the widget in pixels (including it's margins).

Parameters

NameTypeDescription
valuenumberoptionalHeight value in pixels. Default value is 200.

Returns

Widget
Reference to the Widget's API.
Widget.id()
Returns the ID of the current widget.

Returns

string
The widget's identifier.
Widget.margins([margins])
Sets widget margins in pixels. Margins are included in width and height and thus effectively shrink the plotting area.

Parameters

NameTypeDescription
marginsnumber, ObjectoptionalA single number to set all sides to or an object specifying some of the sides. Default value is 0.

Returns

Widget
Reference to the Widget's API.
Widget.render(duration)
Renders and updates the widget. After any change to the widget, the render method should be called.

Parameters

NameTypeDescription
durationDuration of the rendering animation in ms. If not specified, the rendering does not involve animations.

Returns

Widget
Reference to the Widget's API.
Widget.width([value])
Sets the width of the widget in pixels (including it's margins).

Parameters

NameTypeDescription
valuenumberoptionalWidth value in pixels. Default value is 300.

Returns

Widget
Reference to the Widget's API.
Widget.x([value])
Sets the X coordinate of the widget in pixels relative to its parent. If negative, the widget's right side is measured from the right side of the parent, otherwise its left side is measured from the parent's left side.

Parameters

NameTypeDescription
valuenumberoptionalValue of the X coordinate in pixels. Default value is 0.

Returns

Widget
Reference to the Widget's API.
Widget.y([value])
Sets the Y coordinate of the widget in pixels relative to its parent, with a top-down direction. If negative, the widget's bottom side is measured from the bottom of the parent, otherwise the top side is measured from the parent's top.

Parameters

NameTypeDescription
valuenumberoptionalValue of the Y coordinate in pixels. Default value is 0.

Returns

Widget
Reference to the Widget's API.