📄 series.pas
字号:
begin
Canvas.AssignVisiblePen(Legend.Symbol.Pen); { use custom legend pen }
DrawPen:=Legend.Symbol.Pen.Visible;
end;
With Rect do
begin
if DrawPen then
begin
tmpHoriz:=(Right-Left) div 3;
tmpVert :=(Bottom-Top) div 3;
end
else
begin
tmpHoriz:=1+((Right-Left) div 2);
tmpVert :=1+((Bottom-Top) div 2);
end;
Pointer.DrawPointer(Pointer.ParentChart.Canvas,
False, (Left+Right) div 2,(Top+Bottom) div 2,
Math.Min(Pointer.HorizSize,tmpHoriz),
Math.Min(Pointer.VertSize,tmpVert),AColor,AStyle);
end;
end;
end;
{ TCustomLineSeries }
Procedure TCustomLineSeries.Assign(Source:TPersistent);
begin
if Source is TCustomLineSeries then
FTreatNulls:=TCustomLineSeries(Source).FTreatNulls;
inherited;
end;
Function TCustomLineSeries.GetLinePen:TChartPen;
Begin
result:=Pen;
end;
procedure TCustomLineSeries.SetTreatNulls(const Value:TTreatNullsStyle);
begin
if FTreatNulls<>Value then
begin
FTreatNulls:=Value;
Repaint;
end;
end;
{ TCustomSeries }
Constructor TCustomSeries.Create(AOwner: TComponent);
Begin
inherited;
FClickableLine:=True;
FColorEachLine:=True;
DrawBetweenPoints:=True;
FPointer:=TSeriesPointer.Create(Self);
FAreaLinesPen:=CreateChartPen;
FOutLine:=TChartHiddenPen.Create(CanvasChanged);
FShadow:=TTeeShadow.Create(CanvasChanged);
FAreaBrush:=TChartBrush.Create(CanvasChanged);
FAreaColor:=clTeeColor;
FDark3D:=True;
FGradient:=TChartGradient.Create(CanvasChanged);
end;
Destructor TCustomSeries.Destroy;
Begin
FGradient.Free;
FAreaBrush.Free;
FAreaLinesPen.Free;
FShadow.Free;
FOutLine.Free;
FreeAndNil(FPointer);
inherited;
end;
Procedure TCustomSeries.DrawMark( ValueIndex:Integer; Const St:String;
APosition:TSeriesMarkPosition);
begin
Marks.ZPosition:=StartZ;
if YMandatory then Marks.ApplyArrowLength(APosition);
inherited;
end;
function TCustomSeries.DoGetPointerStyle(ValueIndex:Integer):TSeriesPointerStyle;
begin
if Assigned(FOnGetPointerStyle) then
result:=FOnGetPointerStyle(Self,ValueIndex)
else
result:=Pointer.Style;
end;
Function TCustomSeries.ClickedPointer( ValueIndex,tmpX,tmpY:Integer;
x,y:Integer):Boolean;
begin
PreparePointer(ValueIndex); // 7.0
result:=(DoGetPointerStyle(ValueIndex)<>psNothing) and
(Abs(tmpX-X)<FPointer.HorizSize) and
(Abs(tmpY-Y)<FPointer.VertSize);
end;
Procedure TCustomSeries.Assign(Source:TPersistent);
begin
if Source is TCustomSeries then
With TCustomSeries(Source) do
begin
Self.ClickableLine :=ClickableLine;
Self.AreaChartBrush :=FAreaBrush;
Self.FAreaColor :=FAreaColor;
Self.AreaLinesPen :=AreaLinesPen;
Self.FColorEachLine :=ColorEachLine;
Self.FDark3D :=FDark3D;
Self.FDrawArea :=FDrawArea;
Self.FDrawLine :=FDrawLine;
Self.FInvertedStairs :=FInvertedStairs;
Self.FLineHeight :=FLineHeight;
Self.Pointer :=FPointer;
Self.FStacked :=FStacked;
Self.FStairs :=FStairs;
Self.OutLine :=OutLine;
Self.Shadow :=Shadow;
Self.FTransparency :=FTransparency;
Self.Gradient :=FGradient;
end;
inherited;
end;
Function TCustomSeries.Clicked(x,y:Integer):Integer;
var OldXPos : Integer;
OldYPos : Integer;
tmpX : Integer;
tmpY : Integer;
P : TPoint;
Function CheckPointInLine:Boolean;
Function PointInVertLine(x0,y0,y1:Integer):Boolean;
begin
result:=PointInLine(P,x0,y0,x0,y1);
end;
Function PointInHorizLine(x0,y0,x1:Integer):Boolean;
begin
result:=PointInLine(P,x0,y0,x1,y0);
end;
begin
With ParentChart do
if View3D then
result:=PointInPolygon( P,[ TeePoint(tmpX,tmpY),
TeePoint(tmpX+SeriesWidth3D,tmpY-SeriesHeight3D),
TeePoint(OldXPos+SeriesWidth3D,OldYPos-SeriesHeight3D),
TeePoint(OldXPos,OldYPos) ])
else
if FStairs then
begin
if FInvertedStairs then result:= PointInVertLine(OldXPos,OldYPos,tmpY) or
PointInHorizLine(OldXPos,tmpY,tmpX)
else result:= PointInHorizLine(OldXPos,OldYPos,tmpX) or
PointInVertLine(tmpX,OldYPos,tmpY);
end
else
result:=PointInLine(P,tmpX,tmpY,OldXPos,OldYPos)
end;
function PointInArea(Index:Integer):Boolean; // TV52011421
var tmp : TFourPoints;
begin
if YMandatory then
begin
tmp[0].X:=OldXPos;
tmp[1].X:=tmpX;
tmp[2]:=TeePoint(tmpX,GetOriginPos(Index));
tmp[3]:=TeePoint(OldXPos,GetOriginPos(Index-1));
if FStairs then
if FInvertedStairs then
begin
tmp[0].Y:=tmpY;
tmp[1].Y:=tmpY;
end
else
begin
tmp[0].Y:=OldYPos;
tmp[1].Y:=OldYPos;
end
else
begin
tmp[0].Y:=OldYPos;
tmp[1].Y:=tmpY;
end;
end
else
begin
tmp[0].Y:=OldYPos;
tmp[1].Y:=tmpY;
tmp[2]:=TeePoint(GetOriginPos(Index),tmpY);
tmp[3]:=TeePoint(GetOriginPos(Index-1),OldYPos);
if FStairs then
if FInvertedStairs then
begin
tmp[0].X:=tmpX;
tmp[1].X:=tmpX;
end
else
begin
tmp[0].X:=OldXPos;
tmp[1].X:=OldXPos;
end
else
begin
tmp[0].X:=OldXPos;
tmp[1].X:=tmpX;
end;
end;
result:=PointInPolygon(P,tmp);
end;
var t : Integer;
tmpFirst : Integer;
begin
if Assigned(ParentChart) then
ParentChart.Canvas.Calculate2DPosition(X,Y,StartZ);
result:=inherited Clicked(x,y);
if (result=TeeNoPointClicked) and
(FirstValueIndex>-1) and (LastValueIndex>-1) then
begin
OldXPos:=0;
OldYPos:=0;
OldBottomPos:=0;
P.X:=X;
P.Y:=Y;
// Consider hidden previous segment (including non-visible leftmost part)
// TV52010286 7.05
if ClickableLine then
tmpFirst:=Max(0,Pred(FirstValueIndex))
else
tmpFirst:=FirstValueIndex;
for t:=tmpFirst to LastValueIndex do
begin
if t>=Count then exit; // prevent re-entrancy if series is cleared.
tmpX:=CalcXPos(t);
tmpY:=CalcYPos(t);
if FPointer.Visible and ClickedPointer(t,tmpX,tmpY,x,y) then
begin
if Assigned(FOnClickPointer) then
FOnClickPointer(Self,t,x,y);
result:=t;
break;
end;
if (tmpX=X) and (tmpY=Y) then
begin
result:=t;
break;
end;
if (t>tmpFirst) and ClickableLine then
if CheckPointInLine or (FDrawArea and PointInArea(t)) then
begin
result:=t-1;
break;
end;
OldXPos:=tmpX;
OldYPos:=tmpY;
OldBottomPos:=BottomPos;
end;
end;
end;
Procedure TCustomSeries.SetDrawArea(Value:Boolean);
Begin
SetBooleanProperty(FDrawArea,Value);
end;
Procedure TCustomSeries.SetPointer(Value:TSeriesPointer);
Begin
FPointer.Assign(Value);
end;
Procedure TCustomSeries.SetShadow(Value:TTeeShadow);
begin
FShadow.Assign(Value);
end;
Procedure TCustomSeries.SetAreaLinesPen(Value:TChartPen);
Begin
FAreaLinesPen.Assign(Value);
end;
Procedure TCustomSeries.SetLineHeight(Value:Integer);
Begin
SetIntegerProperty(FLineHeight,Value);
end;
Procedure TCustomSeries.SetStairs(Value:Boolean);
Begin
SetBooleanProperty(FStairs,Value);
end;
{$IFDEF TEEOCX}
Procedure TCustomSeries.SetFastPoint(Value:Boolean);
Begin
SetBooleanProperty(FFastPoint,Value);
end;
{$ENDIF}
Procedure TCustomSeries.SetInvertedStairs(Value:Boolean);
Begin
SetBooleanProperty(FInvertedStairs,Value);
end;
Procedure TCustomSeries.SetAreaColor(Value:TColor);
Begin
SetColorProperty(FAreaColor,Value);
end;
Procedure TCustomSeries.SetAreaBrushStyle(Value:TBrushStyle);
Begin
FAreaBrush.Style:=Value;
end;
Function TCustomSeries.GetLineBrush:TBrushStyle;
Begin
result:=Brush.Style;
end;
Procedure TCustomSeries.SetLineBrush(Value:TBrushStyle);
Begin
Brush.Style:=Value;
end;
Procedure TCustomSeries.DrawLegendShape(ValueIndex:Integer; Const Rect:TRect);
var tmpColor : TColor;
Procedure DrawLine(DrawRectangle:Boolean);
begin
if TCustomChart(ParentChart).Legend.Symbol.DefaultPen then
LinePrepareCanvas(ParentChart.Canvas,tmpColor);
With ParentChart.Canvas do
if DrawRectangle then
Rectangle(Rect)
else
With Rect do
DoHorizLine(Left,Right,(Top+Bottom) div 2);
end;
var tmp : TSeriesPointerStyle;
begin
if ValueIndex=TeeAllValues then tmpColor:=SeriesColor
else tmpColor:=LegendItemColor(ValueIndex);
if FPointer.Visible then
begin
if FDrawLine then DrawLine(False);
if Assigned(FOnGetPointerStyle) and (ValueIndex<>TeeAllValues) then
begin
tmp:=FOnGetPointerStyle(Self,ValueIndex);
{$IFNDEF TEEOCX}
tmpColor:=Pointer.Color;
{$ENDIF}
end
else
tmp:=Pointer.Style;
TeePointerDrawLegend(Pointer,tmpColor,Rect,LinePen.Visible,tmp);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -