TAChart: Add TChartMinorAxis.IntervalsCount property. Draw minor axises.

git-svn-id: trunk@31429 -
This commit is contained in:
ask 2011-06-28 10:58:17 +00:00
parent a890570935
commit 01e9be3b20

View File

@ -29,21 +29,27 @@ uses
const const
DEF_TICK_LENGTH = 4; DEF_TICK_LENGTH = 4;
DEF_INTERVALS_COUNT = 5;
type type
{ TChartMinorAxis } { TChartMinorAxis }
TChartMinorAxis = class(TChartBasicAxis) TChartMinorAxis = class(TChartBasicAxis)
strict private
FIntervalsCount: Cardinal;
procedure SetIntervalsCount(AValue: Cardinal);
protected protected
function GetDisplayName: String; override; function GetDisplayName: String; override;
procedure StyleChanged(ASender: TObject); override;
strict protected strict protected
function GetAlignment: TChartAxisAlignment; override; function GetAlignment: TChartAxisAlignment; override;
procedure SetAlignment(AValue: TChartAxisAlignment); override; procedure SetAlignment(AValue: TChartAxisAlignment); override;
procedure StyleChanged(ASender: TObject); override;
public public
constructor Create(ACollection: TCollection); override; constructor Create(ACollection: TCollection); override;
published published
property IntervalsCount: Cardinal
read FIntervalsCount write SetIntervalsCount default DEF_INTERVALS_COUNT;
property TickLength default DEF_TICK_LENGTH div 2; property TickLength default DEF_TICK_LENGTH div 2;
end; end;
@ -258,6 +264,7 @@ end;
constructor TChartMinorAxis.Create(ACollection: TCollection); constructor TChartMinorAxis.Create(ACollection: TCollection);
begin begin
inherited Create(ACollection, (ACollection as TChartMinorAxisList).GetChart); inherited Create(ACollection, (ACollection as TChartMinorAxisList).GetChart);
FIntervalsCount := DEF_INTERVALS_COUNT;
TickLength := DEF_TICK_LENGTH div 2; TickLength := DEF_TICK_LENGTH div 2;
end; end;
@ -277,6 +284,13 @@ begin
raise EChartError.Create('TChartMinorAxis.SetAlignment'); raise EChartError.Create('TChartMinorAxis.SetAlignment');
end; end;
procedure TChartMinorAxis.SetIntervalsCount(AValue: Cardinal);
begin
if FIntervalsCount = AValue then exit;
FIntervalsCount := AValue;
StyleChanged(Self);
end;
procedure TChartMinorAxis.StyleChanged(ASender: TObject); procedure TChartMinorAxis.StyleChanged(ASender: TObject);
begin begin
(Collection.Owner as TChartAxis).StyleChanged(ASender); (Collection.Owner as TChartAxis).StyleChanged(ASender);
@ -352,30 +366,58 @@ end;
procedure TChartAxis.Draw( procedure TChartAxis.Draw(
ADrawer: IChartDrawer; const AClipRect: TRect; ADrawer: IChartDrawer; const AClipRect: TRect;
const ATransf: ICoordTransformer; const AZOffset: TPoint); const ATransf: ICoordTransformer; const AZOffset: TPoint);
function MakeDrawHelper(AAxis: TChartBasicAxis): TAxisDrawHelper;
begin
if IsVertical then
Result := TAxisDrawHelperY.Create
else
Result := TAxisDrawHelperX.Create;
try
Result.FAxis := AAxis;
Result.FClipRect := AClipRect;
Result.FDrawer := ADrawer;
Result.FTransf := ATransf;
Result.FZOffset := AZOffset;
Result.BeginDrawing;
except
Result.Free;
raise;
end;
end;
var var
i, fixedCoord: Integer; i, j, c, ic, fixedCoord: Integer;
axisTransf: TTransformFunc; axisTransf: TTransformFunc;
dh: TAxisDrawHelper; dh, dhMinor: TAxisDrawHelper;
pv, v: Double;
begin begin
if not Visible then exit; if not Visible then exit;
if Marks.Visible then if Marks.Visible then
ADrawer.Font := Marks.LabelFont; ADrawer.Font := Marks.LabelFont;
fixedCoord := TChartAxisMargins(FAxisRect)[Alignment]; fixedCoord := TChartAxisMargins(FAxisRect)[Alignment];
v := 0;
if IsVertical then dh := MakeDrawHelper(Self);
dh := TAxisDrawHelperY.Create
else
dh := TAxisDrawHelperX.Create;
try try
dh.FAxis := Self;
dh.FClipRect := AClipRect;
dh.FDrawer := ADrawer;
dh.FTransf := ATransf;
dh.FZOffset := AZOffset;
dh.BeginDrawing;
axisTransf := @GetTransform.AxisToGraph; axisTransf := @GetTransform.AxisToGraph;
for i := 0 to High(FMarkValues) do for i := 0 to High(FMarkValues) do begin
dh.DrawMark(fixedCoord, axisTransf(FMarkValues[i]), FMarkTexts[i]); pv := v;
v := axisTransf(FMarkValues[i]);
dh.DrawMark(fixedCoord, v, FMarkTexts[i]);
if (i = 0) or (v = pv) then continue;
for j := 0 to Minors.Count - 1 do begin
ic := Minors[j].IntervalsCount;
if not Minors[j].Visible or (ic < 2) then continue;
dhMinor := MakeDrawHelper(Minors[j]);
try
for c := 1 to ic - 1 do
dhMinor.DrawMark(fixedCoord, WeightedAverage(pv, v, c / ic), '');
dhMinor.EndDrawing;
finally
dhMinor.Free;
end;
end;
end;
dh.EndDrawing; dh.EndDrawing;
finally finally
dh.Free; dh.Free;