YOUSEFUL / DELPHI / COMPONENTS

TAtlasGauge

Horizontal bar gauge with a caption, a clamped value and warning and critical colour thresholds.

Visual control Palette: Atlas Unit Atlas.Gauges · Inherits TCustomControl · Product Atlas VCL

Description

TAtlasGauge shows a caption, the current value as text and, along the bottom, a bar filled in proportion to the value within its range. The bar is green below the warning threshold, amber from the warning threshold and red from the critical threshold. Values outside the range are clamped, not rejected.

The default range is 0 to 100 with thresholds at 70 and 90. SetRange resets the thresholds to 70% and 90% of the new range, so call SetThresholds after it. The thresholds cannot be read back.

The three bar colours and the grey track are fixed; TAtlasThemer changes only the background and the text colour. Not implemented: dial or circular styles, tick marks, animation, a change event and value formatting (the value is shown with FloatToStr in the invariant format).

Members

MemberKindWhat it does
CreateconstructorCreates a 240 x 100 gauge with a white background, range 0 to 100, warning 70, critical 90, value 0 and an empty caption.
SetRangemethodSets the range.
SetThresholdsmethodSets the values from which the bar is amber and red.
FractionmethodPosition of Value in the range, from 0 at Minimum to 1 at Maximum.
ValueColormethodBar colour for the current value: $00423FC4 (red) at or above the critical threshold, $002D99CF (amber) at or above the warning threshold, otherwise $00699532 (green).
MinimumpropertyLower end of the range; change it with SetRange.
MaximumpropertyUpper end of the range; change it with SetRange.
ValuepropertyCurrent value, clamped to the range when set.
CaptionpropertyText drawn above the value.
AlignpropertyStandard VCL alignment in the parent.
AnchorspropertyStandard VCL anchors.
ColorpropertyBackground; the constructor sets clWhite.
FontpropertyFont of the caption and the value; the value is drawn bold.
ParentFontpropertyStandard VCL property: use the parent's font.

Constructors

Create constructor

constructor Create(AOwner: TComponent); override;

Creates a 240 x 100 gauge with a white background, range 0 to 100, warning 70, critical 90, value 0 and an empty caption.

Properties

Minimum property

property Minimum: Double read FMinimum;

Lower end of the range; change it with SetRange.

Maximum property

property Maximum: Double read FMaximum;

Upper end of the range; change it with SetRange.

Value property

property Value: Double read FValue write SetValue;

Current value, clamped to the range when set. NaN or infinity raises EArgumentException.

pascal
Gauge.Value := 320;

Caption property

property Caption: string read FCaption write SetCaption;

Text drawn above the value.

Align property

property Align;

Standard VCL alignment in the parent.

Anchors property

property Anchors;

Standard VCL anchors.

Color property

property Color;

Background; the constructor sets clWhite. The bar colours do not depend on it.

Font property

property Font;

Font of the caption and the value; the value is drawn bold.

ParentFont property

property ParentFont;

Standard VCL property: use the parent's font.

Methods

SetRange method

procedure SetRange(Minimum, Maximum: Double);

Sets the range. Both values must be finite with magnitude at most 1E100 and Minimum < Maximum, otherwise EArgumentException and nothing changes. Resets the warning and critical thresholds to 70% and 90% of the range and clamps the current value into it.

pascal
Gauge.SetRange(-50, 50); // thresholds are now 20 and 40

SetThresholds method

procedure SetThresholds(Warning, Critical: Double);

Sets the values from which the bar is amber and red. Requires Minimum <= Warning <= Critical <= Maximum, otherwise EArgumentException. Call it after SetRange.

pascal
Gauge.SetRange(0, 500);
Gauge.SetThresholds(300, 450);

Fraction method

function Fraction: Double;

Position of Value in the range, from 0 at Minimum to 1 at Maximum.

ValueColor method

function ValueColor: TColor;

Bar colour for the current value: $00423FC4 (red) at or above the critical threshold, $002D99CF (amber) at or above the warning threshold, otherwise $00699532 (green).

pascal
Gauge.Value := 95;
if Gauge.ValueColor = $00423FC4 then Beep;

Examples

Queue depth with custom thresholds

A 0 to 500 gauge that is amber from 300 and red from 450.

pascal
uses System.Classes, Vcl.Controls, Atlas.Gauges;

function AddQueueGauge(Owner: TComponent; Parent: TWinControl): TAtlasGauge;
begin
  Result := TAtlasGauge.Create(Owner);
  Result.Parent := Parent;
  Result.Align := alTop;
  Result.Caption := 'Queue depth';
  Result.SetRange(0, 500);
  Result.SetThresholds(300, 450); // after SetRange, which resets the thresholds
  Result.Value := 320;            // amber: at or above 300, below 450
end;

State of a gauge as text

Maps the bar colour to a word, for a status line or a log.

pascal
uses Atlas.Gauges;

function GaugeState(Gauge: TAtlasGauge): string;
begin
  if Gauge.ValueColor = $00423FC4 then Result := 'critical'
  else if Gauge.ValueColor = $002D99CF then Result := 'warning'
  else Result := 'normal';
end;

TAtlasChart · TAtlasThemer

Also in Atlas VCL

TAtlasTable · TAtlasGrid · TAtlasValueEdit · TAtlasTree · TAtlasWorkbook · TAtlasSheetGrid · TAtlasPivot · TAtlasInspector · TAtlasRichEdit · TAtlasSpellChecker · TAtlasChart · TAtlasThemer · TAtlasWizard · TAtlasWorkspace · TAtlasCommandBar · TAtlasActionTile · TAtlasTileBoard · TAtlasNavigation · TAtlasMap · TAtlasGraph · TAtlasDiagram · TAtlasPrintDocument · TAtlasSchedule · TAtlasScheduler · TAtlasTaskPlan · TAtlasGantt · TAtlasPdfDocument · TAtlasPdfViewer