📄 teegauges.pas
字号:
SinCos(TeePiStep*tmpAngle,tmpsin,tmpCos);
Inc(P3.x,Round(TextWidth(tmpS)*0.5*tmpCos));
if (tmpAngle>180) and (tmpAngle<360) then
Inc(P3.y,Round(FontHeight*tmpSin));
end;
TextOut(P3.x,P3.y,tmpS);
end;
tmpValue:=tmpValue+tmpStep;
Until ((TotalAngle<360) and (tmpValue>Maximum)) or
((TotalAngle>=360) and (tmpValue>=Maximum));
end;
end;
// minor ticks
if Axis.MinorTicks.Visible and (Axis.MinorTickCount>0) then
begin
AssignVisiblePen(Axis.MinorTicks);
tmpXRad:=XRadius-Axis.MinorTickLength-MinorTickDistance;
tmpYRad:=YRadius-Axis.MinorTickLength-MinorTickDistance;
if tmpStep<>0 then
begin
tmpStep2:=tmpStep/(Axis.MinorTickCount+1);
tmpValue:=Minimum;
repeat
DrawMinorTicks(tmpValue);
tmpValue:=tmpValue+tmpStep;
Until tmpValue>(Maximum-tmpStep);
if tmpValue<Maximum then
DrawMinorTicks(tmpValue);
end;
end;
// axis
if Axis.Axis.Visible then DrawAxis;
// value line
if Self.Pen.Visible then DrawValueLine;
end;
end;
Function TGaugeSeries.Clicked(x,y:Integer):Integer;
var P0,P1 : TPoint;
begin
CalcLinePoints(P0,P1);
if Assigned(ParentChart) then
ParentChart.Canvas.Calculate2DPosition(X,Y,MiddleZ);
if PointInLine(TeePoint(x,y),P0,P1,2) then
result:=0
else
result:=TeeNoPointClicked;
end;
function TGaugeSeries.SizePointer(APointer:TSeriesPointer):Integer;
begin
if APointer.Visible then
begin
result:=2*APointer.VertSize;
if APointer.Pen.Visible then Inc(result,APointer.Pen.Width);
end
else result:=0;
end;
procedure TGaugeSeries.CalcLinePoints(var P0,P1:TPoint);
var tmp : Double;
tmpRange : Double;
tmpDist : Integer;
begin
tmpRange:=Maximum-Minimum;
if tmpRange=0 then
tmp:=0.5*Pi
else
tmp:=TeePiStep*(360-(TotalAngle-((Value-Minimum)*TotalAngle/tmpRange))+RotationAngle);
P1:=CalcPoint(tmp,ICenter,XRadius,YRadius);
tmpDist:=HandDistance+SizePointer(FEndPoint);
if tmpDist>0 then
P1:=PointAtDistance(ICenter,P1,tmpDist);
if FCenter.Visible and (FCenter.Style=psCircle) then
P0:=PointAtDistance(P1,ICenter,SizePointer(FCenter) div 2)
else
P0:=ICenter;
end;
procedure TGaugeSeries.DrawValueLine;
var tmp : Double;
P4 : TPoint;
tmpCenter : TPoint;
begin
CalcLinePoints(tmpCenter,P4);
if not FullRepaint then Pen.Mode:=pmNotXor
else Pen.Mode:=pmCopy;
ParentChart.Canvas.AssignVisiblePen(Pen);
if HandStyle=hsLine then
ParentChart.Canvas.Line(tmpCenter,P4)
else
begin
tmp:=ArcTan2(P4.y-tmpCenter.X,P4.x-tmpCenter.Y);
ParentChart.Canvas.Polygon([CalcPoint(tmp,tmpCenter,4,4),P4,CalcPoint(tmp+Pi,tmpCenter,4,4)]);
end;
// end point
if FEndPoint.Visible then
begin
if not FullRepaint then FEndPoint.Pen.Mode:=pmNotXor
else FEndPoint.Pen.Mode:=pmCopy;
FEndPoint.PrepareCanvas(ParentChart.Canvas,FEndPoint.Color);
if not FullRepaint then ParentChart.Canvas.Brush.Style:=bsClear;
P4:=PointAtDistance(ICenter,P4,-SizePointer(FEndPoint) div 2);
FEndPoint.Draw(P4);
end;
end;
procedure TGaugeSeries.SetAngle(const Value: Double);
begin
SetDoubleProperty(FAngle,Value);
end;
procedure TGaugeSeries.SetCenter(const Value: TSeriesPointer);
begin
FCenter.Assign(Value);
end;
procedure TGaugeSeries.SetDistance(const Value: Integer);
begin
SetIntegerProperty(FDistance,Value);
end;
procedure TGaugeSeries.SetMax(const AValue: Double);
begin
SetDoubleProperty(FMax,AValue);
Value:=Math.Min(Maximum,Value);
end;
procedure TGaugeSeries.SetMin(const AValue: Double);
begin
SetDoubleProperty(FMin,AValue);
Value:=Math.Max(Minimum,Value);
end;
procedure TGaugeSeries.SetParentChart(const Value: TCustomAxisPanel);
begin
inherited;
if not (csDestroying in ComponentState) then
begin
FCenter.ParentChart:=ParentChart;
FEndPoint.ParentChart:=ParentChart;
end;
if Assigned(ParentChart) then
begin
with TCustomChart(ParentChart) do
begin
Walls.Visible:=False;
View3D:=False;
Frame.Hide;
end;
Axis.TickLength:=14;
Axis.MinorTickLength:=6;
end;
end;
procedure TGaugeSeries.SetStyle(const Value: THandStyle);
begin
if FStyle<>Value then
begin
FStyle:=Value;
Repaint;
end;
end;
procedure TGaugeSeries.SetValue(const AValue: Double);
begin
if Value<>AValue then
begin
if not FullRepaint then DrawValueLine;
MandatoryValueList.Value[0]:=AValue;
if FullRepaint then Repaint
else DrawValueLine;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
procedure TGaugeSeries.SetFullRepaint(const Value: Boolean);
begin
SetBooleanProperty(FFullRepaint,Value);
end;
function TGaugeSeries.GetValue: Double;
begin
if Count=0 then Add(0);
result:=MandatoryValueList.Value[0];
end;
procedure TGaugeSeries.SetEndPoint(const Value: TSeriesPointer);
begin
FEndPoint.Assign(Value);
end;
procedure TGaugeSeries.AddSampleValues(NumValues: Integer; OnlyMandatory:Boolean=False);
begin
Value:=Minimum+(Maximum-Minimum)*Random;
end;
procedure TGaugeSeries.PrepareForGallery(IsEnabled: Boolean);
begin
inherited;
with Axis do
begin
MinorTickCount:=1;
TickLength:=4;
MinorTickLength:=2;
Increment:=25;
end;
HandDistance:=3;
Center.VertSize:=2;
Center.HorizSize:=2;
FullRepaint:=True;
if IsEnabled then Pen.Color:=clBlue
else Pen.Color:=clDkGray;
end;
function TGaugeSeries.NumSampleValues: Integer;
begin
result:=1;
end;
procedure TGaugeSeries.SetMinorDistance(const Value: Integer);
begin
SetIntegerProperty(FMinorDistance,Value);
end;
procedure TGaugeSeries.GalleryChanged3D(Is3D: Boolean);
begin
inherited;
ParentChart.View3D:=False;
Circled:=True;
end;
class function TGaugeSeries.GetEditorClass: String;
begin
result:='TGaugeSeriesEditor';
end;
function TGaugeSeries.MaxYValue: Double;
begin
result:=FMax;
end;
function TGaugeSeries.MinYValue: Double;
begin
result:=FMin;
end;
function TGaugeSeries.Axis: TChartAxis;
begin
result:=GetVertAxis;
end;
procedure TGaugeSeries.SetLabelsInside(const Value: Boolean);
begin
SetBooleanProperty(FLabelsInside,Value);
end;
procedure TGaugeSeries.NotifyNewValue(Sender: TChartSeries;
ValueIndex: Integer);
begin
Value:=MandatoryValueList[ValueIndex];
inherited;
end;
initialization
RegisterTeeSeries(TGaugeSeries, {$IFNDEF CLR}@{$ENDIF}TeeMsg_GalleryGauge,
{$IFNDEF CLR}@{$ENDIF}TeeMsg_GalleryExtended,1);
finalization
UnRegisterTeeSeries([TGaugeSeries]);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -