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
Name | Type | Description |
---|---|---|
type | string | Type of the widget. |
name | string | Widget name. This is the unique identifier of the widget. |
parent | string, HTMLElement, Selection | Parent to insert widget into. May be a string representing the query selector of the parent, an HTMLElement or a d3 selection. |
elem | string | Element 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
Name | Type | Description |
---|---|---|
selection | Object | Selection to retrieve. |
duration | number | Duration 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
Name | Type | Description |
---|---|---|
value | number | optionalHeight 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
Name | Type | Description |
---|---|---|
margins | number, Object | optionalA 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
Name | Type | Description |
---|---|---|
duration | Duration 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
Name | Type | Description |
---|---|---|
value | number | optionalWidth 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
Name | Type | Description |
---|---|---|
value | number | optionalValue 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
Name | Type | Description |
---|---|---|
value | number | optionalValue of the Y coordinate in pixels. Default value is 0 . |
Returns
Widget
Reference to the Widget's API.