du.widget

Module for creating and adding various widgets to an interactive dashboard. This module contains the base class for all widgets, and therefore it is required to be included. All widgets come with some default functionality which are implemented in this module.

There are some fundamental characteristics of all widgets that are listed here: With a few exception, most of the widget methods return a reference to the widget itself for chaining.

Requires: d3@v4

Widget

du.widget.Widget(name, type[, element[, parent]])

The base widget class, all widgets inherit this parent class.
argtypedescription
namestringName of the widget. This is used to identify the element.
typestringWidget type, part of the generated widget ID.
elementstringHTML element type to use in the widget. If not specified, SVG is used. optional
parentobjectParent element to append widget to. If not specified, it is attached to body. optional

_IDS

du.widget.Widget._IDS

Object Internal IDs.

relative

du.widget.Widget.relative(on)

Whether to position widget relative to parent instead of absolute. Default is false.
argtypedescription
onbooleanTrue if relative position should be turned on.
returndescription
du.widget.WidgetReference to the current widget.

x

du.widget.Widget.x(x, dim)

Sets the horizontal position of the widget. Default is 0px.
argtypedescription
xnumberPosition value.
dimstringDimension (unit) of the position. Supported values: px, %.
returndescription
du.widget.WidgetReference to the current widget.

y

du.widget.Widget.y(y, dim)

Sets the vertical position of the widget. Default is 0px.
argtypedescription
ynumberPosition value.
dimstringDimension (unit) of the position. Supported values: px, %.
returndescription
du.widget.WidgetReference to the current widget.

width

du.widget.Widget.width(w)

Sets widget width in pixels. Default is 200.
argtypedescription
wnumberWidth in pixels.
returndescription
du.widget.WidgetReference to the current widget.

height

du.widget.Widget.height(h)

Sets widget height in pixels. Default is 150.
argtypedescription
hnumberHeight in pixels.
returndescription
du.widget.WidgetReference to the current widget.

margins

du.widget.Widget.margins(margins)

Sets widget margins. Default is 0 for all sides.
argtypedescription
marginsnumber objectA single number to set all sides or an object specifying some of the sides.
returndescription
du.widget.WidgetReference to the current widget.

borders

du.widget.Widget.borders(borders)

Sets widget borders. Default is null for all sides.
argtypedescription
bordersobjectA string to use for all sides or an object specifying some of the sides.
returndescription
du.widget.WidgetReference to the current widget.

fontColor

du.widget.Widget.fontColor(color)

Sets the font color of the widget. This color is used for axes and all other non-plot type elements. Default is black.
argtypedescription
colorstringColor to set font and axes to.
returndescription
du.widget.WidgetReference to the current widget.

fontSize

du.widget.Widget.fontSize(size)

Sets font size of the widget in pixels. Default is 10.
argtypedescription
sizenumberFont size in pixels.
returndescription
du.widget.WidgetReference to the current widget.

fontWeight

du.widget.Widget.fontWeight(weight)

Sets font weight of the text elements in the widget. Default is normal.
argtypedescription
weightstringFont weight.
returndescription
du.widget.WidgetReference to the current widget.

label

du.widget.Widget.label(text)

Sets the label of the widget. Default is an empty string.
argtypedescription
textstringLabel text.
returndescription
du.widget.WidgetReference to the current widget.

xLabel

du.widget.Widget.xLabel(text)

Sets the horizontal label of the widget. Default is an empty string.
argtypedescription
textstringLabel text.
returndescription
du.widget.WidgetReference to the current widget.

yLabel

du.widget.Widget.yLabel(text)

Sets the vertical label of the widget. Default is an empty string.
argtypedescription
textstringLabel text.
returndescription
du.widget.WidgetReference to the current widget.

xTicks

du.widget.Widget.xTicks(Array)

Sets explicit tick values for the X axis. Note that thick formatting set by xTickFormat still applies. Default it is off (generated automatically).
argtypedescription
Arraynumber[] string[]of numbers or strings.
returndescription
du.widget.WidgetReference to the current widget.

yTicks

du.widget.Widget.yTicks(Array)

Sets explicit tick values for the Y axis. Note that thick formatting set by xTickFormat still applies. Default it is off (generated automatically).
argtypedescription
Arraynumber[] string[]of numbers or strings.
returndescription
du.widget.WidgetReference to the current widget.

tickFormat

du.widget.Widget.tickFormat(format)

Sets the format function for the ticks. Default is an SI prefixed number
argtypedescription
formatfunctionFunction that converts a number to a string.
returndescription
du.widget.WidgetReference to the current widget.

xTickFormat

du.widget.Widget.xTickFormat(format)

Sets the format function for the X axis. Default is an SI prefixed number.
argtypedescription
formatfunctionFunction that converts a number to a string.
returndescription
du.widget.WidgetReference to the current widget.

yTickFormat

du.widget.Widget.yTickFormat(format)

Sets the format function for the Y axis. Default is an SI prefixed number.
argtypedescription
formatfunctionFunction that converts a number to a string.
returndescription
du.widget.WidgetReference to the current widget.

xTickAngle

du.widget.Widget.xTickAngle(angle)

Sets the angle of the horizontal tick labels. Default is 0.
argtypedescription
anglenumberThe angle to set.
returndescription
du.widget.WidgetReference to the current widget.

yMin

du.widget.Widget.yMin(value)

Sets vertical lower boundary of the widget. Default is 0.
argtypedescription
valuenumberValue to set vertical minimum to.
returndescription
du.widget.WidgetReference to the current widget.

mouseover

du.widget.Widget.mouseover(callback)

Sets a callback when various elements of the widget are hovered. The behavior of this callback is specific to the widget type: for chart widgets, it is bound to the plot elements and the plot's name is passed to the specified callback as argument. This can be used as a selector for e.g, highlighting elements in the widget. For the map it is bound to countries and the name of the country is passed as parameter. For standalone widgets such as a label, it is bound to the widget itself. Default is null.
argtypedescription
callbackfunctionCallback to trigger on mouseover.
returndescription
du.widget.WidgetReference to the current widget.

mouseleave

du.widget.Widget.mouseleave(callback)

Sets a callback when the mouse leaves various elements of the widget. The behavior of this callback is specific to the widget type: for chart widgets, it is bound to the plot elements and the plot's name is passed to the specified callback as argument. This can be used as a selector for e.g, highlighting elements in the widget. For the map it is bound to countries and the name of the country is passed as parameter. For standalone widgets such as a label, it is bound to the widget itself. Default is null.
argtypedescription
callbackfunctionCallback to trigger on mouseleave.
returndescription
du.widget.WidgetReference to the current widget.

click

du.widget.Widget.click(callback)

Sets a callback when the various elements of the widget are clicked. The behavior of this callback is specific to the widget type: for chart widgets, it is bound to the plot elements and the plot's name is passed to the specified callback as argument. This can be used as a selector for e.g, highlighting elements in the widget. For the map it is bound to countries and the name of the country is passed as parameter. For standalone widgets such as a label, it is bound to the widget itself. Default is null.
argtypedescription
callbackfunctionCallback to trigger on click.
returndescription
du.widget.WidgetReference to the current widget.

colors

du.widget.Widget.colors(colors)

Sets the color(s) of the widget plot elements. By default, a combination of the Color Brewer schemes Set 1 and Set 3 is used. If single color is defined, a sequential color scheme is generated with the number of categories equal to the keys in data. If a full color mapping is specified, it is used directly without change.
argtypedescription
colorsstring objectSingle color to set all plot elements or an object specifying the color of each plot.
returndescription
du.widget.WidgetReference to the current widget.

tooltip

du.widget.Widget.tooltip(enable)

Enables tooltip for the chart widget. Default is false.
argtypedescription
enablebooleanIf tooltip should be enabled.
returndescription
du.widget.WidgetReference to the current widget.

tooltipTitleFormat

du.widget.Widget.tooltipTitleFormat(format)

Sets the format for the title in the tooltip. Default is just the title itself.
argtypedescription
formatFunctionThe formatting function that takes a string and returns a string.
returndescription
du.widget.WidgetReference to the current widget.

tooltipXFormat

du.widget.Widget.tooltipXFormat(format)

Sets the number format for X values in the tooltip. Default is just the number itself.
argtypedescription
formatFunctionThe formatting function that takes a number and returns a string.
returndescription
du.widget.WidgetReference to the current widget.

tooltipYFormat

du.widget.Widget.tooltipYFormat(format)

Sets the number format for Y values in the tooltip. Default is just the number itself.
argtypedescription
formatFunctionThe formatting function that takes a number and returns a string.
returndescription
du.widget.WidgetReference to the current widget.

tooltipZFormat

du.widget.Widget.tooltipZFormat(format)

Sets the number format for Z values in the tooltip whenever there is a third dimension. Default is just the number itself.
argtypedescription
formatFunctionThe formatting function that takes a number and returns a string.
returndescription
du.widget.WidgetReference to the current widget.

id

du.widget.Widget.id()

Returns the widget ID.
returndescription
stringIdentifier of the current widget.

describe

du.widget.Widget.describe(content)

Adds a description for the widget. A description is a tooltip that is shown if the user right-clicks on the widget. After 15 second or if the user leaves the widget, the description disappears.
argtypedescription
contentstringContent of the description. Can be HTML formatted.
returndescription
du.widget.WidgetReference to the current widget.

placeholder

du.widget.Widget.placeholder(content, offset)

Replaces the widget with a placeholder. Useful for showing missing data.
argtypedescription
contentstringContent to show in place of the widget. Can be HTML formatted. If nothing is passed,
offsetoffsetVertical offset for the placeholder. Default is 0.
returndescription
du.widget.WidgetReference to the current widget.

render

du.widget.Widget.render([duration])

Renders the widget. Note that without calling this method, the widget is not rendered at all. After any changes in style or bound data, this method should be called.
argtypedescription
durationnumberDuration of the rendering transition. If not specified, 500 ms is applied. optional
returndescription
du.widget.WidgetReference to the current widget.

remove

du.widget.Widget.remove()

Removes widget from DOM.