mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-14 14:39:20 +02:00
TAChart: Fix axis interval scale during printing. Trivial update to print demo.
git-svn-id: trunk@31923 -
This commit is contained in:
parent
de7fc38f9c
commit
a85397a7f2
@ -17,11 +17,13 @@ object Form1: TForm1
|
||||
Marks.Distance = 10
|
||||
Marks.LabelFont.Height = -13
|
||||
Marks.Frame.Style = psSolid
|
||||
Minors = <>
|
||||
Title.LabelFont.Orientation = 900
|
||||
end
|
||||
item
|
||||
Alignment = calBottom
|
||||
Marks.LabelFont.Height = -13
|
||||
Minors = <>
|
||||
end>
|
||||
Foot.Brush.Color = clBtnFace
|
||||
Foot.Font.Color = clBlue
|
||||
|
@ -31,7 +31,7 @@
|
||||
<RequiredPackages Count="5">
|
||||
<Item1>
|
||||
<PackageName Value="LCLBase"/>
|
||||
<MinVersion Major="1" Release="1" Valid="True"/>
|
||||
<MinVersion Major="1" Valid="True" Release="1"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="LCL"/>
|
||||
|
@ -98,6 +98,7 @@ type
|
||||
FAxisRect: TRect;
|
||||
FGroupIndex: Integer;
|
||||
FTitleRect: TRect;
|
||||
function MakeValuesInRangeParams(AMin, AMax: Double): TValuesInRangeParams;
|
||||
strict private
|
||||
FAlignment: TChartAxisAlignment;
|
||||
FAxisPen: TChartAxisPen;
|
||||
@ -139,7 +140,6 @@ type
|
||||
procedure DrawTitle(const ACenter: TPoint; ASize: Integer);
|
||||
function GetChart: TCustomChart; inline;
|
||||
function IsVertical: Boolean; inline;
|
||||
function MakeValuesInRangeParams(AMin, AMax: Double): TValuesInRangeParams;
|
||||
procedure Measure(
|
||||
const AExtent: TDoubleRect; var AMeasureData: TChartAxisGroup);
|
||||
procedure PrepareHelper(
|
||||
@ -596,6 +596,7 @@ begin
|
||||
Result.FAxisToGraph := @GetTransform.AxisToGraph;
|
||||
Result.FGraphToAxis := @GetTransform.GraphToAxis;
|
||||
Result.FGraphToImage := @FHelper.GraphToImage;
|
||||
Result.FScale := @FHelper.FDrawer.Scale;
|
||||
Result.FIntervals := Intervals;
|
||||
Result.FMinStep := 0;
|
||||
end;
|
||||
|
@ -58,6 +58,7 @@ type
|
||||
function GetOwner: TPersistent; override;
|
||||
public
|
||||
constructor Create(AOwner: TPersistent);
|
||||
procedure Assign(ASource: TPersistent); override;
|
||||
property StepValues: TDoubleDynArray read FStepValues;
|
||||
published
|
||||
property Count: Integer read FCount write SetCount default 5;
|
||||
@ -93,6 +94,7 @@ type
|
||||
PChartDataItem = ^TChartDataItem;
|
||||
|
||||
TGraphToImageFunc = function (AX: Double): Integer of object;
|
||||
TIntegerTransformFunc = function (AX: Integer): Integer of object;
|
||||
|
||||
TValuesInRangeParams = object
|
||||
FAxisToGraph: TTransformFunc;
|
||||
@ -102,6 +104,7 @@ type
|
||||
FIntervals: TChartAxisIntervalParams;
|
||||
FMin, FMax: Double;
|
||||
FMinStep: Double;
|
||||
FScale: TIntegerTransformFunc;
|
||||
FUseY: Boolean;
|
||||
|
||||
function CountToStep(ACount: Integer): Double; inline;
|
||||
@ -210,8 +213,8 @@ function TValuesInRangeParams.IsAcceptableStep(AStep: Integer): Boolean;
|
||||
begin
|
||||
with FIntervals do
|
||||
Result := not (
|
||||
(aipUseMinLength in Options) and (AStep < MinLength) or
|
||||
(aipUseMaxLength in Options) and (AStep > MaxLength));
|
||||
(aipUseMinLength in Options) and (AStep < FScale(MinLength)) or
|
||||
(aipUseMaxLength in Options) and (AStep > FScale(MaxLength)));
|
||||
end;
|
||||
|
||||
function TValuesInRangeParams.ToImage(AX: Double): Integer;
|
||||
@ -223,8 +226,23 @@ end;
|
||||
|
||||
{ TChartAxisIntervalParams }
|
||||
|
||||
procedure TChartAxisIntervalParams.Assign(ASource: TPersistent);
|
||||
begin
|
||||
if ASource is TChartAxisIntervalParams then
|
||||
with TChartAxisIntervalParams(ASource) do begin
|
||||
Self.FCount := Count;
|
||||
Self.FMaxLength := MaxLength;
|
||||
Self.FMinLength := MinLength;
|
||||
Self.FNiceSteps := NiceSteps;
|
||||
Self.FOptions := Options;
|
||||
end
|
||||
else
|
||||
inherited Assign(ASource);
|
||||
end;
|
||||
|
||||
procedure TChartAxisIntervalParams.Changed;
|
||||
begin
|
||||
if not (FOwner is TCustomChartSource) then exit;
|
||||
with FOwner as TCustomChartSource do begin
|
||||
BeginUpdate;
|
||||
EndUpdate;
|
||||
@ -607,11 +625,12 @@ begin
|
||||
pv := v;
|
||||
v := IfThen(AParams.FUseY, Item[i]^.Y, Item[i]^.X);
|
||||
if not InRange(v, AParams.FMin, AParams.FMax) then continue;
|
||||
if aipUseMinLength in AParams.FIntervals.Options then begin
|
||||
vi := AParams.ToImage(v);
|
||||
if Abs(vi - pvi) < AParams.FIntervals.MinLength then continue;
|
||||
pvi := vi;
|
||||
end;
|
||||
with AParams do
|
||||
if aipUseMinLength in FIntervals.Options then begin
|
||||
vi := ToImage(v);
|
||||
if Abs(vi - pvi) < FScale(FIntervals.MinLength) then continue;
|
||||
pvi := vi;
|
||||
end;
|
||||
if (cnt = 0) and (i > 0) then
|
||||
Push(pv, i - 1);
|
||||
Push(v, i);
|
||||
|
@ -25,6 +25,7 @@ uses
|
||||
Classes, TAChartUtils, TACustomSource;
|
||||
|
||||
type
|
||||
|
||||
{ TIntervalChartSource }
|
||||
|
||||
TIntervalChartSource = class(TCustomChartSource)
|
||||
@ -175,16 +176,21 @@ procedure TIntervalChartSource.CalculateIntervals(
|
||||
|
||||
procedure CalcMinMaxCount(out AMinCount, AMaxCount: Integer);
|
||||
var
|
||||
imageWidth, d: Integer;
|
||||
imageWidth, len: Integer;
|
||||
begin
|
||||
// If the axis transformation is non-linear, steps may not be equidistant.
|
||||
// However, both minimax and maximin will be achieved on equal steps.
|
||||
with AParams do
|
||||
imageWidth := Abs(ToImage(FMax) - ToImage(FMin));
|
||||
d := IfThen(aipUseMinLength in Params.Options, Max(Params.MinLength, 2), 2);
|
||||
AMaxCount := Max(imageWidth div d, 2);
|
||||
if aipUseMaxLength in Params.Options then
|
||||
AMinCount := Max((imageWidth + 1) div Max(Params.MaxLength, 2), 2)
|
||||
if aipUseMinLength in Params.Options then
|
||||
len := AParams.FScale(Max(Params.MinLength, 2))
|
||||
else
|
||||
len := 2;
|
||||
AMaxCount := Max(imageWidth div len, 2);
|
||||
if aipUseMaxLength in Params.Options then begin
|
||||
len := AParams.FScale(Max(Params.MaxLength, 2));
|
||||
AMinCount := Max((imageWidth + 1) div len, 2);
|
||||
end
|
||||
else
|
||||
AMinCount := 2;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user