📄 teeboxplot.pas
字号:
tmp:=FExtrOut;
if Assigned(tmp) then
With TPointerAccess(tmp) do
if Visible then
begin
tmpColor:=ValueColor[ValueIndex];
PrepareCanvas(ParentChart.Canvas,tmpColor);
if IVertical then Draw(CalcXPosValue(FPosition),CalcYPos(ValueIndex),tmpColor,Style)
else Draw(CalcXPos(ValueIndex),CalcYPosValue(FPosition),tmpColor,Style)
end;
end;
procedure TCustomBoxSeries.AddSampleValues(NumValues:Integer);
var t : Integer;
n : Integer;
begin
t:=ParentChart.SeriesCount+1;
n:=t*(3+System.Random(10));
Add(-n);
for t:=2 to NumValues-2 do Add(n*t/NumValues);
Add(2*n);
end;
procedure TCustomBoxSeries.PrepareForGallery(IsEnabled:Boolean);
var t : Integer;
begin
inherited;
{ by default display 2 series}
for t:=0 to ParentChart.SeriesCount-1 do
if ParentChart.Series[t] is TCustomBoxSeries then
with TCustomBoxSeries(ParentChart.Series[t]) do
begin
FPosition:=t+1;
Pointer.HorizSize:=12;
MildOut.HorizSize:=3;
ExtrOut.VertSize:=3;
FillSampleValues(10*(t+1));
end;
end;
procedure TCustomBoxSeries.DrawAllValues;
Var tmp : Integer;
tmp1 : Integer;
tmpZ : Integer;
Function CalcPos(Const Value:Double):Integer;
begin
if IVertical then result:=CalcYPosValue(Value)
else result:=CalcXPosValue(Value);
end;
Procedure DrawWhisker(AIndex,Pos:Integer);
var tmp2 : Integer;
begin
tmp2:=CalcPos(SampleValues.Value[AIndex]);
With ParentChart,Canvas do
if View3D then
begin
if IVertical then
begin
VertLine3D(tmp1,Pos,tmp2,tmpZ);
HorizLine3D(tmp1-tmp,tmp1+tmp,tmp2,tmpZ);
end
else
begin
HorizLine3D(Pos,tmp2,tmp1,tmpZ);
VertLine3D(tmp2,tmp1-tmp,tmp1+tmp,tmpZ);
end;
end
else
if IVertical then
begin
DoVertLine(tmp1,Pos,tmp2);
DoHorizLine(tmp1-tmp,tmp1+tmp,tmp2);
end
else
begin
DoHorizLine(Pos,tmp2,tmp1);
DoVertLine(tmp2,tmp1-tmp,tmp1+tmp);
end;
end;
var AL,AT,AR,AB,
tmpH,tmpV,
tmpA1,tmpA2 : Integer;
begin
inherited;
if IVertical then
begin
tmp:=Pointer.HorizSize; // 6.0
AL:=CalcXPosValue(FPosition)-tmp;
AR:=CalcXPosValue(FPosition)+tmp;
AT:=CalcYPosValue(FQuartile3);
AB:=CalcYPosValue(FQuartile1);
tmpA1:=AB;
tmpA2:=AT;
end
else
begin
tmp:=Pointer.HorizSize; // 6.0
AT:=CalcYPosValue(FPosition)-tmp;
AB:=CalcYPosValue(FPosition)+tmp;
AR:=CalcXPosValue(FQuartile3);
AL:=CalcXPosValue(FQuartile1);
tmpA1:=AL;
tmpA2:=AR;
end;
if GetHorizAxis.Inverted then SwapInteger(AL,AR);
if GetVertAxis.Inverted then SwapInteger(AT,AB);
With ParentChart,Canvas do
begin
With TPointerAccess(Pointer) do (* box *)
if Visible then
begin
PrepareCanvas;
if IVertical then
begin
tmpV:=(AB-AT) div 2;
DrawPointer(Canvas,View3D,AL+tmp-1,AT+tmpV,HorizSize-1,tmpV-1,Brush.Color,Style);
end
else
begin
tmpH:=(AR-AL) div 2;
DrawPointer(Canvas,View3D,AL+tmpH,AT+tmp-1,tmpH-1,VertSize-1,Brush.Color,Style);
end;
end;
(* median *)
if FMedianPen.Visible then
begin
AssignVisiblePen(FMedianPen);
Brush.Style:=bsClear;
tmpV:=CalcPos(FMedian);
if IVertical then
if View3D then HorizLine3D(AL,AR,tmpV,StartZ)
else DoHorizLine(AL,AR,tmpV)
else
if View3D then VertLine3D(tmpV,AT,AB,StartZ)
else DoVertLine(tmpV,AT,AB);
end;
(* whiskers *)
if FWhiskerPen.Visible then
begin
if Pointer.Visible and Pointer.Draw3D then tmpZ:=MiddleZ else tmpZ:=StartZ;
AssignVisiblePen(FWhiskerPen);
if IVertical then tmp1:=(AL+AR) div 2
else tmp1:=(AT+AB) div 2;
DrawWhisker(FAdjacentPoint1,tmpA1);
DrawWhisker(FAdjacentPoint3,tmpA2);
end;
end;
end;
procedure TCustomBoxSeries.SetParentChart(const Value: TCustomAxisPanel);
begin
inherited;
if not (csDestroying in ComponentState) then
begin
if Assigned(FExtrOut) then FExtrOut.ParentChart:=Value;
if Assigned(FMildOut) then FMildOut.ParentChart:=Value;
end;
end;
class function TCustomBoxSeries.GetEditorClass: String;
begin
result:='TBoxSeriesEditor';
end;
function TCustomBoxSeries.GetBox: TSeriesPointer;
begin
result:=Pointer;
end;
procedure TCustomBoxSeries.Assign(Source: TPersistent);
begin
if Source is TCustomBoxSeries then
With TCustomBoxSeries(Source) do
begin
Self.ExtrOut :=ExtrOut;
Self.MedianPen :=MedianPen;
Self.MildOut :=MildOut;
Self.FPosition :=Position;
Self.FWhiskerLength :=FWhiskerLength;
Self.WhiskerPen :=WhiskerPen;
Self.FUseCustomValues := FUseCustomValues;
end;
inherited;
end;
procedure TCustomBoxSeries.SetUseCustomValues(const Value: boolean);
begin
FUseCustomValues := Value;
end;
procedure TCustomBoxSeries.SetMedian(const Value: double);
begin
FMedian := Value;
end;
procedure TCustomBoxSeries.SetQuartile1(const Value: double);
begin
FQuartile1 := Value;
end;
procedure TCustomBoxSeries.SetQuartile3(const Value: double);
begin
FQuartile3 := Value;
end;
procedure TCustomBoxSeries.SetInnerFence1(const Value: double);
begin
FInnerFence1 := Value;
end;
procedure TCustomBoxSeries.SetInnerFence3(const Value: double);
begin
FInnerFence3 := Value;
end;
procedure TCustomBoxSeries.SetOuterFence1(const Value: double);
begin
FOuterFence1 := Value;
end;
procedure TCustomBoxSeries.SetOuterFence3(const Value: double);
begin
FOuterFence3 := Value;
end;
procedure TCustomBoxSeries.SetAdjacentPoint1(const Value: integer);
begin
FAdjacentPoint1 := Value;
end;
procedure TCustomBoxSeries.SetAdjacentPoint3(const Value: integer);
begin
FAdjacentPoint3 := Value;
end;
{ TBoxSeries }
function TBoxSeries.MaxXValue: Double;
begin
result:=FPosition;
end;
function TBoxSeries.MinXValue: Double;
begin
result:=FPosition;
end;
{ THorizBoxSeries}
Constructor THorizBoxSeries.Create(AOwner:TComponent);
begin
inherited;
SetHorizontal;
IVertical:=False;
end;
function THorizBoxSeries.MaxYValue: Double;
begin
result:=FPosition;
end;
function THorizBoxSeries.MinYValue: Double;
begin
result:=FPosition;
end;
initialization
RegisterTeeSeries(TBoxSeries,@TeeMsg_GalleryBoxPlot,@TeeMsg_GalleryStats,2);
RegisterTeeSeries(THorizBoxSeries,@TeeMsg_GalleryHorizBoxPlot,@TeeMsg_GalleryStats,2);
finalization
UnRegisterTeeSeries([TBoxSeries,THorizBoxSeries]);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -