Metric

Description

A component to display a metric

A Metric component displays a key value alongside a title and an optional indicator of change.

Samples

Basic Metrics

Metrics with Change Indicator

Card With Header & Tags

With Tooltips inside title

Metrics with Sparkline Charts

API reference

class

Metric

public class Metric : ComponentBase<Metric, HTMLElement>

A large numeric KPI tile used inside dashboards, showing a value with optional label and trend indicator. Beside the number it can lead with an IconTile - the same rounded, tinted square an OmniResult{T} row leads with - saying what is being counted, and it can hold a chart (a Sparkline, a ContributionBar) under the value to show how the number got there.

Namespace
Tesserae
Inheritance
ComponentBase<Metric, HTMLElement> → Metric

Constructors

NameDescription
MetricInitializes a new instance of this class.
Constructor
Metric
Overload
Metric(string, string)Initializes a new instance of this class.
Metric(IComponent, IComponent)Initializes a new instance of this class.
Metric(string, string)
public Metric(string title, string value) : this(TextBlock(title).SmallPlus().SemiBold().Foreground(Theme.Secondary.Foreground).Render(), TextBlock(value).XLarge().SemiBold().Render())

Initializes a new instance of this class.

Parameters

title string
value string
Metric(IComponent, IComponent)
public Metric(IComponent title, IComponent value) : this(title.Render(), value.Render())

Initializes a new instance of this class.

Parameters

title IComponent
value IComponent

Methods

NameDescription
SetIconPuts an icon on a tile in front of the title and the value, in the given color, over a paler wash of that same color - the same tile an OmniResult{T} row leads with. Pass the full-strength color the glyph should be; a null color leaves the tile neutral.
IconSizeSets how big the leading tile is drawn - 44px square by default, which is the size a KPI wants beside a number two lines tall.
ValueFirstDraws the value above the title rather than under it - the shape a counter takes when the number is the point and the words under it only say what was counted ("5 / In my scope").
CompactDraws the title and the value on one line instead of two - "42 Open tickets" - for a row of counters, a toolbar or a card header that has no room for a tile two lines tall. The title follows the value when ValueFirst is set and leads it otherwise. A change indicator stays on the same line, after both; a chart still goes under them.
ValueBackgroundPuts the value on a filled, rounded background - a badge for the number, to set it apart from the words around it (most of all in a Compact metric). Takes any CSS color, or a theme variable such as var(--tss-primary-background-color); the foreground, when given, recolors the value to match it. A null background takes the fill away again.
ChangeInHeaderPulls the change indicator up onto the title's own line, pushed to its far end - for a card whose trend belongs beside the label rather than under the chart.
ChartConfigures the component to chart.
ChangeConfigures the component to change.
OnClickRegisters a callback invoked when the tile is clicked - to drill into what the number counts. A clickable tile shows the pointer, answers the hover, and becomes keyboard reachable: it is activated with Enter or Space while the tile itself has focus.
RenderRenders the component's root HTML element.
Method
Metric.SetIcon
Overload
SetIcon(UIcons, string, UIconsWeight)Puts an icon on a tile in front of the title and the value, in the given color, over a paler wash of that same color - the same tile an OmniResult{T} row leads with. Pass the full-strength color the glyph should be; a null color leaves the tile neutral.
SetIcon(string, string, TextSize?)Puts a few letters on the tile in place of a glyph - a unit, a currency, a file type - in the given color, over a paler wash of that same color.
SetIcon(IComponent, string)Puts the given component on the tile - an Image, an Avatar, an emoji. A null value takes the tile away again.
SetIcon(UIcons, string, UIconsWeight)
public Metric SetIcon(UIcons icon, string color = null, UIconsWeight weight = UIconsWeight.Regular)

Puts an icon on a tile in front of the title and the value, in the given color, over a paler wash of that same color - the same tile an OmniResult{T} row leads with. Pass the full-strength color the glyph should be; a null color leaves the tile neutral.

Parameters

icon UIcons
color string
weight UIconsWeight
SetIcon(string, string, TextSize?)
public Metric SetIcon(string text, string color = null, TextSize? size = null)

Puts a few letters on the tile in place of a glyph - a unit, a currency, a file type - in the given color, over a paler wash of that same color.

Parameters

text string
color string
size TextSize?
SetIcon(IComponent, string)
public Metric SetIcon(IComponent iconOrImage, string color = null)

Puts the given component on the tile - an Image, an Avatar, an emoji. A null value takes the tile away again.

Parameters

iconOrImage IComponent
color string
Method
Metric.IconSize
public Metric IconSize(UnitSize size)

Sets how big the leading tile is drawn - 44px square by default, which is the size a KPI wants beside a number two lines tall.

Method
Metric.ValueFirst
public Metric ValueFirst(bool value = true)

Draws the value above the title rather than under it - the shape a counter takes when the number is the point and the words under it only say what was counted ("5 / In my scope").

Method
Metric.Compact
public Metric Compact(bool value = true)

Draws the title and the value on one line instead of two - "42 Open tickets" - for a row of counters, a toolbar or a card header that has no room for a tile two lines tall. The title follows the value when ValueFirst is set and leads it otherwise. A change indicator stays on the same line, after both; a chart still goes under them.

Method
Metric.ValueBackground
public Metric ValueBackground(string background, string foreground = null)

Puts the value on a filled, rounded background - a badge for the number, to set it apart from the words around it (most of all in a Compact metric). Takes any CSS color, or a theme variable such as var(--tss-primary-background-color); the foreground, when given, recolors the value to match it. A null background takes the fill away again.

Method
Metric.ChangeInHeader
public Metric ChangeInHeader(bool value = true)

Pulls the change indicator up onto the title's own line, pushed to its far end - for a card whose trend belongs beside the label rather than under the chart.

Method
Metric.Chart
public Metric Chart(IComponent chart)

Configures the component to chart.

Method
Metric.Change
public Metric Change(IComponent change)

Configures the component to change.

Method
Metric.OnClick
Overload
OnClick(ComponentEventHandler<Metric, MouseEvent>, bool)Registers a callback invoked when the tile is clicked - to drill into what the number counts. A clickable tile shows the pointer, answers the hover, and becomes keyboard reachable: it is activated with Enter or Space while the tile itself has focus.
OnClick(Action)Registers a callback invoked when the tile is clicked. See OnClick.
OnClick(ComponentEventHandler<Metric, MouseEvent>, bool)
public override Metric OnClick(ComponentEventHandler<Metric, MouseEvent> onClick, bool clearPrevious = true)

Registers a callback invoked when the tile is clicked - to drill into what the number counts. A clickable tile shows the pointer, answers the hover, and becomes keyboard reachable: it is activated with Enter or Space while the tile itself has focus.

Parameters

onClick ComponentEventHandler<Metric, MouseEvent>
clearPrevious bool
OnClick(Action)
public Metric OnClick(Action action)

Registers a callback invoked when the tile is clicked. See OnClick.

Parameters

action Action
Method
Metric.Render
public override HTMLElement Render()

Renders the component's root HTML element.

See also