Metric
MetricModule builds dashboard widgets from server-side PHP configuration. It is additive and does not change CounterModule, ChartLineModule, or ChartBarModule.
Use AlexKudrya\Adminix\Modules\Metric\Metric builders:
Result:
value metrics render a counter-styled number card;
trend metrics render a line chart and can add a dashed previous-period series;
partition metrics render a grouped bar chart;
progress metrics render a counter-styled value card with a progress bar.
When a value/progress metric has previous-period comparison data, Adminix renders the smaller delta text inline beside the main value so the card keeps the same vertical rhythm as CounterModule.
Configuration
Common methods:
name()is required and unique on the page.title()is the visible widget title.dataSource()accepts an Eloquent model class or table name.criteria()applies server-side query scope before aggregation.aggregate()acceptscount,sum,avg,min, ormax.aggregate('sum', 'amount')sets both aggregate and aggregate field. Non-count aggregates requireaggregateField().format()controls displayed card values. Supported values are default number formatting,percent, anddecimal:n.
Trend methods:
dateField()selects the date/datetime column, defaulting tocreated_at.bucket()acceptsMetricDateBucketEnum::DAY,WEEK, orMONTH.range()accepts onlyMetricRangePresetEnumvalues:LAST_7_DAYS,LAST_30_DAYS,LAST_90_DAYS, orLAST_12_MONTHS.comparePreviousPeriod()adds a previous-period comparison for value and trend metrics.
Partition methods:
groupBy()is required and defines the grouping field.limit()caps the number of grouped bars.
Progress methods:
target()is required and must be greater than zero.
Safety
Metric ranges are server-side presets, not browser-provided raw dates. Do not use metrics as an authorization boundary; keep tenant/user scope in criteria(). Invalid aggregate names, range presets, missing aggregate fields, missing trend date fields, and invalid progress targets fail with controlled package errors.
Aggregations are covered by SQLite-compatible Testbench tests.