Reference

Widget

A Widget object stores one dashboard component's Source, View, metric and display settings. Obtain widgets through Metrix's Widgets service when extending dashboard behaviour, and use the control panel for ordinary widget configuration.

Properties

id

The unique identifier for the widget, or null before it’s saved.

source

The Source the widget reads from, through getSource() and setSource().

view

The View the widget belongs to, through getView() and setView(). Widgets in a preset have no View.

period

The Period class the widget fetches data for. It’s ignored while the widget inherits the View’s date range.

inheritPeriod

Whether the widget uses the dashboard’s date range in place of its own period.

metric

The provider-native metric key the widget shows.

dimension

The provider-native dimension key the widget breaks data down by, for table, pie and similar widgets.

canonicalMetric

The canonical metric key, which Metrix maps to each provider’s own metric. See getResolvedMetric().

canonicalDimension

The canonical dimension key, which Metrix maps to each provider’s own dimension. See getResolvedDimension().

width

The widget’s layout width on the dashboard, in thirds of the row.

title

The title shown on the widget, or null to use the default.

subtitle

The subtitle shown on the widget, or null for none.

limit

The maximum number of rows for table, pie and similar widgets, from 1 to 500. See getRowLimit().

Methods

getSource()

Returns the widget’s Source, or null when none is set.

setSource()

Arguments: SourceInterface|string $source

Sets the widget’s Source from a Source object or a configured Source handle.

getView()

Returns the View the widget belongs to, or null when it has none.

setView()

Arguments: View $view

Sets the View the widget belongs to.

getResolvedMetric()

Returns the provider-native metric after resolving a canonical metric for the widget's Source.

getResolvedDimension()

Returns the provider-native dimension after resolving a canonical dimension for the widget's Source.

getResolvedPeriod()

Arguments: ?string $globalPeriod = null

Returns the supplied global period when the widget inherits the dashboard range, otherwise the widget's configured period. An inheriting widget with neither value uses Last 30 Days.

getRowLimit()

Returns the effective row limit for dimension widgets. The default is 10 and the maximum is 500.

The following example assigns a configured Source by handle and inspects the provider-native values Metrix will request:

$widget->setSource('analytics');

$metric = $widget->getResolvedMetric();
$dimension = $widget->getResolvedDimension();