Contribution Bar
Description
A stacked horizontal bar showing how weighted segments add up to a total
ContributionBar renders a single horizontal bar divided into colored segments, each sized proportionally to its value. An optional legend below the bar lists every segment with its label and numeric value. It is useful for making the composition of a score visible at a glance — for example, showing how each signal contributes to a similarity score.
Add segments with Add. By default the bar fills entirely (full width equals the sum of all segments). Call Max to pin the full-width value; when the segments sum to less than that value, the remaining space is left as an empty track.
Segments are colored using a built-in eight-color palette. Pass an explicit CSS color string to Add to override the palette color for a specific segment.
API reference
public sealed class ContributionBar : ComponentBase<ContributionBar, HTMLElement>A single stacked horizontal bar that shows how a set of weighted components add up to a total (for example, how each signal contributes to a similarity score). Each segment is sized proportionally to its value and gets a distinct color, and an optional legend lists every segment with its label and numeric value.
Remarks
Add segments with Add. By default the bar fills entirely (the largest extent equals the sum of all segments); call Max to pin the full-width value so a remainder track is shown when the segments do not reach it.
- Namespace
- Tesserae
- Inheritance
- ComponentBase<ContributionBar, HTMLElement> → ContributionBar
Constructors
| Name | Description |
|---|---|
| ContributionBar | Initializes a new instance of this class. |
Methods
| Name | Description |
|---|---|
| Add | Adds a contribution segment. When color is null a color is picked from DefaultPalette based on the segment's position. |
| Max | Pins the value that corresponds to a full-width bar. When the segments sum to less than this value the remaining space is rendered as an empty track. Defaults to the sum of all segments. |
| ShowLegend | Controls whether the legend below the bar is shown. Defaults to true. |
| HideLegend | Hides the legend below the bar. |
| ShowValues | Controls whether the numeric value of each segment is shown in the legend. Defaults to true. |
| Decimals | Sets the number of decimal places used when formatting segment values. Defaults to 2. |
| Thickness | Sets the thickness (height) of the bar. Defaults to 10px. |
| Render | Renders the component's root HTML element. |
public ContributionBar Add(string label, double value, string color = null)Adds a contribution segment. When color is null a color is picked from DefaultPalette based on the segment's position.
public ContributionBar Max(double max)Pins the value that corresponds to a full-width bar. When the segments sum to less than this value the remaining space is rendered as an empty track. Defaults to the sum of all segments.
public ContributionBar ShowLegend(bool show = true)Controls whether the legend below the bar is shown. Defaults to true.
public ContributionBar ShowValues(bool show = true)Controls whether the numeric value of each segment is shown in the legend. Defaults to true.
public ContributionBar Decimals(int decimals)Sets the number of decimal places used when formatting segment values. Defaults to 2.
public ContributionBar Thickness(UnitSize size)Sets the thickness (height) of the bar. Defaults to 10px.
Fields
| Name | Description |
|---|---|
| DefaultPalette | The default color palette used for segments that do not specify an explicit color, cycled in order. |
public static readonly string[] DefaultPalette = { Theme.Colors.Blue500, Theme.Colors.Teal500, Theme.Colors.Green500, Theme.Colors.Orange500, Theme.Colors.Purple500, Theme.Colors.Magenta500, Theme.Colors.Red500, Theme.Colors.Blue400, }The default color palette used for segments that do not specify an explicit color, cycled in order.
Samples
Basic contribution bar
With a fixed maximum (remainder track)
When the sum of segments is less than the pinned maximum, the remaining space is shown as an empty track.
Custom colors and thicker bar
Pass an explicit CSS color string as the third argument to Add to override the palette for that segment. Use Thickness to increase the bar height.
Legend hidden, integer values
Similarity score breakdown
A typical use case: showing how each signal contributes to a ranked search result score.