teemapseries.pas

来自「Delphi TeeChartPro.6.01的源代码」· PAS 代码 · 共 684 行 · 第 1/2 页

PAS
684
字号
  ParentSeries.SetBooleanProperty(FParentBrush,Value);
end;

procedure TTeePolygon.SetParentPen(const Value: Boolean);
begin
  ParentSeries.SetBooleanProperty(FParentPen,Value);
end;

{ TTeePolygonList }
type TTeePolygonAccess=class(TChartSeries);

function TTeePolygonList.Add: TTeePolygon;
begin
  result:=inherited Add as TTeePolygon;
  TTeePolygonAccess(result.Points).SetDesigning(False);
end;

procedure TTeePolygonList.Delete(Start, Quantity: Integer);
var t: Integer;
begin
  for t:=1 to Quantity do Items[Start].Free;
end;

function TTeePolygonList.Get(Index: Integer): TTeePolygon;
begin
  result:=TTeePolygon(Items[Index]);
end;

function TTeePolygonList.Owner: TMapSeries;
begin
  result:=TMapSeries(GetOwner);
end;

procedure TTeePolygonList.Put(Index: Integer; const Value: TTeePolygon);
begin
  Items[Index]:=Value;
end;

{ TMapSeries }
Constructor TMapSeries.Create(AOwner: TComponent);
begin
  inherited;
  FShapes:=TTeePolygonList.Create(Self,TTeePolygon);
  CalcVisiblePoints:=False;
  YMandatory:=False;
  MandatoryValueList:=ZValues;
end;

Destructor TMapSeries.Destroy;
begin
  FreeAndNil(FShapes);
  inherited;
end;

procedure TMapSeries.DrawValue(ValueIndex: Integer);
begin
  if Shapes.Count>ValueIndex then
     Shapes[ValueIndex].Draw(ParentChart.Canvas);
end;

Procedure TMapSeries.Delete(ValueIndex:Integer);
begin
  inherited;
  if Assigned(FShapes) then Shapes[ValueIndex].Free;
end;

Procedure TMapSeries.Delete(Start,Quantity:Integer);
begin
  inherited;
  if Assigned(FShapes) then FShapes.Delete(Start,Quantity);
end;

function TMapSeries.MaxXValue: Double;
var t : Integer;
begin
  if Shapes.Count=0 then result:=0
  else
  begin
    result:=Shapes[0].FPoints.MaxXValue;
    for t:=1 to Shapes.Count-1 do
      result:=Math.Max(result,Shapes[t].FPoints.MaxXValue);
  end;
end;

function TMapSeries.MaxYValue: Double;
var t : Integer;
begin
  if Shapes.Count=0 then result:=0
  else
  begin
    result:=Shapes[0].FPoints.MaxYValue;
    for t:=1 to Shapes.Count-1 do
      result:=Math.Max(result,Shapes[t].FPoints.MaxYValue);
  end;
end;

function TMapSeries.MinXValue: Double;
var t : Integer;
begin
  if Shapes.Count=0 then result:=0
  else
  begin
    result:=Shapes[0].FPoints.MinXValue;
    for t:=1 to Shapes.Count-1 do
      result:=Math.Min(result,Shapes[t].FPoints.MinXValue);
  end;
end;

function TMapSeries.MinYValue: Double;
var t : Integer;
begin
  if Shapes.Count=0 then result:=0
  else
  begin
    result:=Shapes[0].FPoints.MinYValue;
    for t:=1 to Shapes.Count-1 do
      result:=Math.Min(result,Shapes[t].FPoints.MinYValue);
  end;
end;

procedure TMapSeries.PrepareForGallery(IsEnabled:Boolean);
var t : Integer;
begin
  inherited;
  if not IsEnabled then
     for t:=0 to Count-1 do Shapes[t].Color:=clSilver;
end;

procedure TMapSeries.SwapValueIndex(a,b:Integer);
begin
  inherited;
  Shapes[a].Index:=b;
  Repaint;
end;

procedure TMapSeries.SetShapes(const Value: TTeePolygonList);
begin
  FShapes.Assign(Value);
end;

procedure TMapSeries.CalcHorizMargins(var LeftMargin,
  RightMargin: Integer);
begin
  inherited;
  if Pen.Visible then
  begin
    Inc(LeftMargin,Pen.Width);
    Inc(RightMargin,Pen.Width);
  end;
end;

procedure TMapSeries.CalcVerticalMargins(var TopMargin,
  BottomMargin: Integer);
begin
  inherited;
  Inc(BottomMargin);
  if Pen.Visible then
  begin
    Inc(TopMargin,Pen.Width);
    Inc(BottomMargin,Pen.Width);
  end;
end;

procedure TMapSeries.AddSampleValues(NumValues: Integer);

  Procedure AddShape(Const X,Y:Array of Integer; AColor:TColor; Const AText:String);
  var t : Integer;
  begin
    With Shapes.Add do
    begin
      for t:=Low(X) to High(X) do AddXY(X[t],Y[t]);
      Color:=AColor;
      Text:=AText;
      Z:=Random(1000)/1000.0;
    end;
  end;

Const AX:Array[0..13] of Integer=(1,3,4,4,5,5,6,6,4,3,2,1,2,2);
      AY:Array[0..13] of Integer=(7,5,5,7,8,9,10,11,11,12,12,11,10,8);
      BX:Array[0..8]  of Integer=(5,7,8,8,7,6,5,4,4);
      BY:Array[0..8]  of Integer=(4,4,5,6,7,7,8,7,5);
      CX:Array[0..15] of Integer=(9,10,11,11,12,9,8,7,6,6,5,5,6,7,8,8);
      CY:Array[0..15] of Integer=(5,6,6,7,8,11,11,12,11,10,9,8,7,7,6,5);
      DX:Array[0..7]  of Integer=(12,14,15,14,13,12,11,11);
      DY:Array[0..7]  of Integer=(5,5,6,7,7,8,7,6);
      EX:Array[0..10] of Integer=(4,6,7,7,6,6,5,4,3,3,2);
      EY:Array[0..10] of Integer=(11,11,12,13,14,15,16,16,15,14,13);
      FX:Array[0..11] of Integer=(7,8,9,11,10,8,7,6,5,5,6,6);
      FY:Array[0..11] of Integer=(13,14,14,16,17,17,18,18,17,16,15,14);
      GX:Array[0..11] of Integer=(10,12,12,14,13,11,9,8,7,7,8,9);
      GY:Array[0..11] of Integer=(10,12,13,15,16,16,14,14,13,12,11,11);
      HX:Array[0..9]  of Integer=(17,19,18,18,17,15,14,13,15,16);
      HY:Array[0..9]  of Integer=(11,13,14,16,17,15,15,14,12,12);
      IX:Array[0..14] of Integer=(15,16,17,16,15,14,14,13,12,11,10,11,12,13,14);
      IY:Array[0..14] of Integer=(6,6,7,8,8,9,10,11,12,11,10,9,8,7,7);
      JX:Array[0..11] of Integer=(15,16,16,17,17,16,15,13,12,12,14,14);
      JY:Array[0..11] of Integer=(8,8,9,10,11,12,12,14,13,12,10,9);
      KX:Array[0..9]  of Integer=(17,19,20,20,19,17,16,16,17,16);
      KY:Array[0..9]  of Integer=(5,5,6,8,8,10,9,8,7,6);
      LX:Array[0..6]  of Integer=(19,20,21,21,19,17,17);
      LY:Array[0..6]  of Integer=(8,8,9,11,13,11,10);
begin
  AddShape(AX,AY,clLime,'A');
  AddShape(BX,BY,clRed,'B');
  AddShape(CX,CY,clFuchsia,'C');
  AddShape(DX,DY,clAqua,'D');
  AddShape(EX,EY,clSilver,'E');
  AddShape(FX,FY,clAqua,'F');
  AddShape(GX,GY,clGreen,'G');
  AddShape(HX,HY,clTeal,'H');
  AddShape(IX,IY,clWhite,'I');
  AddShape(JX,JY,clRed,'J');
  AddShape(KX,KY,clBlue,'K');
  AddShape(LX,LY,clYellow,'L');
end;

function TMapSeries.Clicked(x, y: Integer): Integer;
var P    : TPointArray;
    t    : Integer;
    tmpX : Integer;
    tmpY : Integer;
begin
  result:=TeeNoPointClicked;
  for t:=0 to Shapes.Count-1 do
  begin
    tmpX:=X;
    tmpY:=Y;
    if Assigned(ParentChart) then
    With ParentChart do
       Canvas.Calculate2DPosition(tmpX,tmpY,CalcZPos(t));
    P:=Shapes[t].GetPoints;
    try
      if PointInPolygon(TeePoint(tmpX,tmpY),P) then
         result:=t;
    finally
      SetLength(P,0);
    end;
    if result<>TeeNoPointClicked then Break;
  end;
end;

procedure TMapSeries.DrawMark(ValueIndex: Integer; const St: String;
  APosition: TSeriesMarkPosition);
Var P : TPointArray;
begin
  if Shapes.Count>ValueIndex then
  begin
    P:=Shapes[ValueIndex].GetPoints;
    try
      with Shapes[ValueIndex].GetBounds(P) do
      begin
        APosition.LeftTop.X:=((Right+Left) div 2)-(APosition.Width div 2);
        APosition.LeftTop.Y:=((Top+Bottom) div 2)-(APosition.Height div 2);
      end;
    finally
      SetLength(P,0);
    end;
  end;
  inherited;
end;

class function TMapSeries.GetEditorClass: String;
begin
  result:='TMapSeriesEditor';
end;

procedure TMapSeries.Clear;
begin
  inherited;
  if Assigned(Shapes) then Shapes.Clear;
end;

class procedure TMapSeries.CreateSubGallery(
  AddSubChart: TChartSubGalleryProc);
begin
  inherited;
  AddSubChart(TeeMsg_Colors);
end;

class procedure TMapSeries.SetSubGallery(ASeries: TChartSeries;
  Index: Integer);
begin
  with TMapSeries(ASeries) do
  Case Index of
    2: ColorEachPoint:=True;
  else inherited;
  end
end;

procedure TMapSeries.GalleryChanged3D(Is3D: Boolean);
begin { 5.02 }
  if Is3D then inherited
          else ParentChart.View3D:=False;
end;

{ TPolygonSeries }
procedure TPolygonSeries.NotifyValue(ValueEvent: TValueEvent;
  ValueIndex: Integer);
begin
  inherited;
  TChartSeries(Owner).Repaint;
end;

procedure TPolygonSeries.SetActive(Value: Boolean);
begin
  inherited;
  TChartSeries(Owner).Repaint;
end;

procedure TPolygonSeries.SetSeriesColor(AColor: TColor);
begin
  inherited;
  TChartSeries(Owner).ValueColor[TTeePolygon(Tag).Index]:=AColor;
end;

procedure TPolygonSeries.PrepareLegendCanvas(ValueIndex:Integer; Var BackColor:TColor;
                                   Var BrushStyle:TBrushStyle);
begin
  inherited;
  with TTeePolygon(Tag) do { 5.02 }
  if not Gradient.Visible then ParentChart.Canvas.Brush.Color:=Color;
end;

procedure TPolygonSeries.DrawLegendShape(ValueIndex: Integer;
  const Rect: TRect);
begin
  with TTeePolygon(Tag).Gradient do { 5.02 }
  if Visible then Draw(ParentChart.Canvas,Rect)
             else inherited;
end;

procedure TPolygonSeries.FillSampleValues(NumValues: Integer);
begin { do nothing, sample values are provided by Owner Series }
end;

initialization
  RegisterTeeSeries( TMapSeries, @TeeMsg_GalleryMap,
                     @TeeMsg_GalleryExtended,1);
finalization
  UnRegisterTeeSeries([TMapSeries]);
end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?