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
The unique identifier for the widget, or null before it’s saved.
The Source the widget reads from, through getSource() and setSource().
The View the widget belongs to, through getView() and setView(). Widgets in a preset have no View.
The Period class the widget fetches data for. It’s ignored while the widget inherits the View’s date range.
Whether the widget uses the dashboard’s date range in place of its own period.
The provider-native metric key the widget shows.
The provider-native dimension key the widget breaks data down by, for table, pie and similar widgets.
The canonical metric key, which Metrix maps to each provider’s own metric. See getResolvedMetric().
The canonical dimension key, which Metrix maps to each provider’s own dimension. See getResolvedDimension().
The widget’s layout width on the dashboard, in thirds of the row.
The title shown on the widget, or null to use the default.
The subtitle shown on the widget, or null for none.
The maximum number of rows for table, pie and similar widgets, from 1 to 500. See getRowLimit().
Methods
Returns the widget’s Source, or null when none is set.
Arguments: SourceInterface|string $source
Sets the widget’s Source from a Source object or a configured Source handle.
Returns the View the widget belongs to, or null when it has none.
Arguments: View $view
Sets the View the widget belongs to.
Returns the provider-native metric after resolving a canonical metric for the widget's Source.
Returns the provider-native dimension after resolving a canonical dimension for the widget's Source.
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.
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();