1 { 2 3 ***************************************************************************** 4 See the file COPYING.modifiedLGPL.txt, included in this distribution, 5 for details about the license. 6 ***************************************************************************** 7 8 Authors: Alexander Klenin 9 10 } 11 12 unit TAAxisSource; 13 14 {$H+} 15 16 interface 17 18 uses 19 Classes, TACustomSource, TAChartAxis; 20 21 type 22 TCustomAxisChartSource = class(TCustomChartSource) 23 strict private 24 FAxisFrom: TChartAxis; 25 FAxisTo: TChartAxis; 26 FItem: TChartDataItem; 27 protected GetCountnull28 function GetCount: Integer; override; GetItemnull29 function GetItem(AIndex: Integer): PChartDataItem; override; 30 procedure SetXCount(AValue: Cardinal); override; 31 procedure SetYCount(AValue: Cardinal); override; 32 public 33 constructor Create(AOwner: TComponent); override; 34 public IsSortednull35 function IsSorted: Boolean; override; 36 37 property AxisFrom: TChartAxis read FAxisFrom write FAxisFrom; 38 property AxisTo: TChartAxis read FAxisTo write FAxisTo; 39 end; 40 41 implementation 42 43 uses 44 Math, 45 TAChartUtils; 46 47 { TCustomAxisChartSource } 48 49 constructor TCustomAxisChartSource.Create(AOwner: TComponent); 50 begin 51 inherited Create(AOwner); 52 FItem.Color := clTAColor; 53 FItem.XList := nil; 54 FItem.YList := nil; 55 end; 56 TCustomAxisChartSource.GetCountnull57function TCustomAxisChartSource.GetCount: Integer; 58 begin 59 if AxisFrom = nil then 60 Result := 0 61 else 62 Result := AxisFrom.ValueCount; 63 end; 64 GetItemnull65function TCustomAxisChartSource.GetItem(AIndex: Integer): PChartDataItem; 66 var 67 v: Double; 68 begin 69 Result := @FItem; 70 if AxisFrom = nil then begin 71 FItem.Text := ''; 72 FItem.X := NaN; 73 FItem.Y := NaN; 74 exit; 75 end; 76 with AxisFrom.Value[AIndex] do begin 77 FItem.Text := FText; 78 v := FValue; 79 end; 80 if AxisFrom.Transformations <> nil then 81 v := AxisFrom.Transformations.AxisToGraph(v); 82 if (AxisTo <> nil) and (AxisTo.Transformations <> nil) then 83 v := AxisTo.Transformations.GraphToAxis(v); 84 FItem.X := v; 85 FItem.Y := v; 86 end; 87 IsSortednull88function TCustomAxisChartSource.IsSorted: Boolean; 89 begin 90 Result := true; 91 end; 92 93 procedure TCustomAxisChartSource.SetXCount(AValue: Cardinal); 94 begin 95 Unused(AValue); 96 raise EXCountError.Create('Cannot set XCount'); 97 end; 98 99 procedure TCustomAxisChartSource.SetYCount(AValue: Cardinal); 100 begin 101 Unused(AValue); 102 raise EYCountError.Create('Cannot set YCount'); 103 end; 104 105 end. 106 107