📄 teelineargauge.pas
字号:
{**********************************************}
{ TeeChart Linear Gauge style }
{ Copyright (c) 2007 by Steema Software }
{**********************************************}
unit TeeLinearGauge;
{$I TeeDefs.inc}
interface
uses
{$IFNDEF LINUX}
Windows, Messages,
{$ENDIF}
SysUtils, Classes,
{$IFDEF CLX}
QGraphics, QControls, QForms, QDialogs, QStdCtrls, QExtCtrls, QComCtrls,
QButtons,
{$ELSE}
Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons,
{$ENDIF}
TeeNumericGauge, TeCanvas, TeeCustomShapeEditor, Chart, TeeProCo,
TeeProcs, TeEngine, TeePenDlg;
type
TGaugePointerStyles=(gpHand, gpCenter, gpTick, gpMinorTick, gpColorLine);
TGaugeSeriesPointer=class(TSeriesPointer)
private
FGaugeStyle : TGaugePointerStyles;
procedure SetGaugeStyle(const Value: TGaugePointerStyles);
protected
PXMinus,
PXPlus,
PYMinus,
PYPlus : Integer;
PXMinusSmall,
PXPlusSmall,
PYMinusSmall,
PYPlusSmall : Integer;
IStartAngle : Double;
procedure SetValues(x, y, horiz, vert:Integer);
public
procedure Draw(const Inner,InnerPlus,InnerMinus,
Outer,OuterPlus,OuterMinus:TPoint); overload;
published
property GaugeStyle:TGaugePointerStyles read FGaugeStyle write SetGaugeStyle;
end;
TGaugePointerRange=class(TGaugeSeriesPointer)
private
FEndValue : Double;
FStartValue : Double;
procedure SetEndValue(const Value: Double);
procedure SetStartValue(const Value: Double);
public
procedure Draw(const StartAngle,EndAngle:Double; const Rectangle:TRect);
published
property EndValue:Double read FEndValue write SetEndValue;
property StartValue:Double read FStartValue write SetStartValue;
end;
TCustomGaugeMinMax=class(TCustomGauge)
private
FGreenLine : TGaugePointerRange;
FHand : TGaugeSeriesPointer;
FMaximum : TChartValue;
FMinimum : TChartValue;
FMinorDist : Integer;
FMinorTicks : TGaugeSeriesPointer;
FRedLine : TGaugePointerRange;
FTicks : TGaugeSeriesPointer;
IAxisDone : Boolean;
procedure SetAxisOnce;
procedure SetGreenLine(const Value: TGaugePointerRange);
procedure SetHand(const Value: TGaugeSeriesPointer);
procedure SetMaximum(const Value: TChartValue);
procedure SetMinimum(const Value: TChartValue);
procedure SetMinorDist(const Value: Integer);
procedure SetMinorTicks(const Value: TGaugeSeriesPointer);
procedure SetRedLine(const Value: TGaugePointerRange);
procedure SetTicks(const Value: TGaugeSeriesPointer);
protected
IRange : Double;
Procedure AddSampleValues(NumValues:Integer; OnlyMandatory:Boolean=False); override;
function Axis:TChartAxis; virtual; abstract;
procedure DrawAllValues; override;
procedure DrawAxis; virtual; abstract;
procedure DrawAxisMinorTick(const Inner,Outer:TPoint);
procedure DrawAxisTick(const Inner,InnerPlus,InnerMinus,Outer,OuterPlus,OuterMinus:TPoint);
procedure DrawHand; virtual;
Procedure SetParentChart(const Value:TCustomAxisPanel); override;
procedure SetValues; override;
public
Constructor Create(AOwner:TComponent); override;
Destructor Destroy; override;
procedure Assign(Source:TPersistent); override;
property GreenLine:TGaugePointerRange read FGreenLine write SetGreenLine;
property Hand:TGaugeSeriesPointer read FHand write SetHand;
property Maximum:TChartValue read FMaximum write SetMaximum;
property Minimum:TChartValue read FMinimum write SetMinimum;
property MinorTickDistance:Integer read FMinorDist write SetMinorDist default 0;
property MinorTicks:TGaugeSeriesPointer read FMinorTicks write SetMinorTicks;
property RedLine:TGaugePointerRange read FRedLine write SetRedLine;
property Ticks:TGaugeSeriesPointer read FTicks write SetTicks;
published
property ShowInLegend default False;
end;
TLinearGauge=class(TCustomGaugeMinMax)
private
FMaxIndicator : TGaugeSeriesPointer;
FUseValuePalette : Boolean;
FValueArea : TTeeShape;
IAxisRect : TRect;
IMaxValue : TChartValue;
procedure DrawColorLines;
procedure SetMaxIndicator(const Value: TGaugeSeriesPointer);
procedure SetUseValuePalette(const Value: Boolean);
procedure SetValueArea(const Value: TTeeShape);
protected
function Axis:TChartAxis; override;
class Function GetEditorClass:String; override;
procedure DrawAllValues; override;
procedure DrawAxis; override;
procedure DrawHand; override;
Procedure PrepareForGallery(IsEnabled:Boolean); override;
Procedure SetParentChart(const Value:TCustomAxisPanel); override;
procedure SetValue(const AValue: TChartValue); override;
procedure SetValues; override;
public
Constructor Create(AOwner:TComponent); override;
Destructor Destroy; override;
procedure Assign(Source:TPersistent); override;
function UseAxis:Boolean; override;
published
property Active;
property Cursor;
property ParentChart;
property DataSource; { after parentchart }
property PercentFormat;
property ShowInLegend;
property Title;
property ValueFormat;
{ events }
property AfterDrawValues;
property BeforeDrawValues;
property OnAfterAdd;
property OnBeforeAdd;
property OnChange;
property OnClearValues;
property OnClick;
property OnDblClick;
property OnMouseEnter;
property OnMouseLeave;
property XValues;
property YValues;
property Face;
property Frame;
property GreenLine;
property Hand;
property Maximum;
property MaxValueIndicator:TGaugeSeriesPointer read FMaxIndicator write SetMaxIndicator;
property Minimum;
property MinorTickDistance;
property MinorTicks;
property RedLine;
property Ticks;
property UseValueColorPalette:Boolean read FUseValuePalette
write SetUseValuePalette default False;
property Value;
property ValueArea:TTeeShape read FValueArea write SetValueArea;
end;
TLinearGaugeEditor = class(TNumericGaugeEditor)
TabAxis: TTabSheet;
TabGreen: TTabSheet;
TabRed: TTabSheet;
EStartGreen: TEdit;
EEndGreen: TEdit;
UDStartGreen: TUpDown;
UDEndGreen: TUpDown;
BValueArea: TButton;
BMaxIndicator: TButton;
PageControl3: TPageControl;
TabSheet7: TTabSheet;
TabSheet9: TTabSheet;
TabTitle: TTabSheet;
Label4: TLabel;
Label5: TLabel;
Button1: TButton;
ETicks: TEdit;
UDTicks: TUpDown;
UDTicksDist: TUpDown;
ETicksDist: TEdit;
Button2: TButton;
EMinor: TEdit;
UDMinorCount: TUpDown;
UDMinorSize: TUpDown;
Edit2: TEdit;
EMax: TEdit;
EMin: TEdit;
Label6: TLabel;
EFormat: TEdit;
Button6: TButton;
CBLabels: TCheckBox;
Label7: TLabel;
Label10: TLabel;
BRed: TButton;
EStartRed: TEdit;
EEndRed: TEdit;
UDStartRed: TUpDown;
UDEndRed: TUpDown;
BGreen:TButton;
BLinearHand: TButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure CBLabelsClick(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure EFormatChange(Sender: TObject);
procedure BGreenClick(Sender: TObject);
procedure EStartGreenChange(Sender: TObject);
procedure EEndGreenChange(Sender: TObject);
procedure EMinChange(Sender: TObject);
procedure EMaxChange(Sender: TObject);
procedure BValueAreaClick(Sender: TObject);
procedure BMaxIndicatorClick(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Edit2Change(Sender: TObject);
procedure EMinorChange(Sender: TObject);
procedure ETicksChange(Sender: TObject);
procedure ETicksDistChange(Sender: TObject);
procedure BLinearHandClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
{$IFNDEF CLX}
{$IFNDEF LCL}
{$R *.DFM}
{$ENDIF}
{$ELSE}
{$R *.xfm}
{$ENDIF}
uses
Math, TeePoEdi, TeeEdiFont, TeeEdiAxis;
const
BlackPalette : Array[0..23] of TColor = (
$282828,
$323232,
$646464,
$0F0F0F,
$484848,
$0F0F0F,
$282864, // 6
clNone,
$646464,
$646464,
clNone,
$1EC81E,
$3C73C8, // 12
clRed, //$3C73C8,
$3C73C8,
$0A3296,
$828282, // 16
$828282,
clNone,
$1E1E1E,
$646464,
$646464,
$646464,
$646464
);
{ TLinearGauge }
Constructor TLinearGauge.Create(AOwner: TComponent);
begin
inherited;
FValueArea:=TTeeShape.Create(nil);
FValueArea.Transparent:=True;
Value:=Round(Random(100));
IMaxValue:=100;
FRedLine.FStartValue:=80;
FRedLine.FEndValue:=100;
FGreenLine.FStartValue:=0;
FGreenLine.FEndValue:=40;
FMaxIndicator:=TGaugeSeriesPointer.Create(Self);
FMaxIndicator.Style:=psTriangle;
FMaxIndicator.Brush.Color:=clRed;
FMaxIndicator.VertSize:=5;
FMaxIndicator.Draw3D:=False;
end;
Destructor TLinearGauge.Destroy;
begin
FMaxIndicator.Free;
FValueArea.Free;
inherited;
end;
procedure TLinearGauge.Assign(Source: TPersistent);
begin
if Source is TLinearGauge then
with TLinearGauge(Source) do
begin
Self.MaxValueIndicator:=MaxValueIndicator;
Self.FUseValuePalette:=FUseValuePalette;
Self.ValueArea:=ValueArea;
end;
inherited;
end;
function TLinearGauge.UseAxis:Boolean;
begin
result:=False;
end;
procedure TLinearGauge.DrawAllValues;
function GetPixelValue(const Value:Double):Integer;
begin
if IRange=0 then
result:=0
else
result:=Round((Value - Minimum) *
( (IAxisRect.Right-IAxisRect.Left) / IRange));
end;
begin
inherited;
if FMaxIndicator.Visible then
begin
FMaxIndicator.PrepareCanvas(ParentChart.Canvas,FMaxIndicator.Color);
FMaxIndicator.Draw(IAxisRect.Left + GetPixelValue(IMaxValue),IAxisRect.Bottom);
end;
end;
procedure TLinearGauge.DrawHand;
var pixelStep : Double;
tmp : Integer;
begin
if Hand.Visible then
begin
if UseValueColorPalette then
with Hand.Gradient do
begin
Visible:= True;
Direction := gdLeftRight;
end
else
Hand.Gradient.Visible := False;
Hand.PrepareCanvas(ParentChart.Canvas,Hand.Color);
pixelStep:=( (IAxisRect.Right-IAxisRect.Left) / IRange) * (Value-Minimum);
Hand.Draw3D:=False;
tmp:=Round(pixelStep*0.5);
if tmp<>0 then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -