📄 teelineargauge.pas
字号:
begin
Hand.HorizSize:=tmp;
tmp:=(IAxisRect.Bottom-IAxisRect.Top) div 2;
if tmp<>0 then
begin
Hand.VertSize:=tmp;
Hand.Draw(IAxisRect.Left+Hand.HorizSize, IAxisRect.Top+Hand.VertSize,
Hand.Color,psRectangle);
end;
end;
end;
end;
class function TLinearGauge.GetEditorClass: String;
begin
result:='TLinearGaugeEditor';
end;
procedure TLinearGauge.SetMaxIndicator(const Value: TGaugeSeriesPointer);
begin
FMaxIndicator.Assign(Value);
end;
procedure TLinearGauge.SetUseValuePalette(const Value: Boolean);
begin
SetBooleanProperty(FUseValuePalette,Value);
end;
procedure TLinearGauge.SetValue(const AValue: TChartValue);
begin
if AValue>IMaxValue then
IMaxValue:=AValue;
inherited;
end;
procedure TLinearGauge.SetValueArea(const Value: TTeeShape);
begin
FValueArea.Assign(Value);
end;
type
TAxisAccess=class(TChartAxis);
procedure TLinearGauge.DrawAxis;
procedure CalcAxisRectangle;
var tmp : Integer;
begin
with IAxisRect do
begin
tmp:=Round((INewRect.Right-INewRect.Left) * 0.8);
Left := (INewRect.Left + ((INewRect.Right-INewRect.Left) div 2)) - (tmp div 2);
Right:=Left+tmp;
tmp:=Ticks.VertSize;
Top := INewRect.Top + (((INewRect.Bottom-INewRect.Top) - tmp) div 2);
Bottom:=Top+tmp;
end;
end;
var tmpS : String;
tmpValue, tmpStep, tmpStep2,
tmpWidth,
pixelStep,
pixelStepMin : Double;
tmp,
count,
tmpW,
tmpFontH, t:Integer;
P3Minus,
P3Plus,
P4Minus,
P4Plus,
P3, P4 : TPoint;
tmpAxis : Boolean;
begin
if (Axis<>nil) and Axis.Visible then
begin
Axis.Increment := IRange * 0.1;
tmpStep := Axis.Increment;
CalcAxisRectangle;
ParentChart.Canvas.AssignVisiblePen(Axis.Axis);
tmpAxis:=Axis.Axis.Visible and (Axis.Axis.Width > 0);
tmp:=Axis.Axis.Width div 2;
if tmpAxis then
begin
InflateRect(IAxisRect,Axis.Axis.Width,Axis.Axis.Width);
OffsetRect(IAxisRect,tmp,tmp);
end;
ValueArea.DrawRectRotated(ParentChart,IAxisRect);
if tmpAxis then
begin
InflateRect(IAxisRect,-Axis.Axis.Width,-Axis.Axis.Width);
OffsetRect(IAxisRect,-tmp,-tmp);
end;
tmpW:=(IAxisRect.Right-IAxisRect.Left);
if Axis.Title.Visible and (Axis.Title.Caption<>'') then
TAxisAccess(Axis).DrawTitle(IAxisRect.Left+(tmpW div 2),
IAxisRect.Bottom +
(ParentChart.Canvas.FontHeight div 2));
if Axis.Ticks.Visible or Axis.Labels then
begin
Axis.TickLength:=Ticks.VertSize;
Axis.Ticks.Assign(Ticks.Pen);
ParentChart.Canvas.AssignFont(Axis.LabelsFont);
ParentChart.Canvas.AssignVisiblePen(Ticks.Pen);
tmpFontH:=ParentChart.Canvas.FontHeight;
if (IRange<>0) and (tmpStep<>0) then
begin
tmpValue := Minimum;
pixelStep := tmpW / IRange;
pixelStep :=pixelStep*tmpStep;
count:=0;
repeat
P3 := TeePoint(IAxisRect.Left + Round(pixelStep * count), IAxisRect.Top);
P4 := TeePoint(P3.X, P3.Y + (IAxisRect.Bottom-IAxisRect.Top)); //(IAxisRectangle.Height - Axis.AxisPen.Width));
P3Minus := TeePoint(P3.X - Round(Ticks.HorizSize * 0.5), P3.Y);
P3Plus := TeePoint(P3.X + Round(Ticks.HorizSize * 0.5), P3.Y);
P4Minus := TeePoint(P4.X - Round(Ticks.HorizSize * 0.5), P4.Y);
P4Plus := TeePoint(P4.X + Round(Ticks.HorizSize * 0.5), P4.Y);
DrawAxisTick(P3, P3Plus, P3Minus, P4, P4Plus, P4Minus);
if Axis.Labels then
begin
tmpS := FormatFloat(ValueFormat, tmpValue);
tmpWidth := ParentChart.Canvas.TextWidth(tmpS);
ParentChart.Canvas.BackMode:=cbmTransparent;
ParentChart.Canvas.TextOut(P3.X - Round(tmpWidth * 0.6), P3.Y - tmpFontH, tmpS);
end;
tmpValue :=tmpValue+tmpStep;
Inc(count);
until tmpValue>Maximum;
end;
if (IRange<>0) and Axis.MinorTicks.Visible and (Axis.MinorTickCount>0) then
begin
Axis.MinorTickLength := MinorTicks.VertSize;
Axis.MinorTicks.Assign(MinorTicks.Pen);
ParentChart.Canvas.AssignVisiblePen(MinorTicks.Pen);
if tmpStep<>0 then
begin
tmpStep2 := tmpStep / (Axis.MinorTickCount + 1);
tmpValue := Minimum;
count := 0;
pixelStep := tmpW / IRange;
pixelStepMin := pixelStep * tmpStep2;
pixelStep :=pixelStep * tmpStep;
repeat
for t:=1 to Axis.MinorTickCount do
begin
P3 := TeePoint(IAxisRect.Left + Round(pixelStep * count) +
Round(pixelStepMin * t), IAxisRect.Top + MinorTickDistance);
P4 := TeePoint(P3.X, P3.Y + (((IAxisRect.Bottom-IAxisRect.Top) - Axis.Axis.Width) div 2 ));
DrawAxisMinorTick(P3, P4);
end;
Inc(count);
tmpValue:=tmpValue+tmpStep;
until not (tmpValue <= (Maximum - tmpStep));
end;
end;
end;
end;
DrawColorLines;
end;
procedure TLinearGauge.DrawColorLines;
procedure DrawColorLine(Line:TGaugePointerRange);
var pixelStep,
tmpStart,
tmpEnd : Double;
tmpR : TRect;
begin
if Line.Visible then
begin
pixelStep := (IAxisRect.Right-IAxisRect.Left) / IRange;
tmpStart := pixelStep * (Line.StartValue - Minimum);
tmpEnd := pixelStep * (Line.EndValue - Minimum);
ParentChart.Canvas.AssignVisiblePen(Line.Pen);
ParentChart.Canvas.AssignBrush(Line.Brush);
tmpR:=TeeRect(IAxisRect.Left + Round(tmpStart),
IAxisRect.Bottom + Axis.Axis.Width,
IAxisRect.Left + Round(tmpEnd),
IAxisRect.Bottom + Axis.Axis.Width + Line.VertSize);
if Line.Gradient.Visible then
begin
Line.Gradient.Draw(ParentChart.Canvas,tmpR);
ParentChart.Canvas.Brush.Style:=bsClear;
end;
ParentChart.Canvas.Rectangle(tmpR);
end;
end;
begin
DrawColorLine(RedLine);
DrawColorLine(GreenLine);
end;
function TLinearGauge.Axis:TChartAxis;
begin
result:=GetHorizAxis;
end;
procedure TLinearGauge.SetParentChart(const Value: TCustomAxisPanel);
begin
inherited;
if not (csDestroying in ComponentState) then
begin
MaxValueIndicator.ParentChart:=ParentChart;
ValueArea.ParentChart:=ParentChart;
end;
end;
procedure TLinearGauge.SetValues;
begin
CalcOrigRect;
INewRect:=IOrigRect;
inherited;
end;
procedure TLinearGauge.PrepareForGallery(IsEnabled: Boolean);
begin
inherited;
Axis.Labels:=False;
Axis.Title.Hide;
Value:=Random(100);
end;
{ TCustomGaugeMinMax }
Constructor TCustomGaugeMinMax.Create(AOwner: TComponent);
procedure SetLineProperties(Line:TGaugePointerRange; Color1,Color2,Color3:Integer);
begin
with Line do
begin
GaugeStyle:=gpColorLine;
VertSize:=5;
Brush.Style:=bsSolid;
Brush.Color:=GetPaletteColor(Color3);
with Gradient do
begin
Visible:=True;
Direction:=gdLeftRight;
StartColor:=GetPaletteColor(Color1);
MidColor:=GetPaletteColor(Color2);
EndColor:=GetPaletteColor(Color3);
end;
end;
end;
begin
inherited;
SetGaugePalette(BlackPalette);
FGreenLine:=TGaugePointerRange.Create(Self);
SetLineProperties(FGreenLine,9,10,11);
FRedLine:=TGaugePointerRange.Create(Self);
SetLineProperties(FRedLine,6,7,8);
FMinorTicks:=TGaugeSeriesPointer.Create(Self);
with FMinorTicks do
begin
GaugeStyle:=gpMinorTick;
Color:=clNone;
VertSize:=1;
HorizSize:=1;
Pen.Color:=GetPaletteColor(23);
end;
FTicks:=TGaugeSeriesPointer.Create(Self);
with FTicks do
begin
GaugeStyle:=gpTick;
Brush.Style:=bsClear;
VertSize:=10;
Pen.Color:=GetPaletteColor(22);
end;
FHand:=TGaugeSeriesPointer.Create(Self);
FHand.FGaugeStyle:=gpHand;
FHand.Brush.Color:=clRed;
FHand.Transparency:=70;
FHand.Pen.Color:=GetPaletteColor(12);
CalcVisiblePoints:=False;
ShowInLegend:=False;
FMaximum:=100;
end;
Destructor TCustomGaugeMinMax.Destroy;
begin
FHand.Free;
FGreenLine.Free;
FMinorTicks.Free;
FRedLine.Free;
FTicks.Free;
inherited;
end;
procedure TCustomGaugeMinMax.Assign(Source: TPersistent);
begin
if Source is TCustomGaugeMinMax then
with TCustomGaugeMinMax(Source) do
begin
Self.GreenLine :=GreenLine;
Self.Hand :=Hand;
Self.FMaximum :=FMaximum;
Self.FMinimum :=FMinimum;
Self.FMinorDist :=FMinorDist;
Self.MinorTicks :=MinorTicks;
Self.RedLine :=RedLine;
Self.Ticks :=Ticks;
end;
inherited;
end;
procedure TCustomGaugeMinMax.DrawHand;
begin
end;
Procedure TCustomGaugeMinMax.SetParentChart(const Value:TCustomAxisPanel);
begin
inherited;
if not (csDestroying in ComponentState) then
begin
GreenLine.ParentChart:=ParentChart;
Hand.ParentChart:=ParentChart;
RedLine.ParentChart:=ParentChart;
MinorTicks.ParentChart:=ParentChart;
Ticks.ParentChart:=ParentChart;
end;
if not IAxisDone then
SetAxisOnce;
end;
procedure TCustomGaugeMinMax.SetAxisOnce;
begin
if (Axis<>nil) then
with Axis do
begin
Axis.Visible:=True;
Title.Visible:=True;
Title.Caption:='Axis Title %';
Title.Font.Color:=GetPaletteColor(21);
Labels:=True;
LabelsFont.Color:=GetPaletteColor(20);
LabelsFont.Name:='Arial';
LabelsFont.Size:=10;
LabelsFont.Style:=[fsBold];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -