1 {
2 *****************************************************************************
3 See the file COPYING.modifiedLGPL.txt, included in this distribution,
4 for details about the license.
5 *****************************************************************************
6
7 TeeChart compatibility.
8
9 Authors: Alexander Klenin
10
11 }
12 unit TAChartTeeChart;
13
14 {$H+}
15
16 interface
17
18 uses
19 Classes, SysUtils,
20 TAGraph, TAChartAxis, TAChartAxisUtils, TAChartUtils, TACustomSeries,
21 TASeries, TATransformations;
22
23 type
24 TChartTeeChart = class helper for TChart
25 strict private
26 // Workaround for issue #21809.
GetAxisByAlign1null27 function GetAxisByAlign1(AIndex: TChartAxisAlignment): TChartAxis; inline;
GetMarginnull28 function GetMargin(AIndex: Integer): Integer; inline;
29 procedure SetMargin(AIndex: Integer; AValue: TChartDistance); inline;
30 public
31 property RightAxis: TChartAxis index calRight read GetAxisByAlign1;
32 property TopAxis: TChartAxis index calTop read GetAxisByAlign1;
33 public
34 property MarginBottom: TChartDistance index 4 read GetMargin write SetMargin;
35 property MarginLeft: TChartDistance index 1 read GetMargin write SetMargin;
36 property MarginRight: TChartDistance index 3 read GetMargin write SetMargin;
37 property MarginTop: TChartDistance index 2 read GetMargin write SetMargin;
38 end;
39
40 TPointSeries = class(TLineSeries)
41 published
42 property LineType default ltNone;
43 property ShowPoints default true;
44 end;
45
46 THorizBarSeries = class(TBarSeries)
47 public
48 // Swap X and Y as TeeChart does.
AddXYnull49 function AddXY(
50 AX, AY: Double; AXLabel: String = '';
51 AColor: TChartColor = clTAColor): Integer; overload; inline;
52 constructor Create(AOwner: TComponent); override;
53 published
54 property AxisIndexX default 0;
55 property AxisIndexY default 1;
56 end;
57
58 TChartSeriesStyle = set of (
59 tssIsTemplate, tssDenyChangeType, tssDenyDelete, tssDenyClone,
60 tssIsPersistent, tssHideDataSource);
61
62 TCustomChartSeriesTeeChart = class helper for TCustomChartSeries
63 strict private
GetStylenull64 function GetStyle: TChartSeriesStyle; inline;
65 procedure SetStyle(AValue: TChartSeriesStyle); inline;
66 published
67 // Does not do anything, just avoid IFDEFs in client code.
68 property Style: TChartSeriesStyle read GetStyle write SetStyle default [];
69 end;
70
71 TChartAxisTeeChart = class helper for TChartAxis
72 strict private
GetLogarithmicnull73 function GetLogarithmic: Boolean;
74 procedure SetLogarithmic(AValue: Boolean);
75 published
76 property Logarithmic: Boolean
77 read GetLogarithmic write SetLogarithmic default false;
78 end;
79
80 implementation
81
82 uses
83 Math;
84
85 type
86 TLogTransformEnumerator = class(TAxisTransformEnumerator)
GetCurrentnull87 function GetCurrent: TLogarithmAxisTransform;
MoveNextnull88 function MoveNext: Boolean;
89 property Current: TLogarithmAxisTransform read GetCurrent;
GetEnumeratornull90 function GetEnumerator: TLogTransformEnumerator;
91 end;
92
93 var
94 VLogTransforms: array of TChartAxisTransformations;
95
AddLogTransformsnull96 function AddLogTransforms: TChartAxisTransformations;
97 begin
98 Result := TChartAxisTransformations.Create(nil);
99 TLogarithmAxisTransform.Create(nil).Transformations := Result;
100 SetLength(VLogTransforms, Length(VLogTransforms) + 1);
101 VLogTransforms[High(VLogTransforms)] := Result;
102 end;
103
104 procedure FreeLogTransforms;
105 var
106 t: TChartAxisTransformations;
107 begin
108 for t in VLogTransforms do
109 t.Free;
110 VLogTransforms := nil;
111 end;
112
113 { TLogTransformEnumerator }
114
GetCurrentnull115 function TLogTransformEnumerator.GetCurrent: TLogarithmAxisTransform;
116 begin
117 Result := inherited GetCurrent as TLogarithmAxisTransform;
118 end;
119
GetEnumeratornull120 function TLogTransformEnumerator.GetEnumerator: TLogTransformEnumerator;
121 begin
122 Result := Self;
123 end;
124
MoveNextnull125 function TLogTransformEnumerator.MoveNext: Boolean;
126 begin
127 repeat
128 Result := inherited MoveNext;
129 until Result and (inherited GetCurrent is TLogarithmAxisTransform);
130 end;
131
132 { TChartAxisTeeChart }
133
TChartAxisTeeChart.GetLogarithmicnull134 function TChartAxisTeeChart.GetLogarithmic: Boolean;
135 var
136 t: TLogarithmAxisTransform;
137 begin
138 if Transformations <> nil then
139 for t in TLogTransformEnumerator.Create(Transformations.List) do
140 if t.Enabled then
141 exit(true);
142 Result := false;
143 end;
144
145 procedure TChartAxisTeeChart.SetLogarithmic(AValue: Boolean);
146 var
147 t: TLogarithmAxisTransform;
148 begin
149 Intervals.Tolerance := IfThen(AValue, 2, 0);
150 if Transformations <> nil then
151 for t in TLogTransformEnumerator.Create(Transformations.List) do
152 t.Enabled := AValue
153 else if AValue then
154 Transformations := AddLogTransforms;
155 end;
156
157 { TCustomChartSeriesTeeChart }
158
TCustomChartSeriesTeeChart.GetStylenull159 function TCustomChartSeriesTeeChart.GetStyle: TChartSeriesStyle;
160 begin
161 Result := [];
162 end;
163
164 procedure TCustomChartSeriesTeeChart.SetStyle(AValue: TChartSeriesStyle);
165 begin
166 Unused(AValue);
167 end;
168
169 { THorizBarSeries }
170
AddXYnull171 function THorizBarSeries.AddXY(
172 AX, AY: Double; AXLabel: String; AColor: TChartColor): Integer;
173 begin
174 Result := inherited AddXY(AY, AX, AXLabel, AColor);
175 end{%H-}; // to silence the compiler warning of impossible inline of inherited method
176
177 constructor THorizBarSeries.Create(AOwner: TComponent);
178 begin
179 inherited Create(AOwner);
180 SetPropDefaults(Self, ['AxisIndexX', 'AxisIndexY']);
181 end;
182
183 { TChartTeeChart }
184
TChartTeeChart.GetAxisByAlign1null185 function TChartTeeChart.GetAxisByAlign1(AIndex: TChartAxisAlignment): TChartAxis;
186 begin
187 // Using "inherited" here results in a crash, probably due to FPC bug.
188 Result := GetAxisByAlign(AIndex);
189 end;
190
GetMarginnull191 function TChartTeeChart.GetMargin(AIndex: Integer): Integer;
192 begin
193 Result := Margins.GetValue(AIndex);
194 end;
195
196 procedure TChartTeeChart.SetMargin(AIndex: Integer; AValue: TChartDistance);
197 begin
198 Margins.SetValue(AIndex, AValue);
199 end;
200
201 procedure Dummy;
202 begin
203 // Workaround for issue #21808.
204 end;
205
206 initialization
207 Dummy;
208
209 finalization
210 FreeLogTransforms;
211
212 end.
213
214