📄 iplotchannel.pas
字号:
Canvas.Pen.Color := Canvas.Brush.Color;
DrawLine(Canvas, XYAxisReverse, X2, FFillReference, X2, Y2, ipurScale);
Canvas.Pen.Color := Color;
end;
DrawLine(Canvas, XYAxisReverse, X1, Y1, X2, Y2, ipurScale);
AddPixelListValue(XAxis.PositionToPixels(X2), Y2);
X1 := X2;
Y1 := Y2;
end;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannel.DrawCubicSpline(Canvas: TCanvas; XYAxisReverse: Boolean);
var
i : Integer;
XArray : DoubleDynamicArray;
YArray : DoubleDynamicArray;
Y2Array : DoubleDynamicArray;
Size : Integer;
begin
if Count < 2 then Exit;
SetLength(XArray, Count+1);
SetLength(YArray, Count+1);
SetLength(Y2Array, Count+1);
Size := 0;
for i := 0 to Count-1 do
begin
if DataEmpty[i] then Continue;
if not DataNull[i] then
begin
Size := Size + 1;
XArray[Size] := DataX[i];
YArray[Size] := DataY[i];
end
else
begin
DrawCubicSplineSet(Canvas, XYAxisReverse, XArray, YArray, Y2Array, Size);
Size := 0;
end;
end;
if Size > 0 then DrawCubicSplineSet(Canvas, XYAxisReverse, XArray, YArray, Y2Array, Size);
XArray := nil;
YArray := nil;
Y2Array := nil;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannel.DrawPolynomial(Canvas: TCanvas; XYAxisReverse: Boolean);
var
i : Integer;
XArray : DoubleDynamicArray;
YArray : DoubleDynamicArray;
Y2Array : DoubleDynamicArray;
XPixelsStart : Integer;
XPixelsStop : Integer;
XStart : Double;
XStop : Double;
XValue : Double;
YValue : Double;
X1, X2 : Double;
Y1, Y2 : Double;
DY : Double;
begin
if Count < 2 then Exit;
Canvas.Brush.Style := FFillStyle;
if FillUseChannelColor then Canvas.Brush.Color := Color else Canvas.Brush.Color := FillColor;
SetLength(XArray, Count+1);
SetLength(YArray, Count+1);
SetLength(Y2Array, Count+1);
for i := 0 to Count -1 do
begin
XArray[i+1] := DataX[i];
YArray[i+1] := DataY[i];
end;
XStart := DataX[0];
XStop := DataX[Count-1];
if XStart < XAxis.Min then XStart := XAxis.Min;
if XStop > XAxis.Max then XStop := XAxis.Max;
XPixelsStart := XAxis.PositionToPixels(XStart);
XPixelsStop := XAxis.PositionToPixels(XStop);
if XPixelsStart > XPixelsStop then SwapIntegers(XPixelsStart, XPixelsStop);
XValue := XAxis.PixelsToPosition(XPixelsStart);
PolynomialInterpolation(XArray, YArray, Count, XValue, YValue, DY);
X1 := XValue;
Y1 := YValue;
if FFillEnabled and (FFillStyle <> bsClear) then
begin
Canvas.Pen.Color := Canvas.Brush.Color;
DrawLine(Canvas, XYAxisReverse, X1, FFillReference, X1, Y1, ipurScale);
Canvas.Pen.Color := Color;
AddPixelListValue(XAxis.PositionToPixels(X1), Y1);
end;
for i := XPixelsStart+1 to XPixelsStop do
begin
XValue := XAxis.PixelsToPosition(i);
PolynomialInterpolation(XArray, YArray, Count, XValue, YValue, DY);
X2 := XValue;
Y2 := YValue;
if FFillEnabled and (FFillStyle <> bsClear) then
begin
Canvas.Pen.Color := Canvas.Brush.Color;
DrawLine(Canvas, XYAxisReverse, X2, FFillReference, X2, Y2, ipurScale);
Canvas.Pen.Color := Color;
end;
DrawLine(Canvas, XYAxisReverse, X1, Y1, X2, Y2, ipurScale);
AddPixelListValue(XAxis.PositionToPixels(X2), Y2);
X1 := X2;
Y1 := Y2;
end;
XArray := nil;
YArray := nil;
Y2Array := nil;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannel.DrawRational(Canvas: TCanvas; XYAxisReverse: Boolean);
var
i : Integer;
XArray : DoubleDynamicArray;
YArray : DoubleDynamicArray;
Y2Array : DoubleDynamicArray;
XPixelsStart : Integer;
XPixelsStop : Integer;
XStart : Double;
XStop : Double;
XValue : Double;
YValue : Double;
X1, X2 : Double;
Y1, Y2 : Double;
DY : Double;
begin
if Count < 2 then Exit;
Canvas.Brush.Style := FFillStyle;
if FillUseChannelColor then Canvas.Brush.Color := Color else Canvas.Brush.Color := FillColor;
SetLength(XArray, Count+1);
SetLength(YArray, Count+1);
SetLength(Y2Array, Count+1);
for i := 0 to Count -1 do
begin
XArray[i+1] := DataX[i];
YArray[i+1] := DataY[i];
end;
XStart := DataX[0];
XStop := DataX[Count-1];
if XStart < XAxis.Min then XStart := XAxis.Min;
if XStop > XAxis.Max then XStop := XAxis.Max;
XPixelsStart := XAxis.PositionToPixels(XStart);
XPixelsStop := XAxis.PositionToPixels(XStop);
if XPixelsStart > XPixelsStop then SwapIntegers(XPixelsStart, XPixelsStop);
XValue := XAxis.PixelsToPosition(XPixelsStart);
RationalInterpolation(XArray, YArray, Count, XValue, YValue, DY);
X1 := XValue;
Y1 := YValue;
if FFillEnabled and (FFillStyle <> bsClear) then
begin
Canvas.Pen.Color := Canvas.Brush.Color;
DrawLine(Canvas, XYAxisReverse, X1, FFillReference, X1, Y1, ipurScale);
Canvas.Pen.Color := Color;
AddPixelListValue(XAxis.PositionToPixels(X1), Y1);
end;
for i := XPixelsStart+1 to XPixelsStop do
begin
XValue := XAxis.PixelsToPosition(i);
RationalInterpolation(XArray, YArray, Count, XValue, YValue, DY);
X2 := XValue;
Y2 := YValue;
if FFillEnabled and (FFillStyle <> bsClear) then
begin
Canvas.Pen.Color := Canvas.Brush.Color;
DrawLine(Canvas, XYAxisReverse, X2, FFillReference, X2, Y2, ipurScale);
Canvas.Pen.Color := Color;
end;
DrawLine(Canvas, XYAxisReverse, X1, Y1, X2, Y2, ipurScale);
AddPixelListValue(XAxis.PositionToPixels(X2), Y2);
X1 := X2;
Y1 := Y2;
end;
XArray := nil;
YArray := nil;
Y2Array := nil;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannel.CalcStartXIndex;
begin
StartIndex := -1;
if not Assigned(XAxis) then exit;
if DataList.Count = 0 then exit;
if FXIncreasing then
begin
StartIndex := CalcXIndexIncreasing(XAxis.Min);
if DataList.X[StartIndex] > XAxis.Min then StartIndex := StartIndex - 1;
end
else
begin
StartIndex := CalcXIndexDecreasing(XAxis.Max);
if DataList.X[StartIndex] < XAxis.Max then StartIndex := StartIndex - 1;
end;
if StartIndex < 0 then StartIndex := 0;
if StartIndex > (DataList.Count-1) then StartIndex := DataList.Count-1;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannel.CalcStopXIndex;
begin
StopIndex := -1;
if not Assigned(XAxis) then exit;
if DataList.Count = 0 then exit;
if FXIncreasing then
begin
StopIndex := CalcXIndexIncreasing(XAxis.Max);
if DataList.X[StopIndex] < XAxis.Max then StopIndex := StopIndex + 1;
end
else
begin
StopIndex := CalcXIndexDecreasing(XAxis.Min);
if DataList.X[StopIndex] > XAxis.Min then StopIndex := StopIndex + 1;
end;
if StopIndex < 0 then StopIndex := 0;
if StopIndex > (DataList.Count-1) then StopIndex := DataList.Count-1;
end;
//****************************************************************************************************************************************************
function TiPlotChannel.CalcXIndexIncreasing(TargetValue: Double): Integer;
var
MinIndex : Integer;
MaxIndex : Integer;
MiddleIndex : Integer;
MiddleValue : Double;
begin
Result := -1;
MinIndex := 0;
MaxIndex := DataList.Count - 1;
while MinIndex <= MaxIndex do
begin
MiddleIndex := (MinIndex + MaxIndex) div 2;
MiddleValue := DataList.X[MiddleIndex];
Result := MiddleIndex;
if MiddleValue = TargetValue then Break;
if MiddleValue > TargetValue then MaxIndex := MiddleIndex - 1
else MinIndex := MiddleIndex + 1;
end;
end;
//****************************************************************************************************************************************************
function TiPlotChannel.CalcXIndexDecreasing(TargetValue: Double): Integer;
var
MinIndex : Integer;
MaxIndex : Integer;
MiddleIndex : Integer;
MiddleValue : Double;
begin
Result := -1;
MinIndex := 0;
MaxIndex := DataList.Count - 1;
while MinIndex <= MaxIndex do
begin
MiddleIndex := (MinIndex + MaxIndex) div 2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -