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
public enum TrendDirectionWhich way a value moved.
- Namespace
- Tesserae
public enum TrendSentimentWhether 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
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
| Name | Description |
|---|---|
| TrendBadge | Initializes a new instance of this class. |
Methods
| Name | Description |
|---|---|
| For | 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. |
| SetText | Sets the text of the badge. |
| Direction | Sets which way the arrow points. |
| Sentiment | Sets whether the movement is good or bad news, which decides the color. |
| Good | The movement is good news. |
| Bad | The movement is bad news. |
| Neutral | The movement is neither: a figure with no target or no good direction. |
| Render | Renders the component's root HTML element. |
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).
public TrendBadge Direction(TrendDirection direction)Sets which way the arrow points.
public TrendBadge Sentiment(TrendSentiment sentiment)Sets whether the movement is good or bad news, which decides the color.
public TrendBadge Neutral()The movement is neither: a figure with no target or no good direction.