📄 qiplotaxis.pas
字号:
procedure TiPlotAxis.SetCursorPrecisionStyle(const Value: TiPrecisionStyle);
begin
if FCursorPrecisionStyle <> Value then
begin
FCursorPrecisionStyle := Value;
TriggerChange(Self);
end;
end;
//****************************************************************************************************************************************************
procedure TiPlotAxis.SetLegendPrecisionStyle(const Value: TiPrecisionStyle);
begin
if FLegendPrecisionStyle <> Value then
begin
FLegendPrecisionStyle := Value;
TriggerChange(Self);
end;
end;
//****************************************************************************************************************************************************
procedure TiPlotAxis.SetScaleType(const Value: TiPlotScaleType);
begin
if FScaleType <> Value then
begin
FScaleType := Value;
if FScaleType = ipstLog10 then if FMin <= 0 then FMin := 1;
TriggerChange(Self);
end;
end;
//****************************************************************************************************************************************************
procedure TiPlotAxis.SetTrackingAlignFirstStyle(const Value: TiPlotAlignFirstStyle);
begin
if FTrackingAlignFirstStyle <> Value then
begin
FTrackingAlignFirstStyle := Value;
TriggerChange(Self);
end;
end;
//****************************************************************************************************************************************************
procedure TiPlotAxis.SetTrackingStyle(const Value: TiPlotTrackingStyle);
begin
if FTrackingStyle <> Value then
begin
FTrackingStyle := Value;
TriggerChange(Self);
end;
end;
//****************************************************************************************************************************************************
procedure TiPlotAxis.SetLabelsPrecisionStyle(const Value: TiPrecisionStyle);
begin
if FLabelsPrecisionStyle <> Value then
begin
FLabelsPrecisionStyle := Value;
TriggerChange(Self);
end;
end;
//****************************************************************************************************************************************************
procedure TiPlotAxis.SetMode(const Value: TiPlotAxisMode);
begin
if FMode <> Value then
begin
FMode := Value;
TriggerChange(Self);
end;
end;
//****************************************************************************************************************************************************
function TiPlotAxis.GetSpanLength: Integer;
begin
with FScaleRect do
begin
if Horizontal then Result := Right - Left else Result := Bottom - Top;
end;
end;
//****************************************************************************************************************************************************
procedure TiPlotAxis.ClearTickList;
begin
while FTickList.Count <> 0 do
begin
FTickList.Objects[0].Free;
FTickList.Delete(0);
end;
end;
//****************************************************************************************************************************************************
function TiPlotAxis.GetTickObject(Index: Integer): TiPlotTickObject;
begin
Result := (FTickList.Objects[Index] as TiPlotTickObject);
end;
//****************************************************************************************************************************************************
procedure TiPlotAxis.TickListClear;
begin
ClearTickList;
TriggerChange(Self);
end;
//****************************************************************************************************************************************************
function TiPlotAxis.GetTickListCount: Integer;
begin
Result := FTickList.Count;
end;
//****************************************************************************************************************************************************
function TiPlotAxis.GetTickListItemLabel (Index:Integer):String; begin Result:=TickObject[Index].Text; end;
function TiPlotAxis.GetTickListItemPosition(Index:Integer):Double; begin Result:=TickObject[Index].Position;end;
function TiPlotAxis.GetTickListItemStyle (Index:Integer):TiPlotTickType;begin Result:=TickObject[Index].TickType;end;
//****************************************************************************************************************************************************
procedure TiPlotAxis.SetTickListItemLabel (Index:Integer;const Value:String); begin TickObject[Index].Text := Value;TriggerChange(Self);end;
procedure TiPlotAxis.SetTickListItemPosition(Index:Integer;const Value:Double); begin TickObject[Index].Position:= Value;TriggerChange(Self);end;
procedure TiPlotAxis.SetTickListItemStyle (Index:Integer;const Value:TiPlotTickType);begin TickObject[Index].TickType:= Value;TriggerChange(Self);end;
//****************************************************************************************************************************************************
function TiPlotAxis.TickListAdd(Position: Double; ALabel: String; Style: TiPlotTickType): Integer;
var
TickObject : TiPlotTickObject;
begin
if (FScaleType = ipstLog10) and (Position <= 0) then raise Exception.Create('Log Scale Requires Position to be Greater Than Zero');
TickObject := TiPlotTickObject.Create;
TickObject.TickType := Style;
TickObject.Position := Position;
TickObject.Text := ALabel;
Result := FTickList.AddObject('', TickObject);
TriggerChange(Self);
end;
//****************************************************************************************************************************************************
procedure TiPlotAxis.AddTick(Value : Double; Style : TiPlotTickType);
var
TickObject : TiPlotTickObject;
begin
if not PointOnScale(Value) then Exit;
if (FScaleType = ipstLog10) and (Value <= 0) then Exit;
TickObject := TiPlotTickObject.Create;
TickObject.TickType := Style;
TickObject.Position := Value;
if Style = ipttMajor then
TickObject.Text := GetLabelText(Value);
FTickList.AddObject('', TickObject);
end;
//****************************************************************************************************************************************************
procedure TiPlotAxis.ZoomRect(ARect: TRect);
var
NewMin : Double;
NewMax : Double;
begin
if Horizontal then
begin
if FReverseScale then
begin
NewMin := PixelsToPosition(ARect.Right);
NewMax := PixelsToPosition(ARect.Left);
end
else
begin
NewMin := PixelsToPosition(ARect.Left);
NewMax := PixelsToPosition(ARect.Right);
end;
end
else
begin
if FReverseScale then
begin
NewMin := PixelsToPosition(ARect.Top);
NewMax := PixelsToPosition(ARect.Bottom);
end
else
begin
NewMin := PixelsToPosition(ARect.Bottom);
NewMax := PixelsToPosition(ARect.Top);
end;
end;
SetMinSpan(NewMin, NewMax-NewMin);
end;
//****************************************************************************************************************************************************
function TiPlotAxis.PixelsToPosition(const Value: Integer): Double;
var
Decades : Double;
begin
Result := FMin;
case FScaleType of
ipstLinear : if Horizontal then
begin
if (FScaleRect.Right = FScaleRect.Left) then Exit;
if FReverseScale then Result := (FScaleRect.Right - Value) /(FScaleRect.Right - FScaleRect.Left)*FSpan + FMin
else Result := (Value - FScaleRect.Left ) /(FScaleRect.Right - FScaleRect.Left)*FSpan + FMin;
end
else
begin
if (FScaleRect.Bottom = FScaleRect.Top) then Exit;
if FReverseScale then Result := (Value - FScaleRect.Top )/(FScaleRect.Bottom - FScaleRect.Top)*FSpan + FMin
else Result := (FScaleRect.Bottom - Value)/(FScaleRect.Bottom - FScaleRect.Top)*FSpan + FMin;
end;
ipstLog10 : begin
Decades := Log10(Max)-Log10(Min);
if Horizontal then
begin
if (FScaleRect.Right = FScaleRect.Left) then Exit;
if FReverseScale then Result := Power(10, (FScaleRect.Right - Value)/(FScaleRect.Right - FScaleRect.Left)*Decades + Log10(FMin))
else Result := Power(10, (Value - FScaleRect.Left )/(FScaleRect.Right - FScaleRect.Left)*Decades + Log10(FMin));
end
else
begin
if (FScaleRect.Bottom = FScaleRect.Top) then Exit;
if FReverseScale then Result := Power(10, (Value - FScaleRect.Top )/(FScaleRect.Bottom - FScaleRect.Top)*Decades + Log10(FMin))
else Result := Power(10, (FScaleRect.Bottom - Value)/(FScaleRect.Bottom - FScaleRect.Top)*Decades + Log10(FMin));
end;
end;
end;
end;
//****************************************************************************************************************************************************
function TiPlotAxis.PixelsToPositionDouble(Value: Double): Double;
var
Decades : Double;
begin
Result := FMin;
case FScaleType of
ipstLinear : if Horizontal then
begin
if (FScaleRect.Right = FScaleRect.Left) then Exit;
if FReverseScale then Result := (FScaleRect.Right - Value) /(FScaleRect.Right - FScaleRect.Left)*FSpan + FMin
else Result := (Value - FScaleRect.Left ) /(FScaleRect.Right - FScaleRect.Left)*FSpan + FMin;
end
else
begin
if (FScaleRect.Bottom = FScaleRect.Top) then Exit;
if FReverseScale then Result := (Value - FScaleRect.Top )/(FScaleRect.Bottom - FScaleRect.Top)*FSpan + FMin
else Result := (FScaleRect.Bottom - Value)/(FScaleRect.Bottom - FScaleRect.Top)*FSpan + FMin;
end;
ipstLog10 : begin
Decades := Log10(Max)-Log10(Min);
if Horizontal then
begin
if (FScaleRect.Right = FScaleRect.Left) then Exit;
if FReverseScale then Result := Power(10, (FScaleRect.Right - Value)/(FScaleRect.Right - FScaleRect.Left)*Decades + Log10(FMin))
else Result := Power(10, (Value - FScaleRect.Left )/(FScaleRect.Right - FScaleRect.Left)*Decades + Log10(FMin));
end
else
begin
if (FScaleRect.Bottom = FScaleRect.Top) then Exit;
if FReverseScale then Result := Power(10, (Value - FScaleRect.Top )/(FScaleRect.Bottom - FScaleRect.Top)*Decades + Log10(FMin))
else Result := Power(10, (FScaleRect.Bottom - Value)/(FScaleRect.Bottom -
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -