TrendBadge

Description

TrendBadge is a small pill showing how a figure moved: an arrow and the size of the change. Use it for week-on-week deltas in KPI tables and dashboards, next to a Sparkline or inside a Metric.

The arrow shows the direction (TrendDirection.Up, Down or Flat). The color shows the sentiment (TrendSentiment.Good, Bad or Neutral): green for good news, red for bad news, gray for a figure with no good direction. The two are independent, so a falling cost is an arrow down in green and a falling revenue is an arrow down in red.

TrendBadge.For derives both from the sign of the change and from which way is better. A change of zero draws a flat, neutral badge.

Samples

Derived from the change

higherIsBetter defaults to true: a rise is green and a fall is red. A change of zero is flat and gray whatever higherIsBetter says.

Lower is better

A falling cost is an arrow down in green. A rising error rate is an arrow up in red.

Set direction and sentiment directly

The constructor takes the text, a direction (Flat by default) and a sentiment (Neutral by default). Direction, Sentiment, Good, Bad and Neutral change them afterwards, and SetText changes the text.

API reference

enum

TrendDirection

public enum TrendDirection

Which way a value moved.

Namespace
Tesserae
enum

TrendSentiment

public enum TrendSentiment

Whether a movement is good news. The direction and the sentiment are independent: a falling cost is Good, a falling revenue is Bad, and a figure with no target to judge it against is Neutral.

Namespace
Tesserae
class

TrendBadge

public sealed class TrendBadge : ComponentBase<TrendBadge, HTMLElement>

A small pill saying how a figure moved - an arrow and the size of the change ("↓ £31", "↑ 1.7pp") - colored by whether that movement is good for the metric rather than by its direction: green is good news, red is bad news, grey is a figure with no good direction.

Remarks

Use For to derive both from the sign of the change and which way is better.

Namespace
Tesserae
Inheritance
ComponentBase<TrendBadge, HTMLElement> → TrendBadge

Constructors

NameDescription
TrendBadgeInitializes a new instance of this class.
Constructor
TrendBadge
public TrendBadge(string text, TrendDirection direction = TrendDirection.Flat, TrendSentiment sentiment = TrendSentiment.Neutral)

Initializes a new instance of this class.

Methods

NameDescription
ForBuilds a badge from the signed size of a change: the arrow follows its sign, and the color says whether that is good news given which way is better for the metric.
SetTextSets the text of the badge.
DirectionSets which way the arrow points.
SentimentSets whether the movement is good or bad news, which decides the color.
GoodThe movement is good news.
BadThe movement is bad news.
NeutralThe movement is neither: a figure with no target or no good direction.
RenderRenders the component's root HTML element.
Method
TrendBadge.For
public static TrendBadge For(double change, string text, bool higherIsBetter = true)

Builds a badge from the signed size of a change: the arrow follows its sign, and the color says whether that is good news given which way is better for the metric.

Parameters

change
The signed change; zero draws a flat, neutral badge.
text
The text to show - the formatted change, typically without its sign.
higherIsBetter
False for a metric where less is better (cost, churn, errors).
Method
TrendBadge.SetText
public TrendBadge SetText(string text)

Sets the text of the badge.

Method
TrendBadge.Direction
public TrendBadge Direction(TrendDirection direction)

Sets which way the arrow points.

Method
TrendBadge.Sentiment
public TrendBadge Sentiment(TrendSentiment sentiment)

Sets whether the movement is good or bad news, which decides the color.

Method
TrendBadge.Good
public TrendBadge Good()

The movement is good news.

Method
TrendBadge.Bad
public TrendBadge Bad()

The movement is bad news.

Method
TrendBadge.Neutral
public TrendBadge Neutral()

The movement is neither: a figure with no target or no good direction.

Method
TrendBadge.Render
public override HTMLElement Render()

Renders the component's root HTML element.

See also